Commit 901b665d authored by Akikonata's avatar Akikonata

merge conflict

parents cc79a59d 6d54ebe4
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"kity", "kity",
"MinderNode", "MinderNode",
"MinderEvent", "MinderEvent",
"KityMinder",
"require", "require",
"km", "km",
"console", "console",
......
...@@ -9,23 +9,8 @@ ...@@ -9,23 +9,8 @@
</body> </body>
<script> <script>
var minder = new km.KityMinder(); minder = new km.KityMinder();
function allEvent () {
var events = 'click mousedown mouseup keydown keyup keypress dblclick interactchange contentchange selectionchange import'.split(' ');
var pharseEvents = [];
for(var i = 0; i < events.length; i++) {
pharseEvents.push('before' + events[i]);
pharseEvents.push('pre' + events[i]);
pharseEvents.push(events[i]);
}
return pharseEvents.join(' ');
}
minder.on(allEvent(), function(e) {
//console.log(e.type, e);
});
minder.importData({ minder.importData({
data: { data: {
x: 50, x: 50,
...@@ -53,9 +38,6 @@ ...@@ -53,9 +38,6 @@
}] }]
}] }]
}); });
console.log(minder);
minder.update(); minder.update();
m = minder;
//console.log(minder.exportData());
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -5,12 +5,20 @@ $dependency = Array( ...@@ -5,12 +5,20 @@ $dependency = Array(
'src/core/command.js', 'src/core/command.js',
'src/core/mindernode.js', 'src/core/mindernode.js',
'src/core/minderevent.js', 'src/core/minderevent.js',
'src/core/kityminder.js' 'src/core/kityminder.js',
'src/module/connect.js',
'src/module/history.js',
'src/module/icon.js',
'src/module/keyboard.js',
'src/module/layout.js',
'src/module/render.js',
'src/module/textedit.js',
'src/module/_example.js'
); );
$content = ""; $content = "";
header('Content-Type: text/javascript'); header('Content-Type: text/javascript; charset=utf-8');
foreach ($dependency as $index => $dep) { foreach ($dependency as $index => $dep) {
echo file_get_contents("../$dep")."\n\n"; echo file_get_contents("../$dep")."\n\n";
......
var mindermoduleDefaultTest = function () {
console.log( "test loaded" );
var stroredData = "stored";
return {
"commands": {
//todo:command字典,name-action 键值对模式编写
"testCommand": kity.createClass( "testCommand", {
base: Command,
"execute": function ( km, arg1, arg2, arg3 ) {
console.log( arg1, arg2, arg3 );
}
} ),
"testCommand2": kity.createClass( "testCommand", {
base: Command,
"execute": function ( km, arg1, arg2, arg3 ) {
console.log( arg1, arg2, arg3 );
}
} )
},
"events": {
//todo:事件响应函数绑定列表,事件名-响应函数 键值对模式编写
"click": function ( e ) {
window.alert( "hahaha" );
},
"keydown keyup": function ( e ) {
window.alert( "key" );
},
"beforecommand": function ( e ) {
console.log( "precommand:", e );
e.cancel();
},
"command": function ( e ) {
console.log( "command exec!", e );
},
"contentchange": function ( e ) {
console.log( "contentchange!" );
}
}
};
};
\ No newline at end of file
var mindermoduleTest = function () {
console.log( "test loaded" );
var stroredData = "stored";
return {
"ready": function () {
//todo:基本的初始化工作
console.log( stroredData );
},
"commands": {
//todo:command字典,name-action 键值对模式编写
"testCommand1": function ( km, arg ) {
console.log( "testCommand1" );
}
},
"events": {
//todo:事件响应函数绑定列表,事件名-响应函数 键值对模式编写
"click": function ( e ) {
},
"keydown keyup": function ( e ) {
}
}
};
};
\ No newline at end of file
...@@ -18,8 +18,8 @@ var KityMinder = km.KityMinder = kity.createClass( "KityMinder", { ...@@ -18,8 +18,8 @@ var KityMinder = km.KityMinder = kity.createClass( "KityMinder", {
this._rc.addShape( this._root.getRenderContainer() ); this._rc.addShape( this._root.getRenderContainer() );
}, },
getDrawingArea: function () { getRenderContainer: function () {
return this._paper; return this._rc;
} }
} ); } );
......
var MinderEvent = kity.createClass('MindEvent', { var MinderEvent = kity.createClass( 'MindEvent', {
constructor: function (type, params, cancelable) { constructor: function ( type, params, cancelable ) {
params = params || {}; params = params || {};
if(params.getType && params.getType() == 'ShapeEvent') { if ( params.getType && params.getType() == 'ShapeEvent' ) {
this.kityEvent = params; this.kityEvent = params;
this.getPosition = params.getPosition.bind(params); this.getPosition = params.getPosition.bind( params );
} else { } else {
kity.Utils.extend(this, params); kity.Utils.extend( this, params );
} }
this.type = type; this.type = type;
this._cancelable = cancelable || false; this._cancelable = cancelable || false;
if(params.targetShape) { if ( params.targetShape ) {
this.getTargetNode = function() { this.getTargetNode = function () {
var findShape = params.targetShape; var findShape = params.targetShape;
while(!findShape.minderNode && findShape.container) { while ( !findShape.minderNode && findShape.container ) {
findShape = findShape.container; findShape = findShape.container;
} }
return findShape.minderNode || null; return findShape.minderNode || null;
...@@ -20,20 +20,20 @@ var MinderEvent = kity.createClass('MindEvent', { ...@@ -20,20 +20,20 @@ var MinderEvent = kity.createClass('MindEvent', {
} }
}, },
cancel: function() { cancel: function () {
this._canceled = true; this._canceled = true;
}, },
cancelImmediately: function() { cancelImmediately: function () {
this._immediatelyCanceld = true; this._immediatelyCanceld = true;
this._canceled = true; this._canceled = true;
}, },
shouldCancel: function() { shouldCancel: function () {
return this._cancelable && this._canceled; return this._cancelable && this._canceled;
}, },
shouldCancelImmediately: function() { shouldCancelImmediately: function () {
return this._cancelable && this._immediatelyCanceld; return this._cancelable && this._immediatelyCanceld;
} }
}); } );
\ No newline at end of file \ No newline at end of file
var MinderNode = km.MinderNode = kity.createClass("MinderNode", { var MinderNode = km.MinderNode = kity.createClass( "MinderNode", {
constructor: function ( treeNotifyHandler ) { constructor: function ( treeNotifyHandler ) {
this.parent = null; this.parent = null;
this.children = []; this.children = [];
...@@ -8,88 +8,89 @@ var MinderNode = km.MinderNode = kity.createClass("MinderNode", { ...@@ -8,88 +8,89 @@ var MinderNode = km.MinderNode = kity.createClass("MinderNode", {
this.rc.minderNode = this; this.rc.minderNode = this;
}, },
getParent: function() { getParent: function () {
return this.parent; return this.parent;
}, },
getRoot: function() { getRoot: function () {
var root = this; var root = this;
while(root.parent) { while ( root.parent ) {
root = root.parent; root = root.parent;
} }
return root; return root;
}, },
getChildren: function() { getChildren: function () {
return this.children; return this.children;
}, },
getIndex: function() { getIndex: function () {
return this.parent ? this.parent.indexOf(this) : -1; return this.parent ? this.parent.indexOf( this ) : -1;
}, },
insertChild: function(node, index) { insertChild: function ( node, index ) {
if(index === undefined) { if ( index === undefined ) {
index = this.children.length; index = this.children.length;
} }
if(node.parent) { if ( node.parent ) {
node.parent.removeChild(node); node.parent.removeChild( node );
} }
node.parent = this; node.parent = this;
this.children.splice(index, 0, node); this.children.splice( index, 0, node );
this.handelInsert(node); this.handelInsert( node );
}, },
handelInsert: function(node) { handelInsert: function ( node ) {
var root = this.getRoot(); var root = this.getRoot();
if(root.tnh) { if ( root.tnh ) {
root.tnh.handelNodeInsert.call( root.tnh, node ); root.tnh.handelNodeInsert.call( root.tnh, node );
} }
}, },
appendChild: function(node) { appendChild: function ( node ) {
return this.insertChild(node); return this.insertChild( node );
}, },
prependChild: function(node) { prependChild: function ( node ) {
return this.insertChild(node, 0); return this.insertChild( node, 0 );
}, },
removeChild: function(elem) { removeChild: function ( elem ) {
var index = elem, removed; var index = elem,
if(elem instanceof MinderNode) { removed;
index = this.children.indexOf(elem); if ( elem instanceof MinderNode ) {
index = this.children.indexOf( elem );
} }
if(index >= 0) { if ( index >= 0 ) {
removed = this.children.splice(index, 1)[0]; removed = this.children.splice( index, 1 )[ 0 ];
removed.parent = null; removed.parent = null;
this.handelRemove(removed); this.handelRemove( removed );
} }
}, },
handelRemove: function(node) { handelRemove: function ( node ) {
var root = this.getRoot(); var root = this.getRoot();
if(root.tnh) { if ( root.tnh ) {
root.tnh.handelNodeRemove.call( root.tnh, node ); root.tnh.handelNodeRemove.call( root.tnh, node );
} }
}, },
getChild: function(index) { getChild: function ( index ) {
return this.children[index]; return this.children[ index ];
}, },
getData: function(name) { getData: function ( name ) {
if(name === undefined) { if ( name === undefined ) {
return this.data; return this.data;
} }
return this.data[name]; return this.data[ name ];
}, },
setData: function(name, value) { setData: function ( name, value ) {
this.data[name] = value; this.data[ name ] = value;
}, },
getRenderContainer: function() { getRenderContainer: function () {
return this.rc; return this.rc;
} }
}); } );
\ No newline at end of file \ No newline at end of file
/**
* 模块初始化函数:模块名称大写,以 Module 作为后缀
*/
KityMinder.registerModule( "ExampleModule", function () {
console.log( "You can cheat: 上下左右ABAB" );
// TODO: 初始化模块静态变量
var cheatCode = "38 40 37 39 65 66 65 66".split( ' ' );
// TODO: 进行模块命令定义
// HINT: 复杂的命令也可以在其它的文件中定义
var ExampleCommand = kity.createClass( "ExampleCommand", {
base: Command,
/**
* 命令执行函数
* @required
* @param {KityMinder} km 命令执行时的 KityMinder 实例
*/
execute: function ( km ) {
// this.setContentChange(true) 可以告知 KM 命令的执行导致了内容的变化,KM会抛出 contentchange 事件
// this.setSelectionChange(true) 可以告知 KM 命令的执行导致了选区的变化,KM会抛出 selectionchange 事件
window.alert( 'you cheat!' );
},
/**
* 命令状态查询
* @optional
* @param {KityMinder} km 命令查询针对的 KityMinder 实例
* @return {int} 返回 0 表示命令在正常状态(Default)
* 返回 1 表示命令在生效的状态
* 返回 -1 表示命令当前不可用
*/
queryState: function ( km ) {
},
/**
* 命令当前值查询
* @param {KityMinder} km 命令查询针对的 KityMinder 实例
* @return {any} 返回命令自定义类型数据。
*/
queryValue: function ( km ) {
}
} );
return {
// TODO: 需要注册的命令
"commands": {
// 约定:命令名称全用小写
"cheat": ExampleCommand
},
// TODO: 需要注册的事件
"events": {
"click": function ( e ) {
// 支持的鼠标事件:mousedown, mouseup, mousemove, click
},
"keydown": function ( e ) {
// 支持的键盘事件:keydown, keyup, keypress
if ( !this._cheated || this._cheated[ 0 ] != e.keyCode ) {
this._cheated = cheatCode.slice( 0 );
}
if ( this._cheated[ 0 ] == e.keyCode ) {
this._cheated.shift();
}
console.log( this._cheated );
if ( this._cheated.length === 0 ) {
this.execCommand( 'cheat' );
}
},
"beforecommand": function ( e ) {
// e.cancel() 方法可以阻止 before 事件进入下个阶段
// e.cancelImmediately() 方法可以阻止当前回调后的回调执行,并且阻止事件进入下个阶段
console.log( e.type + ' fired' );
},
"command": function ( e ) {
// 命令执行后的事件
console.log( e.type + ' fired' );
},
"contentchange": function ( e ) {
// 内容改变后的事件
},
"selectionchange": function ( e ) {
// 选区改变后的事件
}
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "ConnectModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "HistoryModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "IconModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "KeyboardModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ No newline at end of file
KityMinder.registerModule( "LayoutModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ No newline at end of file
var mindermoduleRender = function () { KityMinder.registerModule( "RenderModule", function () {
console.log( "render loaded" );
var commandDrawShape = kity.createClass( "commandDrawShape", { var DrawShapeCommand = kity.createClass( "DrawShapeCommand", {
base: Command, base: Command,
"execute": function ( km, config ) { execute: function ( km, config ) {
var node = kity.createClass( {
base: kity.Group,
} );
} }
} ); } );
return { return {
"commands": { "commands": {
//todo:command字典,name-action 键值对模式编写 //todo:command字典,name-action 键值对模式编写
ommandDrawRect: commandDrawShape "drawrect": DrawShapeCommand
}, },
"events": { "events": {
...@@ -27,4 +23,4 @@ var mindermoduleRender = function () { ...@@ -27,4 +23,4 @@ var mindermoduleRender = function () {
} }
} }
}; };
}; } );
\ No newline at end of file \ No newline at end of file
KityMinder.registerModule( "TextEditModule", function () {
return {
"commands": {
},
"events": {
}
};
} );
\ 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