Commit a2631cfa authored by Akikonata's avatar Akikonata

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

parents 75836c57 fbde29d7
.idea
*.sublime-project
*.sublime-workspace
\ No newline at end of file
{
"undef" : true,
"unused" : false,
"strict" : false,
"curly" : true,
"newcap" : true,
"trailing" : true,
"white": false,
"quotmark": false,
"predef" : [
"kity",
"MinderNode",
"require",
"km"
]
}
\ No newline at end of file
var fs = require('fs');
var dependience = [
'src/core/km.js',
'src/core/command.js',
'src/core/mindernode.js',
'src/core/minderevent.js',
'src/core/kityminder.js'
];
var buildPath = 'dist/kityminder.js';
var contents = [], content;
while(dependience.length) {
contents.push(fs.readFileSync(dependience.shift()));
}
content = contents.join('\n\n');
content = '(function(kity, window) {\n\n' + content + '\n\n})(kity, window);';
fs.writeFileSync(buildPath, content);
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<script src="../kity/dist/kitygraph.all.js"></script>
<script src="../dist/dev.php"></script>
</head>
<body>
</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");
});
minder.getRoot().insertChild(node1);
minder.update();
</script>
</html>
\ No newline at end of file
<?php
$dependency = Array(
'src/core/km.js',
'src/core/command.js',
'src/core/mindernode.js',
'src/core/minderevent.js',
'src/core/kityminder.js'
);
$content = "";
foreach ($dependency as $index => $dep) {
echo file_get_contents("../$dep")."\n\n";
}
\ No newline at end of file
var KityMinder = kity.createClass("KityMinder", {
var KityMinder = km.KityMinder = kity.createClass("KityMinder", {
constructor: function (id, option) {
// 初始化
this._initMinder(id, option || {});
this._initModules();
this._initEvents();
},
_initMinder: function(id, option) {
this.id = id;
this.rc = new kity.Group();
this.paper = new kity.Paper(option.renderTo || document.body);
this.paper.addShape(this.rc);
this.root = new MinderNode(this);
this.rc.addShape(this.root.getRenderContainer());
}
});
KityMinder.version = '1.0.0.0';
KityMinder.debug = true;
// 模块注册
KityMinder.registerModule = function( name, module ) {
//初始化模块列表
......@@ -60,12 +70,44 @@ kity.extendClass(KityMinder, {
// 节点控制
kity.extendClass(KityMinder, {
getRoot: function() {
return this.root;
},
traverse: function( node, fn ) {
var children = node.getChildren();
for(var i = 0; i < children.length; i++) {
this.traverse(children[i], fn);
}
fn.call(this, node);
},
update: function( node ) {
handelNodeInsert: function(node) {
this.traverse(node, function(current) {
this.rc.addShape(current.getRenderContainer());
});
},
handelNodeRemove: function(node) {
this.traverse(node, function(current) {
this.rc.removeShape(current.getRenderContainer());
});
},
update: function( node ) {
node = node || this.root;
this.traverse(node, function(current) {
var rc = current.getRenderContainer();
var x = current.getData('x') || 0,
y = current.getData('y') || 0;
rc.setTransform(new kity.Matrix().translate(x, y));
if(!rc.textContainer) {
rc.textContainer = new kity.Text();
rc.addShape(rc.textContainer);
}
rc.textContainer.setContent(current.getData('text') || '');
});
}
});
......
var km = window.km = {};
km.version = '1.0.0.0';
\ No newline at end of file
var MinderNode = kity.createClass("MinderNode", {
constructor: function () {
var MinderNode = km.MinderNode = kity.createClass("MinderNode", {
constructor: function ( treeNotifyHandler ) {
this.parent = null;
this.children = [];
this.data = {};
this.tnh = treeNotifyHandler;
this.rc = new kity.Group();
},
getParent: function() {
return this.parent;
},
getRoot: function() {
var root = this;
while(root.parent) {
root = root.parent;
}
return root;
},
getChildren: function() {
return this.children;
},
getIndex: function() {
return this.parent ? this.parent.indexOf(this) : -1;
},
insertChild: function(node, index) {
if(index === undefined) {
index = this.children.length;
}
if(node.parent) {
node.parent.removeChild(node);
}
node.parent = this;
this.children.splice(index, 0, node);
this.handelInsert(node);
},
handelInsert: function(node) {
var root = this.getRoot();
if(root.tnh) {
root.tnh.handelNodeInsert.call( root.tnh, node );
}
},
appendChild: function(node) {
return this.insertChild(node);
},
prependChild: function(node) {
return this.insertChild(node, 0);
},
removeChild: function(elem) {
var index = elem, removed;
if(elem instanceof MinderNode) {
index = this.children.indexOf(elem);
}
if(index >= 0) {
removed = this.children.splice(index, 1)[0];
removed.parent = null;
this.handelRemove(removed);
}
},
handelRemove: function(node) {
var root = this.getRoot();
if(root.tnh) {
root.tnh.handelNodeRemove.call( root.tnh, node );
}
},
getChild: function(index) {
return this.children[index];
},
getData: function(name) {
if(name === undefined) {
return this.data;
}
return this.data[name];
},
setData: function(name, value) {
this.data[name] = value;
},
getRenderContainer: function() {
return this.rc;
}
});
\ 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