Commit f4ec4b92 authored by Akikonata's avatar Akikonata

Merge branch 'dev' of https://github.com/kitygraph/kityminder into dev

parents ef57be43 19fbe3dc
...@@ -20,13 +20,13 @@ kity.extendClass( Minder, { ...@@ -20,13 +20,13 @@ kity.extendClass( Minder, {
} }
}, },
execCommand: function ( name ) { execCommand: function ( name ) {
var TargetCommand, command, cmdArgs, eventParams, stoped; var TargetCommand, command, cmdArgs, eventParams, stoped, isTopCommand;
TargetCommand = this._getCommand( name ); TargetCommand = this._getCommand( name );
console.log( TargetCommand );
if ( !TargetCommand ) { if ( !TargetCommand ) {
return false; return false;
} }
command = new TargetCommand(); command = new TargetCommand();
cmdArgs = Array.prototype.slice.call( arguments, 1 ); cmdArgs = Array.prototype.slice.call( arguments, 1 );
...@@ -37,20 +37,23 @@ kity.extendClass( Minder, { ...@@ -37,20 +37,23 @@ kity.extendClass( Minder, {
commandArgs: cmdArgs commandArgs: cmdArgs
}; };
this._executingCommand = this._executingCommand || command; if ( !this._executingCommand ) {
this._executingCommand = command;
if ( this._executingCommand == command ) { isTopCommand = true;
} else {
stoped = this._fire( new MinderEvent( 'beforecommand', eventParams, true ) ); isTopCommand = false;
}
if ( !stoped ) {
this._fire( new MinderEvent( "precommand", eventParams, false ) ); stoped = this._fire( new MinderEvent( 'beforecommand', eventParams, true ) );
command.execute.apply( command, [ this ].concat( cmdArgs ) ); if ( !stoped ) {
this._fire( new MinderEvent( "command", eventParams, false ) ); this._fire( new MinderEvent( "precommand", eventParams, false ) );
command.execute.apply( command, [ this ].concat( cmdArgs ) );
this._fire( new MinderEvent( "command", eventParams, false ) );
// 顶级命令才触发事件
if ( isTopCommand ) {
if ( command.isContentChanged() ) { if ( command.isContentChanged() ) {
this._firePharse( new MinderEvent( 'contentchange' ) ); this._firePharse( new MinderEvent( 'contentchange' ) );
} }
...@@ -59,10 +62,11 @@ kity.extendClass( Minder, { ...@@ -59,10 +62,11 @@ kity.extendClass( Minder, {
} }
this._firePharse( new MinderEvent( 'interactchange' ) ); this._firePharse( new MinderEvent( 'interactchange' ) );
} }
}
// 顶级事件执行完毕才能清楚顶级事件的执行标记
if ( isTopCommand ) {
this._executingCommand = null; this._executingCommand = null;
} else {
command.execute.apply( command, [ this ].concat( cmdArgs ) );
} }
}, },
......
...@@ -7,6 +7,10 @@ kity.extendClass( Minder, { ...@@ -7,6 +7,10 @@ kity.extendClass( Minder, {
this._bindPaperEvents(); this._bindPaperEvents();
this._bindKeyboardEvents(); this._bindKeyboardEvents();
}, },
_resetEvents: function () {
this._initEvents();
this._bindEvents();
},
// TODO: mousemove lazy bind // TODO: mousemove lazy bind
_bindPaperEvents: function () { _bindPaperEvents: function () {
var minder = this; var minder = this;
......
...@@ -12,15 +12,17 @@ ...@@ -12,15 +12,17 @@
var MinderDefaultOptions = {}; var MinderDefaultOptions = {};
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( options ) { constructor: function ( arg0, arg1 ) {
this._options = options || {}; var options = typeof ( arg0 ) === 'string' ? Utils.extend( arg1 || {}, {
options = Utils.extend( window.KITYMINDER_CONFIG || {}, MinderDefaultOptions, options || {} ); renderTo: arg0
} ) : ( arg0 || {} );
this._options = Utils.extend( window.KITYMINDER_CONFIG || {}, MinderDefaultOptions, options );
this._initEvents(); this._initEvents();
this._initMinder( options ); this._initMinder();
this._initModules( options ); this._initModules();
}, },
_initMinder: function ( option ) { _initMinder: function () {
this._rc = new kity.Group(); this._rc = new kity.Group();
this._paper = new kity.Paper(); this._paper = new kity.Paper();
...@@ -29,8 +31,8 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", { ...@@ -29,8 +31,8 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._root = new MinderNode( this ); this._root = new MinderNode( this );
this._rc.addShape( this._root.getRenderContainer() ); this._rc.addShape( this._root.getRenderContainer() );
if ( option.renderTo ) { if ( this._options.renderTo ) {
this.renderTo( option.renderTo ); this.renderTo( this._options.renderTo );
} }
}, },
......
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