Commit 72c028c2 authored by Akikonata's avatar Akikonata

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

Conflicts:
	demo/dev.html
parents 44ecd8c8 f3cc4c73
......@@ -8,14 +8,15 @@
"white": false,
"quotmark": false,
"predef" : [
"require",
"console",
"kity",
"KityMinder",
"Minder",
"MinderNode",
"MinderEvent",
"Minder",
"require",
"km",
"console",
"Command"
"Command",
"KITYMINDER_CONFIG",
"Utils"
]
}
\ No newline at end of file
window.KITYMINDER_CONFIG = {
};
\ No newline at end of file
......@@ -11,6 +11,7 @@
<script>
minder = new KityMinder.Minder(null,{
modules:["ExampleModule","RenderModule"]
renderTo: document.body
});
minder.importData({
......
<?php
$dependency = Array(
'src/core/km.js',
'src/core/kityminder.js',
'src/core/utils.js',
'src/core/command.js',
'src/core/node.js',
'src/core/module.js',
......
var KITYMINDER_CONFIG = window.KITYMINDER_CONFIG = {
};
\ No newline at end of file
var KityMinder = window.KM = window.KityMinder = {};
KityMinder.version = '1.0.0.0';
KityMinder.createMinder = function ( renderTarget, options ) {
options = options || {};
options.renderTo = renderTarget;
return new Minder( options );
};
var instanceMap = {}, instanceId = 0;
KityMinder.addMinderInstance = function ( target, minder ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
instanceMap[ id ] = minder;
};
KityMinder.getMinder = function ( id ) {
return instanceMap[ id ] || null;
};
\ No newline at end of file
var KityMinder = window.KM = window.KityMinder = {};
KityMinder.version = '1.0.0.0';
KityMinder.createMinder = function ( id, option ) {
};
\ No newline at end of file
......@@ -20,40 +20,48 @@ kity.extendClass( Minder, {
}
},
execCommand: function ( name ) {
var me = this;
var Action = this._getCommand( name );
var _action;
if ( !Action ) {
var TargetCommand, command, cmdArgs, eventParams, stoped;
TargetCommand = this._getCommand( name );
if ( !TargetCommand ) {
return false;
} else {
_action = new Action();
}
command = new TargetCommand();
var cmdArgs = Array.prototype.slice.call( arguments, 1 );
cmdArgs = Array.prototype.slice.call( arguments, 1 );
var eventParams = {
command: _action,
eventParams = {
command: command,
commandName: name.toLowerCase(),
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 ) {
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() ) {
me._firePharse( new MinderEvent( 'contentchange' ) );
if ( command.isContentChanged() ) {
this._firePharse( new MinderEvent( 'contentchange' ) );
}
if ( command.isSelectionChanged() ) {
this._firePharse( new MinderEvent( 'selectionchange' ) );
}
if ( _action.isSelectionChanged() ) {
me._firePharse( new MinderEvent( 'selectionchange' ) );
this._firePharse( new MinderEvent( 'interactchange' ) );
}
me._firePharse( new MinderEvent( 'interactchange' ) );
this._executingCommand = null;
} else {
command.execute.apply( command, [ this ].concat( cmdArgs ) );
}
},
......
......@@ -49,6 +49,9 @@ kity.extendClass( Minder, {
this._firePharse( {
type: 'contentchange'
} );
this._firePharse( {
type: 'interactchange'
} );
return this;
}
} );
\ No newline at end of file
......@@ -2,6 +2,8 @@
kity.extendClass( Minder, {
_initEvents: function () {
this._eventCallbacks = {};
},
_bindEvents: function () {
this._bindPaperEvents();
this._bindKeyboardEvents();
},
......@@ -12,16 +14,9 @@ kity.extendClass( Minder, {
},
_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( this._renderTarget, events[ i ], this._firePharse.bind( this ) );
}
},
_firePharse: function ( e ) {
......@@ -40,8 +35,8 @@ kity.extendClass( Minder, {
},
_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 ) {
// 初始化
this._initMinder( id, option || {} );
constructor: function ( options ) {
options = Utils.extend( window.KITYMINDER_CONFIG || {}, MinderDefaultOptions, options || {} );
this._initEvents();
this._initModules( option );
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( option.renderTo );
}
},
renderTo: function ( target ) {
this._paper.renderTo( this._renderTarget = target );
this._bindEvents();
KityMinder.addMinderInstance( target, this );
},
getRenderContainer: function () {
......@@ -24,3 +47,11 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
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
var MinderEvent = kity.createClass( 'MindEvent', {
constructor: function ( type, params, cancelable ) {
params = params || {};
if ( params.getType && params.getType() == 'ShapeEvent' ) {
this.kityEvent = params;
this.getPosition = params.getPosition.bind( params );
} else {
kity.Utils.extend( this, params );
}
this.type = type;
this._cancelable = cancelable || false;
if ( params.targetShape ) {
this.getTargetNode = function () {
var findShape = params.targetShape;
while ( !findShape.minderNode && findShape.container ) {
findShape = findShape.container;
}
return findShape.minderNode || null;
};
}
},
cancel: function () {
this._canceled = true;
},
cancelImmediately: function () {
this._immediatelyCanceld = true;
this._canceled = true;
},
shouldCancel: function () {
return this._cancelable && this._canceled;
},
shouldCancelImmediately: function () {
return this._cancelable && this._immediatelyCanceld;
}
} );
\ No newline at end of file
var Utils = KityMinder.Utils = {};
Utils.extend = kity.Utils.extend.bind( kity.Utils );
Utils.listen = function ( element, type, callback ) {
( element.addEventListener || element.attachEvent )( type, 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