Skip to content

Commit

Permalink
add temlate feture
Browse files Browse the repository at this point in the history
  • Loading branch information
techird committed Jun 17, 2014
1 parent 0552156 commit 8f99760
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 5 deletions.
2 changes: 2 additions & 0 deletions import.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@
'core/connect.js',
'core/render.js',
'core/theme.js',
'core/template.js',
'layout/default.js',
'layout/default.connect.js',
'layout/bottom.js',
'layout/filetree.js',
'theme/default.js',
'theme/bottom.js',
'theme/filetree.js',
'template/bottom.js',
'module/node.js',
'module/text.js',
'module/outline.js',
Expand Down
63 changes: 63 additions & 0 deletions src/core/template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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;
}
})
}
});
10 changes: 5 additions & 5 deletions src/core/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ kity.extendClass(Minder, {
* 获取脑图实例上的当前主题
* @return {[type]} [description]
*/
getTheme: function() {
getTheme: function(node) {
return this._theme || KityMinder._defaultTheme;
},

/**
* 获得脑图实例上的样式
* @param {String} item 样式名称
*/
getStyle: function(item) {
var theme = KityMinder._themes[this.getTheme()];
getStyle: function(item, node) {
var theme = KityMinder._themes[this.getTheme(node)];
var segment, dir, selector, value, matcher;

if (item in theme) return theme[item];
Expand Down Expand Up @@ -102,8 +102,8 @@ kity.extendClass(Minder, {
* @param {String} name 样式名称,可以不加节点类型的前缀
*/
getNodeStyle: function(node, name) {
var value = this.getStyle(name);
return value !== null ? value : this.getStyle(node.getType() + '-' + name);
var value = this.getStyle(name, node);
return value !== null ? value : this.getStyle(node.getType() + '-' + name, node);
}
});

Expand Down
14 changes: 14 additions & 0 deletions src/template/bottom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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';
}
});

0 comments on commit 8f99760

Please sign in to comment.