Commit c9b61560 authored by Akikonata's avatar Akikonata

changed argument getting method

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