Commit 8f997604 authored by techird's avatar techird

add temlate feture

parent 05521569
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
'core/connect.js', 'core/connect.js',
'core/render.js', 'core/render.js',
'core/theme.js', 'core/theme.js',
'core/template.js',
'layout/default.js', 'layout/default.js',
'layout/default.connect.js', 'layout/default.connect.js',
'layout/bottom.js', 'layout/bottom.js',
...@@ -32,6 +33,7 @@ ...@@ -32,6 +33,7 @@
'theme/default.js', 'theme/default.js',
'theme/bottom.js', 'theme/bottom.js',
'theme/filetree.js', 'theme/filetree.js',
'template/bottom.js',
'module/node.js', 'module/node.js',
'module/text.js', 'module/text.js',
'module/outline.js', 'module/outline.js',
......
utils.extend(KityMinder, {
_templates: {},
registerTemplate: function(name, supports) {
KityMinder._templates[name] = supports;
}
});
kity.extendClass(Minder, (function() {
var originGetTheme = Minder.prototype.getTheme;
return {
useTemplate: function(name) {
this._template = name;
this.getRoot().traverse(function(node) {
node.render();
});
this.layout(300);
},
getTemplateSupports: function() {
return KityMinder._templates[this._template] || null;
},
getTheme: function(node) {
var supports = this.getTemplateSupports();
if (supports && supports.getTheme) {
return supports.getTheme(node);
}
return originGetTheme.call(this, node);
}
};
})());
kity.extendClass(MinderNode, (function() {
var originGetLayout = MinderNode.prototype.getLayout;
return {
getLayout: function() {
var supports = this.getMinder().getTemplateSupports();
if (supports && supports.getLayout) {
return supports.getLayout(this);
}
return originGetLayout.call(this);
}
};
})());
KityMinder.registerModule('TemplateModule', {
commands: {
'template': kity.createClass('TemplateCommand', {
base: Command,
execute: function(minder, name) {
minder.useTemplate(name);
},
queryCommandValue: function(minder) {
return minder._template;
}
})
}
});
\ No newline at end of file
...@@ -63,7 +63,7 @@ kity.extendClass(Minder, { ...@@ -63,7 +63,7 @@ kity.extendClass(Minder, {
* 获取脑图实例上的当前主题 * 获取脑图实例上的当前主题
* @return {[type]} [description] * @return {[type]} [description]
*/ */
getTheme: function() { getTheme: function(node) {
return this._theme || KityMinder._defaultTheme; return this._theme || KityMinder._defaultTheme;
}, },
...@@ -71,8 +71,8 @@ kity.extendClass(Minder, { ...@@ -71,8 +71,8 @@ kity.extendClass(Minder, {
* 获得脑图实例上的样式 * 获得脑图实例上的样式
* @param {String} item 样式名称 * @param {String} item 样式名称
*/ */
getStyle: function(item) { getStyle: function(item, node) {
var theme = KityMinder._themes[this.getTheme()]; var theme = KityMinder._themes[this.getTheme(node)];
var segment, dir, selector, value, matcher; var segment, dir, selector, value, matcher;
if (item in theme) return theme[item]; if (item in theme) return theme[item];
...@@ -102,8 +102,8 @@ kity.extendClass(Minder, { ...@@ -102,8 +102,8 @@ kity.extendClass(Minder, {
* @param {String} name 样式名称,可以不加节点类型的前缀 * @param {String} name 样式名称,可以不加节点类型的前缀
*/ */
getNodeStyle: function(node, name) { getNodeStyle: function(node, name) {
var value = this.getStyle(name); var value = this.getStyle(name, node);
return value !== null ? value : this.getStyle(node.getType() + '-' + name); return value !== null ? value : this.getStyle(node.getType() + '-' + name, node);
} }
}); });
......
KityMinder.registerTemplate('bottom', {
getLayout: function(node) {
if (node.getData('layout')) return node.getData('layout');
if (node.isRoot()) return 'bottom';
return 'filetree';
},
getTheme: function(node) {
return node.isRoot() ? 'bottom' : 'filetree';
}
});
\ 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