Commit 65b73774 authored by techird's avatar techird

Module Example

parent 8402f4c8
......@@ -9,23 +9,8 @@
</body>
<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({
data: {
x: 50,
......@@ -53,9 +38,6 @@
}]
}]
});
console.log(minder);
minder.update();
m = minder;
//console.log(minder.exportData());
</script>
</html>
\ No newline at end of file
......@@ -5,12 +5,20 @@ $dependency = Array(
'src/core/command.js',
'src/core/mindernode.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 = "";
header('Content-Type: text/javascript');
header('Content-Type: text/javascript; charset=utf-8');
foreach ($dependency as $index => $dep) {
echo file_get_contents("../$dep")."\n\n";
......
......@@ -2,9 +2,10 @@
* 模块初始化函数:模块名称大写,以 Module 作为后缀
*/
KityMinder.registerModule( "ExampleModule", function () {
console.log( "You can cheat: 上下左右ABAB" );
// TODO: 初始化模块静态变量
var moduleVar = "moduleValue";
var cheatCode = "38 40 37 39 65 66 65 66".split( ' ' );
// TODO: 进行模块命令定义
// HINT: 复杂的命令也可以在其它的文件中定义
......@@ -19,6 +20,7 @@ KityMinder.registerModule( "ExampleModule", function () {
execute: function ( km ) {
// this.setContentChange(true) 可以告知 KM 命令的执行导致了内容的变化,KM会抛出 contentchange 事件
// this.setSelectionChange(true) 可以告知 KM 命令的执行导致了选区的变化,KM会抛出 selectionchange 事件
window.alert( 'you cheat!' );
},
/**
......@@ -49,7 +51,7 @@ KityMinder.registerModule( "ExampleModule", function () {
"commands": {
// 约定:命令名称全用小写
"example": ExampleCommand
"cheat": ExampleCommand
},
// TODO: 需要注册的事件
......@@ -59,17 +61,29 @@ KityMinder.registerModule( "ExampleModule", function () {
// 支持的鼠标事件:mousedown, mouseup, mousemove, click
},
"keydown keyup": function ( e ) {
"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 ) {
......
KityMinder.registerModule( "RenderModule", function () {
console.log( "render loaded" );
var DrawShapeCommand = kity.createClass( "DrawShapeCommand", {
base: Command,
......
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