Commit 5343aade authored by Akikonata's avatar Akikonata

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

parents 87a53298 d9a86469
......@@ -10,6 +10,7 @@
"predef" : [
"kity",
"MinderNode",
"MinderEvent",
"require",
"km",
"console",
......
......@@ -10,12 +10,50 @@
</body>
<script>
var minder = new km.KityMinder();
var node1 = new km.MinderNode().pipe(function () {
this.setData('x', 100);
this.setData('y', 100);
this.setData('text', "this is a text");
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);
});
minder.importData({
data: {
x: 50,
y: 50,
text: 'center',
},
children: [{
data: {
x: 200,
y: 50,
text: 'child1'
}
},{
data: {
x: 200,
y: 100,
text: 'child2'
},
children: [{
data: {
x: 350,
y: 100,
text: 'leaf'
}
}]
}]
});
minder.getRoot().insertChild(node1);
minder.update();
//console.log(minder.exportData());
</script>
</html>
\ No newline at end of file
......@@ -10,6 +10,8 @@ $dependency = Array(
$content = "";
header('Content-Type: text/javascript');
foreach ($dependency as $index => $dep) {
echo file_get_contents("../$dep")."\n\n";
}
\ No newline at end of file
Subproject commit 7f8b3b2743aa0ce609a3e8406d9efe8aa117accc
Subproject commit b6f3e9996353a089e7b78f603a66668a6a7354a3
......@@ -171,31 +171,149 @@ kity.extendClass(KityMinder, {
// 事件机制
kity.extendClass(KityMinder, {
_initEvents: function() {
this._eventCallbacks = {};
this._bindPaperEvents();
this._bindKeyboardEvents();
},
on: function( name, callback ) {
// TODO: mousemove lazy bind
_bindPaperEvents: function() {
var minder = this;
this.paper.on('click mousedown mouseup mousemove', this._firePharse.bind(this));
},
once: function( name, callback ) {
_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));
}
},
_firePharse: function(e) {
var beforeEvent, preEvent, executeEvent;
beforeEvent = new MinderEvent('before' + e.type, e, true);
if( this._fire(beforeEvent) ) {
return;
}
preEvent = new MinderEvent('pre' + e.type, e, false);
executeEvent = new MinderEvent(e.type, e, false);
this._fire(preEvent);
this._fire(executeEvent);
if(~'mousedown mouseup keydown keyup'.indexOf(e.type)) {
this._interactChange(e);
}
},
_interactChange: function(e) {
var minder = this;
clearTimeout(this.interactTimeout);
this.interactTimeout = setTimeout(function() {
var canceled = minder._fire(new MinderEvent('beforeinteractchange'));
if(canceled) {
return;
}
minder._fire(new MinderEvent('preinteractchange'));
minder._fire(new MinderEvent('interactchange'));
}, 300);
},
_listen: function( type, callback ) {
var callbacks = this._eventCallbacks[type] || (this._eventCallbacks[type] = []);
callbacks.push( callback );
},
_fire: function( e ) {
var callbacks = this._eventCallbacks[e.type];
if(!callbacks) {
return false;
}
for(var i = 0; i < callbacks.length; i++) {
callbacks[i].call(this, e);
if(e.shouldCancelImmediately()) {
break;
}
}
return e.shouldCancel();
},
on: function( name, callback ) {
var types = name.split(' ');
for(var i = 0; i < types.length; i++) {
this._listen( types[i], callback );
}
return this;
},
off: function( name, callback ) {
var types = name.split(' ');
var i, j, callbacks, removeIndex;
for(i = 0; i < types.length; i++) {
callbacks = this._eventCallbacks[ types[i] ];
if(callbacks) {
removeIndex = null;
for(j = 0; j < callbacks.length; j++) {
if(callbacks[j] == callback) {
removeIndex = j;
}
}
if(removeIndex !== null) {
callbacks.splice(removeIndex, 1);
}
}
}
},
fire: function( name, params ) {
fire: function( type, params ) {
var e = new MinderEvent(type, params);
this._fire(e);
return this;
}
});
// 导入导出
kity.extendClass(KityMinder, {
export: function() {
exportData: function(node) {
var exported = {};
node = node || this.getRoot();
exported.data = node.getData();
var childNodes = node.getChildren();
if(childNodes.length) {
exported.children = [];
for(var i = 0; i < childNodes.length; i++) {
exported.children.push(this.exportData(childNodes[i]));
}
}
return exported;
},
import: function() {
importData: function( treeData ) {
function importToNode(treeData, node) {
var data = treeData.data;
for(var field in data) {
node.setData(field, data[field]);
}
var childrenTreeData = treeData.children;
if(!childrenTreeData) return;
for(var i = 0; i < childrenTreeData.length; i++) {
var childNode = new MinderNode();
importToNode(childrenTreeData[i], childNode);
node.appendChild(childNode);
}
}
var params = { importData: treeData };
var canceled = this._fire(new MinderEvent('beforeimport', params , true));
if(canceled) return this;
this._fire(new MinderEvent('preimport', params, false));
while(this.root.getChildren().length) {
this.root.removeChild(0);
}
importToNode(treeData, this.root);
this._fire(new MinderEvent('import', params, false));
return this;
}
});
......
var MinderEvent = kity.createClass('MindEvent', {
constructor: function (type, params, cancelable) {
params = params || {};
kity.Utils.extend(this, params);
this.type = type;
this.cancelable = cancelable || false;
if(params.targetShape) {
this.targetNode = params.targetShape.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
......@@ -5,6 +5,7 @@ var MinderNode = km.MinderNode = kity.createClass("MinderNode", {
this.data = {};
this.tnh = treeNotifyHandler;
this.rc = new kity.Group();
this.rc.minderNode = this;
},
getParent: function() {
......
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