Commit d652a8fb authored by techird's avatar techird

stash

parent e2ac6d1e
/**
* 开发版本的文件导入
*/
(function () {
(function() {
var paths = [
'core/kityminder.js',
'core/utils.js',
'core/command.js',
'core/node.js',
'core/module.js',
'core/event.js',
'core/minder.js',
'core/minder.data.js',
'core/minder.event.js',
'core/minder.module.js',
'core/minder.command.js',
'core/minder.node.js',
'core/keymap.js',
'core/minder.lang.js',
'core/minder.defaultoptions.js',
'core/minder.preference.js',
'core/browser.js',
'module/geometry.js',
'module/history.js',
'module/icon.js',
'module/image.js',
'module/resource.js',
'module/layout.js',
'module/layout.default.js',
'module/layout.bottom.js',
'core/minder.select.js',
'module/view.js',
'module/dragtree.js',
'module/dropfile.js',
'module/keyboard.js',
'module/select.js',
'module/history.js',
'module/editor.js',
'module/editor.range.js',
'module/editor.receiver.js',
'module/editor.selection.js',
'module/basestyle.js',
'module/font.js',
'module/zoom.js',
'module/nodetext.js',
'module/hyperlink.js',
'module/expand.js',
'ui/jquery-ui-1.10.4.custom.min.js',
'ui/widget.js',
'ui/button.js',
'ui/toolbar.js',
'ui/menu.js',
'ui/dropmenu.js',
'ui/splitbutton.js',
'ui/colorsplitbutton.js',
'ui/popup.js',
'ui/scale.js',
'ui/colorpicker.js',
'ui/combobox.js',
'ui/buttoncombobox.js',
'ui/modal.js',
'ui/tooltip.js',
'ui/tab.js',
'ui/separator.js',
'ui/scale.js',
'adapter/utils.js',
'adapter/adapter.js',
'adapter/button.js',
'adapter/combobox.js',
'adapter/color.js',
'adapter/saveto.js',
'adapter/tooltips.js',
'adapter/layout.js',
'adapter/node.js',
'adapter/contextmenu.js',
'adapter/dialog.js',
'adapter/hyperlink.js',
'adapter/image.js',
'adapter/zoom.js',
'protocal/xmind.js',
'protocal/freemind.js',
'protocal/mindmanager.js',
'protocal/plain.js',
'protocal/json.js',
'protocal/png.js',
'protocal/svg.js'
],
baseURL = 'src/', doc = document;
'core/kityminder.js',
'core/utils.js',
'core/command.js',
'core/node.js',
'core/module.js',
'core/event.js',
'core/minder.js',
'core/minder.data.js',
'core/minder.event.js',
'core/minder.module.js',
'core/minder.command.js',
'core/minder.node.js',
'core/keymap.js',
'core/minder.lang.js',
'core/minder.defaultoptions.js',
'core/minder.preference.js',
'core/browser.js',
'core/layout.js',
'core/render.js',
'core/theme.js',
'layout/default.js',
'theme/default.js',
'module/outline.js',
'module/geometry.js',
'module/history.js',
'module/icon.js',
'module/image.js',
'module/resource.js',
'core/minder.select.js',
'module/view.js',
'module/dragtree.js',
'module/dropfile.js',
'module/keyboard.js',
'module/select.js',
'module/history.js',
'module/editor.js',
'module/editor.range.js',
'module/editor.receiver.js',
'module/editor.selection.js',
'module/basestyle.js',
'module/font.js',
'module/zoom.js',
'module/nodetext.js',
'module/hyperlink.js',
'module/expand.js',
'ui/jquery-ui-1.10.4.custom.min.js',
'ui/widget.js',
'ui/button.js',
'ui/toolbar.js',
'ui/menu.js',
'ui/dropmenu.js',
'ui/splitbutton.js',
'ui/colorsplitbutton.js',
'ui/popup.js',
'ui/scale.js',
'ui/colorpicker.js',
'ui/combobox.js',
'ui/buttoncombobox.js',
'ui/modal.js',
'ui/tooltip.js',
'ui/tab.js',
'ui/separator.js',
'ui/scale.js',
'adapter/utils.js',
'adapter/adapter.js',
'adapter/button.js',
'adapter/combobox.js',
'adapter/color.js',
'adapter/saveto.js',
'adapter/tooltips.js',
//'adapter/layout.js',
'adapter/node.js',
'adapter/contextmenu.js',
'adapter/dialog.js',
'adapter/hyperlink.js',
'adapter/image.js',
'adapter/zoom.js',
'protocal/xmind.js',
'protocal/freemind.js',
'protocal/mindmanager.js',
'protocal/plain.js',
'protocal/json.js',
'protocal/png.js',
'protocal/svg.js'
],
baseURL = 'src/',
doc = document;
while (paths.length) {
doc.write('<script type="text/javascript" src="' + baseURL + paths.shift() + '"></script>');
}
......
......@@ -62,8 +62,8 @@
</body>
<script>
// create km instance
window.km = KM.getKityMinder('kityminder');
km = KM.getKityMinder('kityminder');
// New Version Notify
$(function() {
......
KM.registerToolbarUI('switchlayout', function (name) {
KM.registerToolbarUI('switchlayout', function(name) {
var me = this,
label = me.getLang('tooltips.' + name),
options = {
......@@ -16,24 +16,24 @@ KM.registerToolbarUI('switchlayout', function (name) {
return null;
}
utils.each(options.items, function (i, item) {
utils.each(options.items, function(i, item) {
options.items[i] = me.getLang('layout')[item];
});
//实例化
$combox = $.kmuibuttoncombobox(options).css('zIndex', me.getOptions('zIndex') + 1);
var comboboxWidget = $combox.kmui();
comboboxWidget.on('comboboxselect', function (evt, res) {
comboboxWidget.on('comboboxselect', function(evt, res) {
me.execCommand(name, res.value);
me.initStyle();
}).on("beforeshow", function () {
}).on("beforeshow", function() {
if ($combox.parent().length === 0) {
$combox.appendTo(me.$container.find('.kmui-dialog-container'));
}
});
//状态反射
me.on('interactchange', function () {
me.on('interactchange', function() {
var state = this.queryCommandState(name),
value = this.queryCommandValue(name);
//设置按钮状态
......@@ -48,19 +48,19 @@ KM.registerToolbarUI('switchlayout', function (name) {
});
// var data = [];
// utils.each(me.getLayoutStyleItems(), function (i, v) {
// data.push({
// label: me.getLang('tooltips.' + name) + ' ' + v,
// cmdName: 'switchlayout',
// exec: function () {
// me.execCommand('switchlayout', v);
// }
// });
// });
// data.push({
// divider: 1
// });
// me.addContextmenu(data);
// var data = [];
// utils.each(me.getLayoutStyleItems(), function (i, v) {
// data.push({
// label: me.getLang('tooltips.' + name) + ' ' + v,
// cmdName: 'switchlayout',
// exec: function () {
// me.execCommand('switchlayout', v);
// }
// });
// });
// data.push({
// divider: 1
// });
// me.addContextmenu(data);
return comboboxWidget.button().addClass('kmui-combobox');
});
\ No newline at end of file
var MinderEvent = kity.createClass( 'MindEvent', {
constructor: function ( type, params, canstop ) {
var MinderEvent = kity.createClass('MindEvent', {
constructor: function(type, params, canstop) {
params = params || {};
if ( params.getType && params.getType() == 'ShapeEvent' ) {
if (params.getType && params.getType() == 'ShapeEvent') {
this.kityEvent = params;
this.originEvent = params.originEvent;
this.getPosition = params.getPosition.bind( params );
} else if ( params.target && params.preventDefault ) {
this.getPosition = params.getPosition.bind(params);
} else if (params.target && params.preventDefault) {
this.originEvent = params;
} else {
kity.Utils.extend( this, params );
kity.Utils.extend(this, params);
}
this.type = type;
this._canstop = canstop || false;
},
getTargetNode: function () {
getTargetNode: function() {
var findShape = this.kityEvent && this.kityEvent.targetShape;
if ( !findShape ) return null;
while ( !findShape.minderNode && findShape.container ) {
if (!findShape) return null;
while (!findShape.minderNode && findShape.container) {
findShape = findShape.container;
}
return findShape.minderNode || null;
},
stopPropagation: function () {
stopPropagation: function() {
this._stoped = true;
},
stopPropagationImmediately: function () {
stopPropagationImmediately: function() {
this._immediatelyStoped = true;
this._stoped = true;
},
shouldStopPropagation: function () {
shouldStopPropagation: function() {
return this._canstop && this._stoped;
},
shouldStopPropagationImmediately: function () {
shouldStopPropagationImmediately: function() {
return this._canstop && this._immediatelyStoped;
},
preventDefault:function(){
preventDefault: function() {
this.originEvent.preventDefault();
},
isRightMB:function(){
isRightMB: function() {
var isRightMB = false;
if(!this.originEvent){
if (!this.originEvent) {
return false;
}
if ("which" in this.originEvent)
......@@ -53,4 +53,4 @@ var MinderEvent = kity.createClass( 'MindEvent', {
isRightMB = this.originEvent.button == 2;
return isRightMB;
}
} );
\ No newline at end of file
});
\ No newline at end of file
var KityMinder = window.KM = window.KityMinder = function () {
var instanceMap = {},
instanceId = 0;
return {
version: '1.1.3.1',
createMinder: function ( renderTarget, options ) {
options = options || {};
options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
var minder = new Minder( options );
this.addMinder( options.renderTo, minder );
return minder;
},
addMinder: function ( target, minder ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
instanceMap[ id ] = minder;
},
getMinder: function ( target, options ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
return instanceMap[ id ] || this.createMinder( target, options );
},
//挂接多语言
LANG: {}
};
var KityMinder = window.KM = window.KityMinder = function() {
var instanceMap = {},
instanceId = 0,
uuidMap = {};
return {
version: '1.1.3.1',
uuid: function(name) {
name = name || 'unknown';
uuidMap[name] = uuidMap[name] || 0;
++uuidMap[name];
return name + '_' + uuidMap[name];
},
createMinder: function(renderTarget, options) {
options = options || {};
options.renderTo = Utils.isString(renderTarget) ? document.getElementById(renderTarget) : renderTarget;
var minder = new Minder(options);
this.addMinder(options.renderTo, minder);
return minder;
},
addMinder: function(target, minder) {
var id;
if (typeof(target) === 'string') {
id = target;
} else {
id = target.id || ("KM_INSTANCE_" + instanceId++);
}
instanceMap[id] = minder;
},
getMinder: function(target, options) {
var id;
if (typeof(target) === 'string') {
id = target;
} else {
id = target.id || ("KM_INSTANCE_" + instanceId++);
}
return instanceMap[id] || this.createMinder(target, options);
},
//挂接多语言
LANG: {}
};
}();
\ No newline at end of file
var Layout = kity.createClass('Layout', {
doLayout: function(node) {
throw new Error('Not Implement: Layout.doLayout()');
}
});
Utils.extend(KityMinder, {
_layout: {},
registerLayout: function(name, layout) {
KityMinder._layout[name] = layout;
if (!KityMinder._defaultLayout) {
KityMinder._defaultLayout = name;
}
}
});
kity.extendClass(MinderNode, {
getLayout: function() {
var layout = this.getData('layout');
layout = layout || (this.isRoot() ? KityMinder._defaultLayout : this.parent.getLayout());
return layout;
},
layout: function(name) {
if (name) {
this.setData('layout', name);
}
var LayoutClass = KityMinder._layout[this.getLayout()];
var layout = new LayoutClass();
layout.doLayout(this);
return this;
},
getTreeBox: function() {
var box = this.getContentBox();
this.getChildren().forEach(function(child) {
box = KityMinder.Geometry.mergeBox(child.getTreeBox(), box);
});
return box;
}
});
\ No newline at end of file
Utils.extend( KityMinder, {
Utils.extend(KityMinder, {
_protocals: {},
registerProtocal: function ( name, protocalDeal ) {
KityMinder._protocals[ name ] = protocalDeal();
registerProtocal: function(name, protocalDeal) {
KityMinder._protocals[name] = protocalDeal();
},
findProtocal: function ( name ) {
return KityMinder._protocals[ name ] || null;
findProtocal: function(name) {
return KityMinder._protocals[name] || null;
},
getSupportedProtocals: function () {
return Utils.keys( KityMinder._protocals ).sort( function ( a, b ) {
return KityMinder._protocals[ b ].recognizePriority - KityMinder._protocals[ a ].recognizePriority;
} );
getSupportedProtocals: function() {
return Utils.keys(KityMinder._protocals).sort(function(a, b) {
return KityMinder._protocals[b].recognizePriority - KityMinder._protocals[a].recognizePriority;
});
},
getAllRegisteredProtocals: function () {
getAllRegisteredProtocals: function() {
return KityMinder._protocals;
}
} );
});
// 这里的 Json 是一个对象
function exportNode( node ) {
function exportNode(node) {
var exported = {};
exported.data = node.getData();
var childNodes = node.getChildren();
if ( childNodes.length ) {
if (childNodes.length) {
exported.children = [];
for ( var i = 0; i < childNodes.length; i++ ) {
exported.children.push( exportNode( childNodes[ i ] ) );
for (var i = 0; i < childNodes.length; i++) {
exported.children.push(exportNode(childNodes[i]));
}
}
return exported;
......@@ -36,61 +36,62 @@ var DEFAULT_TEXT = {
'sub': 'topic'
};
function importNode( node, json, km ) {
function importNode(node, json, km) {
var data = json.data;
for ( var field in data ) {
node.setData( field, data[ field ] );
for (var field in data) {
node.setData(field, data[field]);
}
node.setData( 'text', data.text || km.getLang( DEFAULT_TEXT[ node.getType() ] ) );
node.setData('text', data.text || km.getLang(DEFAULT_TEXT[node.getType()]));
node.render();
var childrenTreeData = json.children;
if ( !childrenTreeData ) return;
for ( var i = 0; i < childrenTreeData.length; i++ ) {
var childNode = new MinderNode();
node.appendChild( childNode );
importNode( childNode, childrenTreeData[ i ], km );
if (!childrenTreeData) return;
for (var i = 0; i < childrenTreeData.length; i++) {
var childNode = km.createNode();
node.appendChild(childNode);
importNode(childNode, childrenTreeData[i], km);
}
return node;
}
// 导入导出
kity.extendClass( Minder, {
exportData: function ( protocalName ) {
kity.extendClass(Minder, {
exportData: function(protocalName) {
var json, protocal;
json = exportNode( this.getRoot() );
protocal = KityMinder.findProtocal( protocalName );
json = exportNode(this.getRoot());
protocal = KityMinder.findProtocal(protocalName);
if ( this._fire( new MinderEvent( 'beforeexport', {
if (this._fire(new MinderEvent('beforeexport', {
json: json,
protocalName: protocalName,
protocal: protocal
}, true ) ) === true ) return;
}, true)) === true) return;
if ( protocal ) {
return protocal.encode( json, this );
if (protocal) {
return protocal.encode(json, this);
} else {
return json;
}
},
importData: function ( local, protocalName ) {
importData: function(local, protocalName) {
var json, protocal;
if ( protocalName ) {
protocal = KityMinder.findProtocal( protocalName );
if (protocalName) {
protocal = KityMinder.findProtocal(protocalName);
} else {
KityMinder.getSupportedProtocals().every( function ( name ) {
var test = KityMinder.findProtocal( name );
if ( test.recognize && test.recognize( local ) ) {
KityMinder.getSupportedProtocals().every(function(name) {
var test = KityMinder.findProtocal(name);
if (test.recognize && test.recognize(local)) {
protocal = test;
}
return !protocal;
} );
});
}
if ( !protocal ) {
throw new Error( "Unsupported protocal: " + protocalName );
if (!protocal) {
throw new Error('Unsupported protocal: ' + protocalName);
}
var params = {
......@@ -100,73 +101,42 @@ kity.extendClass( Minder, {
};
// 是否需要阻止导入
var stoped = this._fire( new MinderEvent( 'beforeimport', params, true ) );
if ( stoped ) return this;
var stoped = this._fire(new MinderEvent('beforeimport', params, true));
if (stoped) return this;
json = params.json || (params.json = protocal.decode(local));
//*******************
function ts( d, str, last ) {
var h = d.getHours(),
m = d.getMinutes(),
s = d.getSeconds(),
ms = d.getMilliseconds();
if ( last ) {
console.log( '--- ' + str + ': ' + ( d - last ) + ' ---' );
} else {
console.log( '--- ' + str + ' ---' );
}
return d;
}
//var t1 = ts( new Date(), '开始解析' );
//*******************
json = params.json || ( params.json = protocal.decode( local ) );
if ( typeof json === 'object' && 'then' in json ) {
if (typeof json === 'object' && 'then' in json) {
var self = this;
json.then( local, function ( data ) {
//*******************
//var t2 = ts( new Date(), '解压解析耗时', t1 );
//*******************
self._afterImportData( data, params );
//*******************
//ts( new Date(), '渲染耗时', t2 );
//*******************
} );
json.then(local, function(data) {
self._doImport(data, params);
});
} else {
//*******************
//var t2 = ts( new Date(), '解压解析耗时', t1 );
//*******************
this._afterImportData( json, params );
//*******************
//ts( new Date(), '渲染耗时', t2 );
//*******************
this._doImport(json, params);
}
return this;
},
_afterImportData: function ( json, params ) {
this._fire( new MinderEvent( 'preimport', params, false ) );
_doImport: function(json, params) {
this._fire(new MinderEvent('preimport', params, false));
// 删除当前所有节点
while ( this._root.getChildren().length ) {
this._root.removeChild( 0 );
while (this._root.getChildren().length) {
this.removeNode(this._root.getChildren()[0]);
}
var curLayout = this._root.getData( "currentstyle" );
this._root.setData();
this._root.setData( "currentstyle", curLayout );
importNode( this._root, json, this );
this.fire( 'beforeimport' );
this._fire( new MinderEvent( 'import', params, false ) );
this._firePharse( {
importNode(this._root, json, this);
this._root.layout();
this.fire('beforeimport', params);
this.fire('import', params);
this._firePharse({
type: 'contentchange'
} );
this._firePharse( {
});
this._firePharse({
type: 'interactchange'
} );
});
}
} );
\ No newline at end of file
});
\ No newline at end of file
This diff is collapsed.
// 模块声明周期维护
kity.extendClass( Minder, {
_initModules: function () {
kity.extendClass(Minder, {
_initModules: function() {
var modulesPool = KityMinder.getModules();
var modulesToLoad = this._options.modules || Utils.keys( modulesPool );
var modulesToLoad = this._options.modules || Utils.keys(modulesPool);
this._commands = {};
this._query = {};
this._modules = {};
var i, name, type, module, moduleDeals, dealCommands, dealEvents;
this._renderers = {
center: [],
left: [],
right: [],
top: [],
bottom: [],
outline: []
};
var i, name, type, module, moduleDeals,
dealCommands, dealEvents, dealRenderers;
var me = this;
for ( i = 0; i < modulesToLoad.length; i++ ) {
name = modulesToLoad[ i ];
for (i = 0; i < modulesToLoad.length; i++) {
name = modulesToLoad[i];
if ( !modulesPool[ name ] ) continue;
if (!modulesPool[name]) continue;
//执行模块初始化,抛出后续处理对象
moduleDeals = modulesPool[ name ].call( me );
this._modules[ name ] = moduleDeals;
// 执行模块初始化,抛出后续处理对象
moduleDeals = modulesPool[name].call(me);
this._modules[name] = moduleDeals;
if ( moduleDeals.init ) {
moduleDeals.init.call( me, this._options );
if (moduleDeals.init) {
moduleDeals.init.call(me, this._options);
}
//command加入命令池子
// command加入命令池子
dealCommands = moduleDeals.commands;
for ( name in dealCommands ) {
this._commands[ name.toLowerCase() ] = new dealCommands[ name ]();
for (name in dealCommands) {
this._commands[name.toLowerCase()] = new dealCommands[name]();
}
//绑定事件
// 绑定事件
dealEvents = moduleDeals.events;
if ( dealEvents ) {
for ( type in dealEvents ) {
me.on( type, dealEvents[ type ] );
if (dealEvents) {
for (type in dealEvents) {
me.on(type, dealEvents[type]);
}
}
if ( moduleDeals.defaultOptions ) {
this.setDefaultOptions( moduleDeals.defaultOptions );
// 渲染器
dealRenderers = moduleDeals.renderers;
if (dealRenderers) {
for (type in dealRenderers) {
if (!(type in this._renderers)) continue;
if (Utils.isArray(dealRenderers[type])) {
this._renderers[type] = this._renderers[type].concat(dealRenderers[type]);
} else {
this._renderers[type].push(dealRenderers[type]);
}
}
}
if (moduleDeals.defaultOptions) {
this.setDefaultOptions(moduleDeals.defaultOptions);
}
//添加模块的快捷键
if ( moduleDeals.addShortcutKeys ) {
this.addShortcutKeys( moduleDeals.addShortcutKeys );
if (moduleDeals.addShortcutKeys) {
this.addShortcutKeys(moduleDeals.addShortcutKeys);
}
//添加邮件菜单
if(moduleDeals.contextmenu){
if (moduleDeals.contextmenu) {
this.addContextmenu(moduleDeals.contextmenu);
}
}
},
_garbage: function () {
_garbage: function() {
this.clearSelect();
while ( this._root.getChildren().length ) {
this._root.removeChild( 0 );
while (this._root.getChildren().length) {
this._root.removeChild(0);
}
},
destroy: function () {
destroy: function() {
var modules = this._modules;
this._resetEvents();
this._garbage();
for ( var key in modules ) {
if ( !modules[ key ].destroy ) continue;
modules[ key ].destroy.call( this );
for (var key in modules) {
if (!modules[key].destroy) continue;
modules[key].destroy.call(this);
}
},
reset: function () {
reset: function() {
var modules = this._modules;
this._garbage();
for ( var key in modules ) {
if ( !modules[ key ].reset ) continue;
modules[ key ].reset.call( this );
for (var key in modules) {
if (!modules[key].reset) continue;
modules[key].reset.call(this);
}
}
} );
\ No newline at end of file
});
\ No newline at end of file
......@@ -3,35 +3,48 @@ kity.extendClass(Minder, {
getRoot: function() {
return this._root;
},
setRoot: function(root) {
this._root = root;
root.minder = this;
},
createNode: function(unknown) {
var node = new MinderNode(unknown);
this.handelNodeCreate(node);
return node;
},
removeNode: function(node) {
if (node.parent) {
node.parent.removeChild(node);
this.handelNodeRemove(node);
}
},
handelNodeInsert: function(node) {
handelNodeCreate: function(node) {
var rc = this._rc;
// node.traverse( function ( current ) {
// rc.addShape( current.getRenderContainer() );
// } );
node.traverse(function(current) {
rc.addShape(current.getRenderContainer());
});
rc.addShape(node.getRenderContainer());
},
handelNodeRemove: function(node) {
var rc = this._rc;
node.traverse(function(current) {
rc.removeShape(current.getRenderContainer());
});
},
renderNodes: function(nodes) {
var km = this;
if (nodes instanceof Array) {
if (nodes.length === 0) return false;
for (var i = 0; i < nodes.length; i++) {
km.renderNode(nodes[i]);
}
} else {
km.renderNode(nodes);
}
},
getMinderTitle: function() {
return this.getRoot().getText();
}
});
kity.extendClass(MinderNode, {
getMinder: function() {
return this.root.minder;
}
});
\ No newline at end of file
// 选区管理
kity.extendClass( Minder, function () {
function highlightNode( km, node ) {
if( node ){
node.setTmpData( "highlight", true );
km.highlightNode( node );
kity.extendClass(Minder, {
_initSelection: function() {
this._selectedNodes = [];
},
renderChangedSelection: function(changed) {
var i = 0;
while (i < changed.length) changed[i++].render();
},
getSelectedNodes: function() {
//不能克隆返回,会对当前选区操作,从而影响querycommand
return this._selectedNodes;
},
getSelectedNode: function() {
return this.getSelectedNodes()[0] || null;
},
removeAllSelectedNodes: function() {
var me = this;
var changed = this._selectedNodes;
this._selectedNodes = [];
this.renderChangedSelection(changed);
return this.fire('selectionclear');
},
removeSelectedNodes: function(nodes) {
var me = this;
nodes = Utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
var index;
if ((index = me._selectedNodes.indexOf(n)) === -1) return;
me._selectedNodes.splice(index, 1);
});
this.renderChangedSelection(nodes);
return this;
},
select: function(nodes, isToggleSelect) {
if (isToggleSelect) {
this.removeAllSelectedNodes();
}
}
var me = this;
nodes = Utils.isArray(nodes) ? nodes : [nodes];
Utils.each(nodes, function(i, n) {
if (me._selectedNodes.indexOf(n) !== -1) return;
me._selectedNodes.push(n);
});
this.renderChangedSelection(nodes);
return this;
},
function unhighlightNode( km, node ) {
if( node ){
node.setTmpData( "highlight", false );
km.highlightNode( node );
//当前选区中的节点在给定的节点范围内的保留选中状态,
//没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect: function(node) {
if (Utils.isArray(node)) {
node.forEach(this.toggleSelect.bind(this));
} else {
if (node.isSelected()) this.removeSelectedNodes(node);
else this.select(node);
}
}
return {
_initSelection: function () {
this._selectedNodes = [];
},
getSelectedNodes: function () {
//不能克隆返回,会对当前选区操作,从而影响querycommand
return this._selectedNodes;
},
getSelectedNode: function () {
return this.getSelectedNodes()[ 0 ] || null;
},
removeAllSelectedNodes: function () {
var me = this;
Utils.each( this.getSelectedNodes(), function ( i, n ) {
unhighlightNode( me, n );
} );
this._selectedNodes = [];
return this.fire( 'selectionclear' );
},
removeSelectedNodes: function ( nodes ) {
var me = this;
Utils.each( Utils.isArray( nodes ) ? nodes : [ nodes ], function ( i, n ) {
var index;
if ( ( index = me._selectedNodes.indexOf( n ) ) === -1 ) return;
me._selectedNodes.splice( index, 1 );
unhighlightNode( me, n );
} );
return this;
},
select: function ( nodes, isToggleSelect ) {
if ( isToggleSelect ) {
this.removeAllSelectedNodes();
}
var me = this;
Utils.each( Utils.isArray( nodes ) ? nodes : [ nodes ], function ( i, n ) {
if ( me._selectedNodes.indexOf( n ) !== -1 ) return;
me._selectedNodes.push( n );
highlightNode( me, n );
} );
return this;
},
return this;
},
isNodeSelected: function ( node ) {
return node.getTmpData( 'highlight' ) === true;
},
//当前选区中的节点在给定的节点范围内的保留选中状态,
//没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect: function ( node ) {
if ( Utils.isArray( node ) ) {
node.forEach( this.toggleSelect.bind( this ) );
} else {
if ( node.isSelected() ) this.removeSelectedNodes( node );
else this.select( node );
}
return this;
},
isSingleSelect: function () {
return this._selectedNodes.length == 1;
},
getSelectedAncestors: function() {
var nodes = this.getSelectedNodes().slice( 0 ),
isSingleSelect: function() {
return this._selectedNodes.length == 1;
},
getSelectedAncestors: function() {
var nodes = this.getSelectedNodes().slice(0),
ancestors = [],
judge;
// 根节点不参与计算
var rootIndex = nodes.indexOf( this.getRoot() );
if ( ~rootIndex ) {
nodes.splice( rootIndex, 1 );
}
// 根节点不参与计算
var rootIndex = nodes.indexOf(this.getRoot());
if (~rootIndex) {
nodes.splice(rootIndex, 1);
}
// 判断 nodes 列表中是否存在 judge 的祖先
function hasAncestor( nodes, judge ) {
for ( var i = nodes.length - 1; i >= 0; --i ) {
if ( nodes[ i ].isAncestorOf( judge ) ) return true;
}
return false;
// 判断 nodes 列表中是否存在 judge 的祖先
function hasAncestor(nodes, judge) {
for (var i = nodes.length - 1; i >= 0; --i) {
if (nodes[i].isAncestorOf(judge)) return true;
}
return false;
}
// 按照拓扑排序
nodes.sort( function ( node1, node2 ) {
return node1.getLevel() - node2.getLevel();
} );
// 按照拓扑排序
nodes.sort(function(node1, node2) {
return node1.getLevel() - node2.getLevel();
});
// 因为是拓扑有序的,所以只需往上查找
while ( ( judge = nodes.pop() ) ) {
if ( !hasAncestor( nodes, judge ) ) {
ancestors.push( judge );
}
// 因为是拓扑有序的,所以只需往上查找
while ((judge = nodes.pop())) {
if (!hasAncestor(nodes, judge)) {
ancestors.push(judge);
}
return ancestors;
}
};
}() );
\ No newline at end of file
return ancestors;
}
});
kity.extendClass(MinderNode, {
isSelected: function() {
return (~this.getMinder().getSelectedNodes().indexOf(this));
}
});
\ No newline at end of file
This diff is collapsed.
var Renderer = kity.createClass('Renderer', {
create: function(node) {
throw new Error('Not implement: Renderer.create()');
},
update: function(node) {
throw new Error('Not implement: Renderer.update()');
}
});
kity.extendClass(MinderNode, {
getContentBox: function() {
return this._contentBox;
}
});
kity.extendClass(Minder, {
_createRendererForNode: function(node) {
var registered = this._renderers;
var renderers = [];
renderers = renderers.concat(registered.center);
renderers = renderers.concat(registered.left);
renderers = renderers.concat(registered.right);
renderers = renderers.concat(registered.top);
renderers = renderers.concat(registered.bottom);
renderers = renderers.concat(registered.outline);
node._renderers = renderers.map(function(Renderer) {
var renderer = new Renderer();
renderer.create(node);
return renderer;
});
},
renderNode: function(node) {
var rendererClasses = this._renderers,
g = KityMinder.Geometry,
contentBox = node._contentBox = g.wrapBox({
left: 0,
right: 0,
top: 0,
bottom: 0
});
var i, latestBox;
if (!node._renderers) {
this._createRendererForNode(node);
}
for (i = 0; i < node._renderers.length; i++) {
latestBox = node._renderers[i].update(node);
if (latestBox) {
node._contentBox = contentBox = g.mergeBox(contentBox, latestBox);
}
}
}
});
kity.extendClass(MinderNode, {
render: function() {
this.getMinder().renderNode(this);
return this;
},
getContentBox: function() {
return this._contentBox;
}
});
\ No newline at end of file
......@@ -46,7 +46,7 @@ kity.extendClass(Minder, {
* @param {String} name 要使用的主题的名称
*/
useTheme: function(name) {
if (!KityMinder._theme[name]) {
if (!KityMinder._themes[name]) {
return false;
}
......@@ -72,7 +72,7 @@ kity.extendClass(Minder, {
* @param {String} item 样式名称
*/
getStyle: function(item) {
var theme = KityMinder._theme[this.getTheme()];
var theme = KityMinder._themes[this.getTheme()];
var segment, dir, selector, value, matcher;
if (item in theme) return theme[item];
......@@ -81,7 +81,7 @@ kity.extendClass(Minder, {
// 比如 item 为 'pading-left'
// theme 里有 {'padding': [10, 20]} 的定义,则可以返回 20
segment = item.split('-');
if (segment.length < 2) return;
if (segment.length < 2) return null;
dir = segment.pop();
item = segment.join('-');
......@@ -95,24 +95,20 @@ kity.extendClass(Minder, {
}
return null;
}
});
kity.extendClass(Node, {
},
/**
* 获节点的样式
* @param {String} name 样式名称
* 获取指定节点的样式
* @param {String} name 样式名称,可以不加节点类型的前缀
*/
getStyle: function(name) {
var minder = this.minder,
value;
if (!this.minder) return null;
value = minder.getStyle(name);
getNodeStyle: function(node, name) {
var value = this.getStyle(name);
return value !== null ? value : this.getStyle(node.getType() + '-' + name);
}
});
return value !== null ? value : minder.getStyle(this.getType() + '-' + name);
kity.extendClass(MinderNode, {
getStyle: function(name) {
return this.getMinder().getNodeStyle(this, name);
}
});
\ No newline at end of file
This diff is collapsed.
/* global Layout:true */
KityMinder.registerLayout('default', kity.createClass({
base: Layout,
doLayout: function(node) {
node.getChildren().forEach(function(childNode) {
childNode.layout();
});
}
}));
\ No newline at end of file
KityMinder.registerModule( "basestylemodule", function () {
KityMinder.registerModule("basestylemodule", function() {
var km = this;
return {
"commands": {
"bold": kity.createClass( "boldCommand", {
"bold": kity.createClass("boldCommand", {
base: Command,
execute: function () {
execute: function() {
var nodes = km.getSelectedNodes();
if ( this.queryState( 'bold' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold' );
n.getTextShape().setAttr( 'font-weight' );
km.updateLayout( n );
} );
if (this.queryState('bold') == 1) {
utils.each(nodes, function(i, n) {
n.setData('bold');
n.getTextShape().setAttr('font-weight');
km.updateLayout(n);
});
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'bold', true );
n.getTextShape().setAttr( 'font-weight', 'bold' );
km.updateLayout( n );
} );
utils.each(nodes, function(i, n) {
n.setData('bold', true);
n.getTextShape().setAttr('font-weight', 'bold');
km.updateLayout(n);
});
}
},
queryState: function () {
queryState: function() {
var nodes = km.getSelectedNodes(),
result = 0;
if ( nodes.length === 0 ) {
if (nodes.length === 0) {
return -1;
}
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'bold' ) ) {
utils.each(nodes, function(i, n) {
if (n && n.getData('bold')) {
result = 1;
return false;
}
} );
});
return result;
}
} ),
"italic": kity.createClass( "italicCommand", {
}),
"italic": kity.createClass("italicCommand", {
base: Command,
execute: function () {
execute: function() {
var nodes = km.getSelectedNodes();
if ( this.queryState( 'italic' ) == 1 ) {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic' );
n.getTextShape().setAttr( 'font-style' );
km.updateLayout( n );
} );
if (this.queryState('italic') == 1) {
utils.each(nodes, function(i, n) {
n.setData('italic');
n.getTextShape().setAttr('font-style');
km.updateLayout(n);
});
} else {
utils.each( nodes, function ( i, n ) {
n.setData( 'italic', true );
n.getTextShape().setAttr( 'font-style', 'italic' );
km.updateLayout( n );
} );
utils.each(nodes, function(i, n) {
n.setData('italic', true);
n.getTextShape().setAttr('font-style', 'italic');
km.updateLayout(n);
});
}
},
queryState: function () {
queryState: function() {
var nodes = km.getSelectedNodes(),
result = 0;
if ( nodes.length === 0 ) {
if (nodes.length === 0) {
return -1;
}
utils.each( nodes, function ( i, n ) {
if ( n && n.getData( 'italic' ) ) {
utils.each(nodes, function(i, n) {
if (n && n.getData('italic')) {
result = 1;
return false;
}
} );
});
return result;
}
} )
})
},
addShortcutKeys: {
"bold": "ctrl+b", //bold
"italic": "ctrl+i" //italic
},
"events": {
"afterrendernodecenter": function ( e ) {
"afterrendernodecenter": function(e) {
//加粗
if ( e.node.getData( 'bold' ) ) {
e.node.getTextShape().setAttr( 'font-weight', 'bold' );
if (e.node.getData('bold')) {
e.node.getTextShape().setAttr('font-weight', 'bold');
}
if ( e.node.getData( 'italic' ) ) {
e.node.getTextShape().setAttr( 'font-style', 'italic' );
if (e.node.getData('italic')) {
e.node.getTextShape().setAttr('font-style', 'italic');
}
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
KityMinder.Geometry = ( function () {
var g = {};
var min = Math.min,
max = Math.max,
abs = Math.abs;
var own = Object.prototype.hasOwnProperty;
KityMinder.Geometry = (function() {
var g = {};
var min = Math.min,
max = Math.max,
abs = Math.abs;
var own = Object.prototype.hasOwnProperty;
g.isNumberInRange = function ( number, range ) {
return number > range[ 0 ] && number < range[ 1 ];
};
g.isNumberInRange = function(number, range) {
return number > range[0] && number < range[1];
};
g.getDistance = function ( p1, p2 ) {
return kity.Vector.fromPoints( p1, p2 ).length();
};
g.getDistance = function(p1, p2) {
return kity.Vector.fromPoints(p1, p2).length();
};
function wrapBox( box ) {
box.width = box.right - box.left;
box.height = box.bottom - box.top;
box.x = box.left;
box.y = box.top;
return box;
}
function wrapBox(box) {
box.width = box.right - box.left;
box.height = box.bottom - box.top;
box.x = box.left;
box.y = box.top;
return box;
}
g.getBox = function ( p1, p2 ) {
return wrapBox( {
left: min( p1.x, p2.x ),
right: max( p1.x, p2.x ),
top: min( p1.y, p2.y ),
bottom: max( p1.y, p2.y )
} );
};
function uniformBox(box) {
// duck check
if ('x' in box) {
box.left = box.x;
box.right = box.x + box.width;
box.top = box.y;
box.bottom = box.y + box.height;
}
}
g.mergeBox = function ( b1, b2 ) {
return wrapBox( {
left: min( b1.left, b2.left ),
right: max( b1.right, b2.right ),
top: min( b1.top, b2.top ),
bottom: max( b1.bottom, b2.bottom )
} );
};
g.wrapBox = wrapBox;
g.getBoxRange = function ( box ) {
return {
x: [ box.left, box.right ],
y: [ box.top, box.bottom ]
};
};
g.getBox = function(p1, p2) {
return wrapBox({
left: min(p1.x, p2.x),
right: max(p1.x, p2.x),
top: min(p1.y, p2.y),
bottom: max(p1.y, p2.y)
});
};
g.getBoxVertex = function ( box ) {
return {
leftTop: {
x: box.left,
y: box.top
},
rightTop: {
x: box.right,
y: box.top
},
leftBottom: {
x: box.left,
y: box.bottom
},
rightBottom: {
x: box.right,
y: box.bottom
}
};
};
g.mergeBox = function(b1, b2) {
uniformBox(b1);
uniformBox(b2);
return wrapBox({
left: min(b1.left, b2.left),
right: max(b1.right, b2.right),
top: min(b1.top, b2.top),
bottom: max(b1.bottom, b2.bottom)
});
};
g.isPointInsideBox = function ( p, b ) {
var ranges = g.getBoxRange( b );
return g.isNumberInRange( p.x, ranges.x ) && g.isNumberInRange( p.y, ranges.y );
};
g.getBoxRange = function(box) {
return {
x: [box.left, box.right],
y: [box.top, box.bottom]
};
};
g.isBoxIntersect = function ( b1, b2 ) {
var minx = max(b1.left, b2.left),
miny = max(b1.top, b2.top),
maxx = min(b1.right, b2.right),
maxy = min(b1.bottom, b2.bottom);
return minx < maxx && miny < maxy;
};
g.getBoxVertex = function(box) {
return {
leftTop: {
x: box.left,
y: box.top
},
rightTop: {
x: box.right,
y: box.top
},
leftBottom: {
x: box.left,
y: box.bottom
},
rightBottom: {
x: box.right,
y: box.bottom
}
};
};
g.snapToSharp = function ( unknown ) {
if ( utils.isNumber( unknown ) ) {
return ( unknown | 0 ) + 0.5;
}
if ( utils.isArray( unknown ) ) {
return unknown.map( g.snapToSharp );
}
[ 'x', 'y', 'left', 'top', 'right', 'bottom' ].forEach( function ( n ) {
if ( own.call( unknown, n ) ) {
unknown[ n ] = g.snapToSharp( unknown[ n ] );
}
} );
return unknown;
};
g.isPointInsideBox = function(p, b) {
var ranges = g.getBoxRange(b);
return g.isNumberInRange(p.x, ranges.x) && g.isNumberInRange(p.y, ranges.y);
};
g.expandBox = function( box, sizeX, sizeY ) {
if(sizeY === undefined) {
sizeY = sizeX;
}
return wrapBox( {
left: box.left - sizeX,
top: box.top - sizeY,
right: box.right + sizeX,
bottom: box.bottom + sizeY
} );
};
g.isBoxIntersect = function(b1, b2) {
var minx = max(b1.left, b2.left),
miny = max(b1.top, b2.top),
maxx = min(b1.right, b2.right),
maxy = min(b1.bottom, b2.bottom);
return minx < maxx && miny < maxy;
};
return g;
} )();
\ No newline at end of file
g.snapToSharp = function(unknown) {
if (utils.isNumber(unknown)) {
return (unknown | 0) + 0.5;
}
if (utils.isArray(unknown)) {
return unknown.map(g.snapToSharp);
}
['x', 'y', 'left', 'top', 'right', 'bottom'].forEach(function(n) {
if (own.call(unknown, n)) {
unknown[n] = g.snapToSharp(unknown[n]);
}
});
return unknown;
};
g.expandBox = function(box, sizeX, sizeY) {
if (sizeY === undefined) {
sizeY = sizeX;
}
return wrapBox({
left: box.left - sizeX,
top: box.top - sizeY,
right: box.right + sizeX,
bottom: box.bottom + sizeY
});
};
return g;
})();
\ No newline at end of file
KityMinder.registerModule("KeyboardModule", function () {
KityMinder.registerModule("KeyboardModule", function() {
var min = Math.min,
max = Math.max,
abs = Math.abs,
......@@ -8,7 +8,7 @@ KityMinder.registerModule("KeyboardModule", function () {
function buildPositionNetwork(root) {
var pointIndexes = [],
p;
root.traverse(function (node) {
root.traverse(function(node) {
p = node.getRenderContainer().getRenderBox('top');
// bugfix: 不应导航到收起的节点(判断其尺寸是否存在)
......@@ -129,51 +129,52 @@ KityMinder.registerModule("KeyboardModule", function () {
}
return {
"events": {
contentchange: function () {
'events': {
'contentchange': function() {
buildPositionNetwork(this.getRoot());
},
"normal.keydown": function (e) {
'normal.keydown': function(e) {
var keys = KityMinder.keymap;
var node = e.getTargetNode();
this.receiver.keydownNode = node;
switch (e.originEvent.keyCode) {
case keys.Enter:
this.execCommand('appendSiblingNode', new MinderNode(this.getLang().topic));
e.preventDefault();
break;
case keys.Tab:
this.execCommand('appendChildNode', new MinderNode(this.getLang().topic));
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
e.preventDefault();
this.execCommand('removenode');
break;
case keys.F2:
e.preventDefault();
this.execCommand('editnode');
break;
case keys.Left:
navigateTo(this, 'left');
e.preventDefault();
break;
case keys.Up:
navigateTo(this, 'top');
e.preventDefault();
break;
case keys.Right:
navigateTo(this, 'right');
e.preventDefault();
break;
case keys.Down:
navigateTo(this, 'down');
e.preventDefault();
break;
case keys.Enter:
this.execCommand('appendSiblingNode', new MinderNode(this, this.getLang().topic));
e.preventDefault();
break;
case keys.Tab:
this.execCommand('appendChildNode', new MinderNode(this, this.getLang().topic));
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
e.preventDefault();
this.execCommand('removenode');
break;
case keys.F2:
e.preventDefault();
this.execCommand('editnode');
break;
case keys.Left:
navigateTo(this, 'left');
e.preventDefault();
break;
case keys.Up:
navigateTo(this, 'top');
e.preventDefault();
break;
case keys.Right:
navigateTo(this, 'right');
e.preventDefault();
break;
case keys.Down:
navigateTo(this, 'down');
e.preventDefault();
break;
}
}
......
/* global Renderer: true */
KityMinder.registerModule('OutlineModule', function() {
return {
renderers: {
outline: kity.createClass('OutlineRenderer', {
base: Renderer,
create: function(node) {
var outline = this.outline = new kity.Rect().setId(KityMinder.uuid('node_outline'));
node.getRenderContainer().prependShape(outline);
},
update: function(node) {
var contentBox = node.getContentBox();
var paddingLeft = node.getStyle('padding-left'),
paddingRight = node.getStyle('padding-right'),
paddingTop = node.getStyle('padding-top'),
paddingBottom = node.getStyle('padding-bottom');
this.outline
.setPosition(
contentBox.x - paddingLeft,
contentBox.y - paddingTop)
.setSize(
contentBox.width + paddingLeft + paddingRight,
contentBox.height + paddingTop + paddingBottom)
.setRadius(node.getStyle('radius'))
.fill(node.isSelected() ?
node.getStyle('selected-background') :
node.getStyle('background'));
}
})
}
};
});
\ No newline at end of file
KityMinder.registerModule( "Select", function () {
KityMinder.registerModule("Select", function() {
var minder = this;
var g = KityMinder.Geometry;
// 在实例上渲染框选矩形、计算框选范围的对象
var marqueeActivator = ( function () {
var marqueeActivator = (function() {
// 记录选区的开始位置(mousedown的位置)
var startPosition = null;
// 选区的图形
var marqueeShape = new kity.Path().fill( 'rgba(255,255,255,.3)' ).stroke( 'white' );
var marqueeShape = new kity.Path().fill('rgba(255,255,255,.3)').stroke('white');
// 标记是否已经启动框选状态
// 并不是 mousedown 发生之后就启动框选状态,而是检测到移动了一定的距离(MARQUEE_MODE_THRESHOLD)之后
......@@ -17,126 +17,126 @@ KityMinder.registerModule( "Select", function () {
var MARQUEE_MODE_THRESHOLD = 10;
return {
selectStart: function ( e ) {
selectStart: function(e) {
// 只接受左键
if ( e.originEvent.button ) return;
if (e.originEvent.button) return;
// 清理不正确状态
if ( startPosition ) {
if (startPosition) {
return this.selectEnd();
}
startPosition = g.snapToSharp( e.getPosition() );
startPosition = g.snapToSharp(e.getPosition());
},
selectMove: function ( e ) {
if ( minder.isTextEditStatus() ) {
selectMove: function(e) {
if (minder.isTextEditStatus()) {
return;
}
if ( !startPosition ) return;
if (!startPosition) return;
var p1 = startPosition,
p2 = e.getPosition();
// 检测是否要进入选区模式
if ( !marqueeMode ) {
if (!marqueeMode) {
// 距离没达到阈值,退出
if ( g.getDistance( p1, p2 ) < MARQUEE_MODE_THRESHOLD ) {
if (g.getDistance(p1, p2) < MARQUEE_MODE_THRESHOLD) {
return;
}
// 已经达到阈值,记录下来并且重置选区形状
marqueeMode = true;
minder.getPaper().addShape( marqueeShape );
marqueeShape.setOpacity( 0.8 ).getDrawer().clear();
minder.getPaper().addShape(marqueeShape);
marqueeShape.setOpacity(0.8).getDrawer().clear();
}
var marquee = g.getBox( p1, p2 ),
var marquee = g.getBox(p1, p2),
selectedNodes = [];
// 使其犀利
g.snapToSharp( marquee );
g.snapToSharp(marquee);
// 选区形状更新
marqueeShape.getDrawer().pipe( function () {
marqueeShape.getDrawer().pipe(function() {
this.clear();
this.moveTo( marquee.left, marquee.top );
this.lineTo( marquee.right, marquee.top );
this.lineTo( marquee.right, marquee.bottom );
this.lineTo( marquee.left, marquee.bottom );
this.moveTo(marquee.left, marquee.top);
this.lineTo(marquee.right, marquee.top);
this.lineTo(marquee.right, marquee.bottom);
this.lineTo(marquee.left, marquee.bottom);
this.close();
} );
});
// 计算选中范围
minder.getRoot().traverse( function ( node ) {
var renderBox = node.getRenderContainer().getRenderBox( "top" );
if ( g.isBoxIntersect( renderBox, marquee ) ) {
selectedNodes.push( node );
minder.getRoot().traverse(function(node) {
var renderBox = node.getRenderContainer().getRenderBox("top");
if (g.isBoxIntersect(renderBox, marquee)) {
selectedNodes.push(node);
}
} );
});
// 应用选中范围
minder.select( selectedNodes, true );
minder.select(selectedNodes, true);
},
selectEnd: function ( e ) {
if ( startPosition ) {
selectEnd: function(e) {
if (startPosition) {
startPosition = null;
}
if ( marqueeMode ) {
marqueeShape.fadeOut( 200, 'ease', 0, function () {
if ( marqueeShape.remove ) marqueeShape.remove();
} );
if (marqueeMode) {
marqueeShape.fadeOut(200, 'ease', 0, function() {
if (marqueeShape.remove) marqueeShape.remove();
});
marqueeMode = false;
}
}
};
} )();
})();
var lastDownNode = null;
return {
"events": {
"normal.mousedown textedit.mousedown": function ( e ) {
'events': {
'normal.mousedown textedit.mousedown': function(e) {
var downNode = e.getTargetNode();
// 没有点中节点:
// 清除选中状态,并且标记选区开始位置
if ( !downNode ) {
if (!downNode) {
this.removeAllSelectedNodes();
marqueeActivator.selectStart( e );
marqueeActivator.selectStart(e);
this.setStatus('normal')
this.setStatus('normal');
}
// 点中了节点,并且按了 shift 键:
// 被点中的节点切换选中状态
else if ( e.originEvent.shiftKey ) {
this.toggleSelect( downNode );
else if (e.originEvent.shiftKey) {
this.toggleSelect(downNode);
}
// 点中的节点没有被选择:
// 单选点中的节点
else if ( !downNode.isSelected() ) {
this.select( downNode, true );
else if (!downNode.isSelected()) {
this.select(downNode, true);
}
// 点中的节点被选中了,并且不是单选:
// 完成整个点击之后需要使其变为单选。
// 不能马上变为单选,因为可能是需要拖动选中的多个节点
else if ( !this.isSingleSelect() ) {
else if (!this.isSingleSelect()) {
lastDownNode = downNode;
}
},
"normal.mousemove textedit.mousemove": marqueeActivator.selectMove,
"normal.mouseup textedit.mouseup": function ( e ) {
'normal.mousemove textedit.mousemove': marqueeActivator.selectMove,
'normal.mouseup textedit.mouseup': function(e) {
var upNode = e.getTargetNode();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的
if ( upNode && upNode == lastDownNode ) {
this.select( lastDownNode, true );
if (upNode && upNode == lastDownNode) {
this.select(lastDownNode, true);
lastDownNode = null;
}
// 清理一下选择状态
marqueeActivator.selectEnd( e );
marqueeActivator.selectEnd(e);
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
var ViewDragger = kity.createClass( "ViewDragger", {
constructor: function ( minder ) {
var ViewDragger = kity.createClass("ViewDragger", {
constructor: function(minder) {
this._minder = minder;
this._enabled = false;
this._offset = {
......@@ -8,132 +8,138 @@ var ViewDragger = kity.createClass( "ViewDragger", {
};
this._bind();
},
isEnabled: function () {
isEnabled: function() {
return this._enabled;
},
setEnabled: function ( value ) {
setEnabled: function(value) {
var paper = this._minder.getPaper();
paper.setStyle( 'cursor', value ? 'pointer' : 'default' );
paper.setStyle( 'cursor', value ? '-webkit-grab' : 'default' );
paper.setStyle('cursor', value ? 'pointer' : 'default');
paper.setStyle('cursor', value ? '-webkit-grab' : 'default');
this._enabled = value;
},
move: function ( offset ) {
this._minder.getRenderContainer().translate( offset.x, offset.y );
move: function(offset) {
this._minder.getRenderContainer().translate(offset.x, offset.y);
},
_bind: function () {
_bind: function() {
var dragger = this,
isRootDrag = false,
lastPosition = null,
currentPosition = null;
this._minder.on( 'normal.mousedown readonly.mousedown readonly.touchstart', function ( e ) {
this._minder.on('normal.mousedown readonly.mousedown readonly.touchstart', function(e) {
// 点击未选中的根节点临时开启
if ( e.getTargetNode() == this.getRoot() &&
( !this.getRoot().isSelected() || !this.isSingleSelect() ) ) {
if (e.getTargetNode() == this.getRoot() &&
(!this.getRoot().isSelected() || !this.isSingleSelect())) {
lastPosition = e.getPosition();
isRootDrag = true;
}
} )
})
.on('normal.mousemove normal.touchmove', function (e) {
.on('normal.mousemove normal.touchmove', function(e) {
if (!isRootDrag) return;
var offset = kity.Vector.fromPoints( lastPosition, e.getPosition());
if (offset.length() > 3) this.setStatus( 'hand' );
var offset = kity.Vector.fromPoints(lastPosition, e.getPosition());
if (offset.length() > 3) this.setStatus('hand');
})
.on( 'hand.beforemousedown hand.beforetouchend', function ( e ) {
.on('hand.beforemousedown hand.beforetouchend', function(e) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
if (dragger.isEnabled()) {
lastPosition = e.getPosition();
e.stopPropagation();
}
} )
})
.on( 'hand.beforemousemove hand.beforetouchmove', function ( e ) {
if ( lastPosition ) {
.on('hand.beforemousemove hand.beforetouchmove', function(e) {
if (lastPosition) {
currentPosition = e.getPosition();
// 当前偏移加上历史偏移
var offset = kity.Vector.fromPoints( lastPosition, currentPosition );
dragger.move( offset );
var offset = kity.Vector.fromPoints(lastPosition, currentPosition);
dragger.move(offset);
e.stopPropagation();
e.preventDefault();
e.originEvent.preventDefault();
lastPosition = currentPosition;
}
} )
})
.on( 'mouseup', function ( e ) {
.on('mouseup', function(e) {
lastPosition = null;
// 临时拖动需要还原状态
if ( isRootDrag ) {
dragger.setEnabled( false );
if (isRootDrag) {
dragger.setEnabled(false);
isRootDrag = false;
this.rollbackStatus();
}
} );
});
}
} );
});
KityMinder.registerModule( 'View', function () {
KityMinder.registerModule('View', function() {
var km = this;
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
var ToggleHandCommand = kity.createClass("ToggleHandCommand", {
base: Command,
execute: function ( minder ) {
execute: function(minder) {
minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() );
if ( minder._viewDragger.isEnabled() ) {
minder.setStatus( 'hand' );
minder._viewDragger.setEnabled(!minder._viewDragger.isEnabled());
if (minder._viewDragger.isEnabled()) {
minder.setStatus('hand');
} else {
minder.rollbackStatus();
}
this.setContentChanged( false );
this.setContentChanged(false);
},
queryState: function ( minder ) {
queryState: function(minder) {
return minder._viewDragger.isEnabled() ? 1 : 0;
},
enableReadOnly: false
} );
});
var CameraCommand = kity.createClass( "CameraCommand", {
var CameraCommand = kity.createClass("CameraCommand", {
base: Command,
execute: function ( km, focusNode ) {
execute: function(km, focusNode, noAnimate) {
focusNode = focusNode || km.getRoot();
var viewport = km.getPaper().getViewPort();
var offset = focusNode.getRenderContainer().getRenderBox( 'view' );
var offset = focusNode.getRenderContainer().getRenderBox('view');
var dx = viewport.center.x - offset.x - offset.width / 2,
dy = viewport.center.y - offset.y;
km.getRenderContainer().fxTranslate( dx, dy, 1000, "easeOutQuint" );
this.setContentChanged( false );
if (noAnimate) {
km.getRenderContainer().translate(dx, dy);
} else {
km.getRenderContainer().fxTranslate(dx, dy, 1000, "easeOutQuint");
}
this.setContentChanged(false);
},
enableReadOnly: false
} );
});
return {
init: function () {
this._viewDragger = new ViewDragger( this );
init: function() {
this._viewDragger = new ViewDragger(this);
},
commands: {
'hand': ToggleHandCommand,
'camera': CameraCommand
},
events: {
keyup: function ( e ) {
if ( e.originEvent.keyCode == keymap.Spacebar && this.getSelectedNodes().length === 0 ) {
this.execCommand( 'hand' );
keyup: function(e) {
if (e.originEvent.keyCode == keymap.Spacebar && this.getSelectedNodes().length === 0) {
this.execCommand('hand');
e.preventDefault();
}
},
mousewheel: function ( e ) {
mousewheel: function(e) {
var dx, dy;
e = e.originEvent;
if ( e.ctrlKey || e.shiftKey ) return;
if (e.ctrlKey || e.shiftKey) return;
if ( 'wheelDeltaX' in e ) {
if ('wheelDeltaX' in e) {
dx = e.wheelDeltaX || 0;
dy = e.wheelDeltaY || 0;
......@@ -145,18 +151,35 @@ KityMinder.registerModule( 'View', function () {
}
this._viewDragger.move( {
this._viewDragger.move({
x: dx / 2.5,
y: dy / 2.5
} );
});
e.preventDefault();
},
'normal.dblclick readonly.dblclick': function ( e ) {
if ( e.kityEvent.targetShape instanceof kity.Paper ) {
this.execCommand( 'camera', this.getRoot() );
'normal.dblclick readonly.dblclick': function(e) {
if (e.kityEvent.targetShape instanceof kity.Paper) {
this.execCommand('camera', this.getRoot());
}
},
ready: function() {
this.execCommand('camera', null, true);
this._lastClientSize = {
width: this.getRenderTarget().clientWidth,
height: this.getRenderTarget().clientHeight
};
},
resize: function(e) {
var a = {
width: this.getRenderTarget().clientWidth,
height: this.getRenderTarget().clientHeight
},
b = this._lastClientSize;
this.getRenderContainer().translate(
(a.width - b.width) / 2, (a.height - b.height) / 2);
this._lastClientSize = a;
}
}
};
} );
\ No newline at end of file
});
\ No newline at end of file
KityMinder.registerTheme('default', {
'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 0,
'root-radius': 30,
'root-space': 10,
'main-color': '#333',
'main-background': '#a4c5c0',
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [0, 10, 30, 50],
'main-radius': 10,
'main-space': 5,
'sub-color': 'white',
'sub-background': 'none',
'sub-stroke': 'white',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [0, 10, 20, 6],
'sub-radius': 0,
'sub-space': 5,
'selected-background': 'rgb(254, 219, 0)'
});
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment