Commit 05069fe2 authored by techird's avatar techird

dev

parent 8b8945db
......@@ -8,13 +8,15 @@
"white": false,
"quotmark": false,
"predef" : [
"require",
"console",
"kity",
"KityMinder",
"Minder",
"MinderNode",
"MinderEvent",
"KityMinder",
"require",
"km",
"console",
"Command"
"Command",
"KITYMINDER_CONFIG",
"Utils"
]
}
\ No newline at end of file
......@@ -4,4 +4,8 @@ KityMinder.version = '1.0.0.0';
KityMinder.createMinder = function ( id, option ) {
};
KityMinder.getMinder = function ( id ) {
};
\ No newline at end of file
kity.extendClass( Minder, {
execCommand: function ( name ) {
var me = this;
var _action = new _commands[ name.toLowerCase() ]();
var TargetCommand, command, cmdArgs, eventParams, stoped;
var cmdArgs = Array.prototype.slice.call( arguments, 1 );
TargetCommand = this._getCommand( name );
command = new TargetCommand();
var eventParams = {
command: _action,
cmdArgs = Array.prototype.slice.call( arguments, 1 );
eventParams = {
command: command,
commandName: name.toLowerCase(),
commandArgs: cmdArgs
};
var stoped = me._fire( new MinderEvent( 'beforecommand', eventParams, true ) );
this._executingCommand = this._executingCommand || command;
if ( !stoped ) {
if ( this._executingCommand == command ) {
me._fire( new MinderEvent( "precommand", eventParams, false ) );
stoped = this._fire( new MinderEvent( 'beforecommand', eventParams, true ) );
_action.execute.apply( _action, [ this ].concat( cmdArgs ) );
if ( !stoped ) {
me._fire( new MinderEvent( "command", eventParams, false ) );
this._fire( new MinderEvent( "precommand", eventParams, false ) );
if ( _action.isContentChanged() ) {
me._firePharse( new MinderEvent( 'contentchange' ) );
}
if ( _action.isSelectionChanged() ) {
me._firePharse( new MinderEvent( 'selectionchange' ) );
command.execute.apply( command, [ this ].concat( cmdArgs ) );
this._fire( new MinderEvent( "command", eventParams, false ) );
if ( command.isContentChanged() ) {
this._firePharse( new MinderEvent( 'contentchange' ) );
}
if ( command.isSelectionChanged() ) {
this._firePharse( new MinderEvent( 'selectionchange' ) );
}
}
this._executingCommand = null;
} else {
command.execute.apply( command, [ this ].concat( cmdArgs ) );
}
},
......
// 导入导出
kity.extendClass( KityMinder, {
kity.extendClass( Minder, {
exportData: function ( node ) {
var exported = {};
node = node || this.getRoot();
......@@ -49,6 +49,9 @@ kity.extendClass( KityMinder, {
this._firePharse( {
type: 'contentchange'
} );
this._firePharse( {
type: 'interactchange'
} );
return this;
}
} );
\ No newline at end of file
// 事件机制
kity.extendClass( KityMinder, {
kity.extendClass( Minder, {
_initEvents: function () {
this._eventCallbacks = {};
this._bindPaperEvents();
......@@ -12,16 +12,9 @@ kity.extendClass( KityMinder, {
},
_bindKeyboardEvents: function () {
var minder = this;
var listen = function ( name, callback ) {
if ( window.addEventListener ) {
window.addEventListener( name, callback );
} else if ( window.attachEvent ) {
window.attachEvent( name, callback );
}
};
var events = 'keydown keyup keypress'.split( ' ' );
for ( var i = 0; i < events.length; i++ ) {
listen( events[ i ], this._firePharse.bind( this ) );
Utils.listen( events[ i ], this._firePharse.bind( this ) );
}
},
_firePharse: function ( e ) {
......@@ -40,8 +33,8 @@ kity.extendClass( KityMinder, {
},
_interactChange: function ( e ) {
var minder = this;
clearTimeout( this.interactTimeout );
this.interactTimeout = setTimeout( function () {
clearTimeout( this._interactTimeout );
this._interactTimeout = setTimeout( function () {
var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) );
if ( stoped ) {
return;
......
/**
* @require <kityminder.js>
* @require <module.js>
* @require <event.js>
* @require <node.js>
* @reuqire <command.js>
* @require <utils.js>
*
* @description KityMinder 使用类
*/
var MinderDefaultOptions = {};
var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
constructor: function ( id, option ) {
constructor: function ( options ) {
options = Utils.extend( KITYMINDER_CONFIG || {}, MinderDefaultOptions, options || {} );
// 初始化
this._initMinder( id, option || {} );
this._initEvents();
this._initModules();
this._initMinder( options );
this._initModules( options );
},
_initMinder: function ( id, option ) {
_initMinder: function ( option ) {
this._rc = new kity.Group();
this._paper = new kity.Paper( option.renderTo || document.body );
this._paper = new kity.Paper();
this._paper.addShape( this._rc );
this._root = new MinderNode( this );
this._rc.addShape( this._root.getRenderContainer() );
if ( option.renderTo ) {
this.renderTo( this._renderTarget = option.renderTo );
}
},
renderTo: function ( target ) {
this._paper.renderTo( target );
this._initEvents();
},
getRenderContainer: function () {
......@@ -23,4 +45,12 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
getPaper: function () {
return this._paper;
}
} );
\ No newline at end of file
} );
/**
* @include <minder.data.js>
* @include <minder.event.js>
* @include <minder.module.js>
* @include <minder.node.js>
* @include <minder.select.js>
*/
\ No newline at end of file
kity.extendClass( KityMinder, {
kity.extendClass( Minder, {
getRoot: function () {
return this._root;
......
// 选区管理
kity.extendClass( KityMinder, {
kity.extendClass( Minder, {
getSelectedNodes: function () {
return this._selectedNodes || ( this._selectedNodes = [] );
},
......
var Utils = KityMinder.Utils = {};
Utils.extend = kity.Utils.extend;
Utils.listen = function ( element, type, callback ) {
( element.addEventListener || element.attachEvent )( name, callback );
};
\ 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