Commit 05069fe2 authored by techird's avatar techird

dev

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