Commit c9b61560 authored by Akikonata's avatar Akikonata

changed argument getting method

parent 9631b740
...@@ -46,15 +46,16 @@ ...@@ -46,15 +46,16 @@
_root.setData("appendside","right"); _root.setData("appendside","right");
minder.renderNode(_root); minder.renderNode(_root);
minder.execCommand("createchildnode",_root);
//模拟生成一个初始图 //模拟生成一个初始图
for(var j=0;j<20;j++){ // for(var j=0;j<20;j++){
var appendSide = Math.random()>0.5?"left":"right"; // var appendSide = Math.random()>0.5?"left":"right";
var layerArray = _root.getData("layer"+appendSide); // var layerArray = _root.getData("layer"+appendSide);
var layer = parseInt(Math.random()*layerArray.length); // var layer = parseInt(Math.random()*layerArray.length);
var layerData = layerArray[layer]; // var layerData = layerArray[layer];
var root = layerData[parseInt(Math.random()*layerData.length)] // var root = layerData[parseInt(Math.random()*layerData.length)]
minder.execCommand("createchildnode",root); // minder.execCommand("createchildnode",root);
} // }
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -31,7 +31,7 @@ var Command = kity.createClass( "Command", { ...@@ -31,7 +31,7 @@ var Command = kity.createClass( "Command", {
queryValue: function ( km ) { queryValue: function ( km ) {
return 0; return 0;
}, },
isNeedUndo:function(){ isNeedUndo: function () {
return true; return true;
} }
} ); } );
\ No newline at end of file
...@@ -5,29 +5,30 @@ kity.extendClass( Minder, { ...@@ -5,29 +5,30 @@ kity.extendClass( Minder, {
_queryCommand: function ( name, type, args ) { _queryCommand: function ( name, type, args ) {
var cmd = this._getCommand( name ); var cmd = this._getCommand( name );
if(cmd){ if ( cmd ) {
var queryCmd = cmd['query' + type]; var queryCmd = cmd[ 'query' + type ];
if(queryCmd) if ( queryCmd )
return queryCmd.apply(cmd,[this].concat(args)) return queryCmd.apply( cmd, [ this ].concat( args ) );
} }
return 0 return 0;
}, },
queryCommandState: function ( name ) { queryCommandState: function ( name ) {
return this._queryCommand( name, "State",utils.argsToArray(1)); return this._queryCommand( name, "State", Utils.argsToArray( 1 ) );
}, },
queryCommandValue: function ( name ) { queryCommandValue: function ( name ) {
return this._queryCommand( name, "Value",utils.argsToArray(1)); return this._queryCommand( name, "Value", Utils.argsToArray( 1 ) );
}, },
execCommand: function ( name ) { execCommand: function ( name ) {
name = name.toLowerCase(); name = name.toLowerCase();
var cmdArgs = utils.argsToArray(1), cmd, stoped, result, eventParams; var cmdArgs = Array.prototype.slice.call( arguments, 1 ),
cmd, stoped, result, eventParams;
var me = this; var me = this;
cmd = this._getCommand( name ); cmd = this._getCommand( name );
console.log( cmdArgs );
eventParams = { eventParams = {
command: cmd, command: cmd,
...@@ -38,13 +39,13 @@ kity.extendClass( Minder, { ...@@ -38,13 +39,13 @@ kity.extendClass( Minder, {
return false; return false;
} }
if(!this._hasEnterExecCommand && cmd.isNeedUndo()){ if ( !this._hasEnterExecCommand && cmd.isNeedUndo() ) {
this._hasEnterExecCommand = true; this._hasEnterExecCommand = true;
stoped = this._fire( new MinderEvent( 'beforeExecCommand', eventParams, true ) ); stoped = this._fire( new MinderEvent( 'beforeExecCommand', eventParams, true ) );
if ( !stoped ) { if ( !stoped ) {
//保存场景 //保存场景
this._fire(new MinderEvent( 'saveScene' )); this._fire( new MinderEvent( 'saveScene' ) );
this._fire( new MinderEvent( "preExecCommand", eventParams, false ) ); this._fire( new MinderEvent( "preExecCommand", eventParams, false ) );
...@@ -53,7 +54,7 @@ kity.extendClass( Minder, { ...@@ -53,7 +54,7 @@ kity.extendClass( Minder, {
this._fire( new MinderEvent( 'execCommand', eventParams, false ) ); this._fire( new MinderEvent( 'execCommand', eventParams, false ) );
//保存场景 //保存场景
this._fire(new MinderEvent( 'saveScene' )); this._fire( new MinderEvent( 'saveScene' ) );
if ( cmd.isContentChanged() ) { if ( cmd.isContentChanged() ) {
this._firePharse( new MinderEvent( 'contentchange' ) ); this._firePharse( new MinderEvent( 'contentchange' ) );
...@@ -64,7 +65,7 @@ kity.extendClass( Minder, { ...@@ -64,7 +65,7 @@ kity.extendClass( Minder, {
this._firePharse( new MinderEvent( 'interactchange' ) ); this._firePharse( new MinderEvent( 'interactchange' ) );
} }
this._hasEnterExecCommand = false; this._hasEnterExecCommand = false;
}else{ } else {
result = cmd.execute.apply( cmd, [ me ].concat( cmdArgs ) ); result = cmd.execute.apply( cmd, [ me ].concat( cmdArgs ) );
} }
......
var utils = Utils = KityMinder.Utils = { var utils = Utils = KityMinder.Utils = {
extend : kity.Utils.extend.bind( kity.Utils ), extend: kity.Utils.extend.bind( kity.Utils ),
listen : function ( element, type, handler ) { listen: function ( element, type, handler ) {
var types = utils.isArray(type) ? type : utils.trim(type).split(/\s+/), var types = utils.isArray( type ) ? type : utils.trim( type ).split( /\s+/ ),
k = types.length; k = types.length;
if (k) while (k--) { if ( k )
type = types[k]; while ( k-- ) {
if (element.addEventListener) { type = types[ k ];
element.addEventListener(type, handler, false); if ( element.addEventListener ) {
element.addEventListener( type, handler, false );
} else { } else {
if (!handler._d) { if ( !handler._d ) {
handler._d = { handler._d = {
els : [] els: []
}; };
} }
var key = type + handler.toString(),index = utils.indexOf(handler._d.els,element); var key = type + handler.toString(),
if (!handler._d[key] || index == -1) { index = utils.indexOf( handler._d.els, element );
if(index == -1){ if ( !handler._d[ key ] || index == -1 ) {
handler._d.els.push(element); if ( index == -1 ) {
handler._d.els.push( element );
} }
if(!handler._d[key]){ if ( !handler._d[ key ] ) {
handler._d[key] = function (evt) { handler._d[ key ] = function ( evt ) {
return handler.call(evt.srcElement, evt || window.event); return handler.call( evt.srcElement, evt || window.event );
}; };
} }
element.attachEvent('on' + type, handler._d[key]); element.attachEvent( 'on' + type, handler._d[ key ] );
} }
} }
} }
element = null; element = null;
}, },
trim : function (str) { trim: function ( str ) {
return str.replace(/(^[ \t\n\r]+)|([ \t\n\r]+$)/g, ''); return str.replace( /(^[ \t\n\r]+)|([ \t\n\r]+$)/g, '' );
}, },
each : function(obj, iterator, context){ each: function ( obj, iterator, context ) {
if (obj == null) return; if ( obj == null ) return;
if (obj.length === +obj.length) { if ( obj.length === +obj.length ) {
for (var i = 0, l = obj.length; i < l; i++) { for ( var i = 0, l = obj.length; i < l; i++ ) {
if(iterator.call(context, i,obj[i], obj) === false) if ( iterator.call( context, i, obj[ i ], obj ) === false )
return false; return false;
} }
} else { } else {
for (var key in obj) { for ( var key in obj ) {
if (obj.hasOwnProperty(key)) { if ( obj.hasOwnProperty( key ) ) {
if(iterator.call(context, key,obj[key], obj) === false) if ( iterator.call( context, key, obj[ key ], obj ) === false )
return false; return false;
} }
} }
} }
}, },
addCssRule : function (key, style, doc) { addCssRule: function ( key, style, doc ) {
var head, node; var head, node;
if(style === undefined || style && style.nodeType && style.nodeType == 9){ if ( style === undefined || style && style.nodeType && style.nodeType == 9 ) {
//获取样式 //获取样式
doc = style && style.nodeType && style.nodeType == 9 ? style : (doc || document); doc = style && style.nodeType && style.nodeType == 9 ? style : ( doc || document );
node = doc.getElementById(key); node = doc.getElementById( key );
return node ? node.innerHTML : undefined; return node ? node.innerHTML : undefined;
} }
doc = doc || document; doc = doc || document;
node = doc.getElementById(key); node = doc.getElementById( key );
//清除样式 //清除样式
if(style === ''){ if ( style === '' ) {
if(node){ if ( node ) {
node.parentNode.removeChild(node); node.parentNode.removeChild( node );
return true return true
} }
return false; return false;
} }
//添加样式 //添加样式
if(node){ if ( node ) {
node.innerHTML = style; node.innerHTML = style;
}else{ } else {
node = doc.createElement('style'); node = doc.createElement( 'style' );
node.id = key; node.id = key;
node.innerHTML = style; node.innerHTML = style;
doc.getElementsByTagName('head')[0].appendChild(node); doc.getElementsByTagName( 'head' )[ 0 ].appendChild( node );
} }
}, },
keys : function ( plain ) { keys: function ( plain ) {
var keys = []; var keys = [];
for ( var key in plain ) { for ( var key in plain ) {
if ( plain.hasOwnProperty( key ) ) { if ( plain.hasOwnProperty( key ) ) {
...@@ -88,30 +90,30 @@ var utils = Utils = KityMinder.Utils = { ...@@ -88,30 +90,30 @@ var utils = Utils = KityMinder.Utils = {
} }
return keys; return keys;
}, },
proxy : function(fn,context){ proxy: function ( fn, context ) {
return function () { return function () {
return fn.apply(context, arguments); return fn.apply( context, arguments );
}; };
}, },
indexOf:function (array, item, start) { indexOf: function ( array, item, start ) {
var index = -1; var index = -1;
start = this.isNumber(start) ? start : 0; start = this.isNumber( start ) ? start : 0;
this.each(array, function (v, i) { this.each( array, function ( v, i ) {
if (i >= start && v === item) { if ( i >= start && v === item ) {
index = i; index = i;
return false; return false;
} }
}); } );
return index; return index;
}, },
argsToArray:function(index){ argsToArray: function ( index ) {
return Array.prototype.slice.call( arguments, index||0); return Array.prototype.slice.call( arguments, index || 0 );
} }
}; };
Utils.each(['String', 'Function', 'Array', 'Number', 'RegExp', 'Object'], function (i,v) { Utils.each( [ 'String', 'Function', 'Array', 'Number', 'RegExp', 'Object' ], function ( i, v ) {
KityMinder.Utils['is' + v] = function (obj) { KityMinder.Utils[ 'is' + v ] = function ( obj ) {
return Object.prototype.toString.apply(obj) == '[object ' + v + ']'; return Object.prototype.toString.apply( obj ) == '[object ' + v + ']';
} }
}); } );
\ No newline at end of file \ No newline at end of file
...@@ -83,6 +83,7 @@ KityMinder.registerModule( "LayoutModule", function () { ...@@ -83,6 +83,7 @@ KityMinder.registerModule( "LayoutModule", function () {
}; };
var createChildNode = function ( km, parent, index ) { var createChildNode = function ( km, parent, index ) {
console.log( km, parent );
var root = km.getRoot(); var root = km.getRoot();
var appendSide = parent.getData( "appendside" ); var appendSide = parent.getData( "appendside" );
var _node = new MinderNode(); var _node = new MinderNode();
......
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