Commit 4b354b10 authored by techird's avatar techird

make private sign

parent d9a86469
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"undef" : true, "undef" : true,
"unused" : false, "unused" : false,
"strict" : false, "strict" : false,
"curly" : true, "curly" : false,
"newcap" : true, "newcap" : true,
"trailing" : true, "trailing" : true,
"white": false, "white": false,
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
} }
minder.on(allEvent(), function(e) { minder.on(allEvent(), function(e) {
console.log(e.type); //console.log(e.type, e);
}); });
minder.importData({ minder.importData({
data: { data: {
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
data: { data: {
x: 200, x: 200,
y: 100, y: 100,
text: 'child2' text: 'child2'
}, },
children: [{ children: [{
data: { data: {
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
}] }]
}] }]
}); });
console.log(minder);
minder.update(); minder.update();
m = minder;
//console.log(minder.exportData()); //console.log(minder.exportData());
</script> </script>
</html> </html>
\ No newline at end of file
var KityMinderId = 0;
var KityMinder = km.KityMinder = kity.createClass("KityMinder", { var KityMinder = km.KityMinder = kity.createClass("KityMinder", {
constructor: function (id, option) { constructor: function (id, option) {
// 初始化 // 初始化
...@@ -7,14 +9,14 @@ var KityMinder = km.KityMinder = kity.createClass("KityMinder", { ...@@ -7,14 +9,14 @@ var KityMinder = km.KityMinder = kity.createClass("KityMinder", {
}, },
_initMinder: function(id, option) { _initMinder: function(id, option) {
this.id = id; this.id = id || KityMinderId++;
this.rc = new kity.Group(); this._rc = new kity.Group();
this.paper = new kity.Paper(option.renderTo || document.body); this._paper = new kity.Paper(option.renderTo || document.body);
this.paper.addShape(this.rc); this._paper.addShape(this._rc);
this.root = new MinderNode(this); this._root = new MinderNode(this);
this.rc.addShape(this.root.getRenderContainer()); this._rc.addShape(this._root.getRenderContainer());
} }
}); });
...@@ -118,7 +120,7 @@ kity.extendClass(KityMinder, (function(){ ...@@ -118,7 +120,7 @@ kity.extendClass(KityMinder, (function(){
kity.extendClass(KityMinder, { kity.extendClass(KityMinder, {
getRoot: function() { getRoot: function() {
return this.root; return this._root;
}, },
traverse: function( node, fn ) { traverse: function( node, fn ) {
...@@ -131,18 +133,18 @@ kity.extendClass(KityMinder, { ...@@ -131,18 +133,18 @@ kity.extendClass(KityMinder, {
handelNodeInsert: function(node) { handelNodeInsert: function(node) {
this.traverse(node, function(current) { this.traverse(node, function(current) {
this.rc.addShape(current.getRenderContainer()); this._rc.addShape(current.getRenderContainer());
}); });
}, },
handelNodeRemove: function(node) { handelNodeRemove: function(node) {
this.traverse(node, function(current) { this.traverse(node, function(current) {
this.rc.removeShape(current.getRenderContainer()); this._rc.removeShape(current.getRenderContainer());
}); });
}, },
update: function( node ) { update: function( node ) {
node = node || this.root; node = node || this._root;
this.traverse(node, function(current) { this.traverse(node, function(current) {
var rc = current.getRenderContainer(); var rc = current.getRenderContainer();
var x = current.getData('x') || 0, var x = current.getData('x') || 0,
...@@ -177,7 +179,7 @@ kity.extendClass(KityMinder, { ...@@ -177,7 +179,7 @@ kity.extendClass(KityMinder, {
// TODO: mousemove lazy bind // TODO: mousemove lazy bind
_bindPaperEvents: function() { _bindPaperEvents: function() {
var minder = this; var minder = this;
this.paper.on('click mousedown mouseup mousemove', this._firePharse.bind(this)); this._paper.on('click mousedown mouseup mousemove', this._firePharse.bind(this));
}, },
_bindKeyboardEvents: function() { _bindKeyboardEvents: function() {
var minder = this; var minder = this;
...@@ -300,18 +302,22 @@ kity.extendClass(KityMinder, { ...@@ -300,18 +302,22 @@ kity.extendClass(KityMinder, {
node.appendChild(childNode); node.appendChild(childNode);
} }
} }
var params = { importData: treeData }; var params = { importData: treeData };
var canceled = this._fire(new MinderEvent('beforeimport', params , true)); var canceled = this._fire(new MinderEvent('beforeimport', params , true));
if(canceled) return this; if(canceled) return this;
this._fire(new MinderEvent('preimport', params, false)); this._fire(new MinderEvent('preimport', params, false));
while(this.root.getChildren().length) { while(this._root.getChildren().length) {
this.root.removeChild(0); this._root.removeChild(0);
} }
importToNode(treeData, this.root); importToNode(treeData, this._root);
this._fire(new MinderEvent('import', params, false)); this._fire(new MinderEvent('import', params, false));
this._firePharse( {type: 'contentchange'} );
return this; return this;
} }
}); });
...@@ -319,22 +325,52 @@ kity.extendClass(KityMinder, { ...@@ -319,22 +325,52 @@ kity.extendClass(KityMinder, {
// 选区管理 // 选区管理
kity.extendClass(KityMinder, { kity.extendClass(KityMinder, {
getSelectedNodes: function() { getSelectedNodes: function() {
return this._selectedNodes || (this._selectedNodes = []);
}, },
select: function( nodes ) { select: function( nodes ) {
var selection = this.getSelectedNodes();
if(false === nodes instanceof Array) nodes = [nodes];
for(var i = 0; i < nodes.length; i++) {
if(selection.indexOf(nodes[i]) !== -1) {
selection.push(nodes[i]);
}
}
return this;
}, },
selectSingle: function( node ) { selectSingle: function( node ) {
return this.clearSelect().select( node );
}, },
toggleSelect: function( nodes ) { toggleSelect: function( nodes ) {
var selection = this.getSelectedNodes();
var needAdd = [], needRemove = [];
if(false === nodes instanceof Array) nodes = [nodes];
for(var i = 0; i < nodes.length; i++) {
if(selection.indexOf(nodes[i]) === -1) {
needAdd.push(nodes[i]);
} else {
needRemove.push(nodes[i]);
}
}
this.clearSelect( needRemove );
this.select( needAdd );
}, },
clearSelect: function( nodes ) { clearSelect: function( nodes ) {
if(!nodes) {
this._selectedNodes = [];
return this;
}
var originSelection = this.getSelectedNodes();
var newSelection = [];
for(var i = 0; i < originSelection.length; i++) {
if(nodes.indexOf(originSelection[i]) !== -1) {
newSelection.push(originSelection[i]);
}
}
this._selectedNodes = newSelection;
return this;
} }
}); });
\ No newline at end of file
var MinderEvent = kity.createClass('MindEvent', { var MinderEvent = kity.createClass('MindEvent', {
constructor: function (type, params, cancelable) { constructor: function (type, params, cancelable) {
params = params || {}; params = params || {};
kity.Utils.extend(this, params); if(params.getType && params.getType() == 'ShapeEvent') {
this.kityEvent = params;
this.getPosition = params.getPosition.bind(params);
} else {
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.targetNode = params.targetShape.minderNode || null; this.getTargetNode = function() {
var findShape = params.targetShape;
while(!findShape.minderNode && findShape.container) {
findShape = findShape.container;
}
return findShape.minderNode || null;
};
} }
}, },
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
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