Commit 135460ed authored by techird's avatar techird

Merge branch 'dev' of github.com:fex-team/kityminder into dev

parents d471a6a8 543a0834
Subproject commit 022e5cb489e65df8a38eedf8508478ee1d29c29c Subproject commit 437d9c160a7961a3843cce3d9e2b01f64090f0df
utils.extend( KityMinder, function () { utils.extend(KityMinder, function() {
var _kityminderUI = {}, var _kityminderUI = {},
_kityminderToolbarUI = {}, _kityminderToolbarUI = {},
_activeWidget = null, _activeWidget = null,
_widgetData = {}, _widgetData = {},
_widgetCallBack = {}; _widgetCallBack = {};
return { return {
registerUI: function ( uiname, fn ) { registerUI: function(uiname, fn) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) { utils.each(uiname.split(/\s+/), function(i, name) {
_kityminderUI[ name ] = fn; _kityminderUI[name] = fn;
} ); });
}, },
registerToolbarUI: function ( uiname, fn ) { registerToolbarUI: function(uiname, fn) {
utils.each( uiname.split( /\s+/ ), function ( i, name ) { utils.each(uiname.split(/\s+/), function(i, name) {
_kityminderToolbarUI[ name ] = fn; _kityminderToolbarUI[name] = fn;
} ); });
}, },
loadUI: function ( km ) { loadUI: function(km) {
utils.each( _kityminderUI, function ( i, fn ) { utils.each(_kityminderUI, function(i, fn) {
fn.call( km ); fn.call(km);
} ); });
}, },
_createUI: function ( id ) { _createUI: function(id) {
var $cont = $( '<div class="kmui-container"></div>' ), var $cont = $('<div class="kmui-container"></div>'),
$toolbar = $.kmuitoolbar(), $toolbar = $.kmuitoolbar(),
$kmbody = $( '<div class="kmui-editor-body"></div>' ), $kmbody = $('<div class="kmui-editor-body"></div>'),
$statusbar = $( '<div class="kmui-statusbar"></div>' ); $statusbar = $('<div class="kmui-statusbar"></div>');
$cont.append( $toolbar ).append( $kmbody ).append( $statusbar ); $cont.append($toolbar).append($kmbody).append($statusbar);
$( utils.isString( id ) ? '#' + id : id ).append( $cont ); $(utils.isString(id) ? '#' + id : id).append($cont);
return { return {
'$container': $cont, '$container': $cont,
...@@ -36,108 +36,109 @@ utils.extend( KityMinder, function () { ...@@ -36,108 +36,109 @@ utils.extend( KityMinder, function () {
'$statusbar': $statusbar '$statusbar': $statusbar
}; };
}, },
_createToolbar: function ( $toolbar, km ) { _createToolbar: function($toolbar, km) {
var toolbars = km.getOptions( 'toolbars' ); var toolbars = km.getOptions('toolbars');
if ( toolbars && toolbars.length ) { if (toolbars && toolbars.length) {
var btns = []; var btns = [];
$.each( toolbars, function ( i, uiNames ) { $.each(toolbars, function(i, uiNames) {
$.each( uiNames.split( /\s+/ ), function ( index, name ) { $.each(uiNames.split(/\s+/), function(index, name) {
if ( name == '|' ) { if (name == '|') {
if ($.kmuiseparator) btns.push( $.kmuiseparator() ); if ($.kmuiseparator) btns.push($.kmuiseparator());
} else { } else {
if ( _kityminderToolbarUI[ name ] ) { if (_kityminderToolbarUI[name]) {
var ui = _kityminderToolbarUI[ name ].call( km, name ); var ui = _kityminderToolbarUI[name].call(km, name);
if (ui) btns.push( ui ); if (ui) btns.push(ui);
} }
} }
} ); });
if (btns.length) $toolbar.kmui().appendToBtnmenu( btns ); if (btns.length) $toolbar.kmui().appendToBtnmenu(btns);
} ); });
$toolbar.append( $( '<div class="kmui-dialog-container"></div>' ) ); $toolbar.append($('<div class="kmui-dialog-container"></div>'));
}else{ } else {
$toolbar.hide(); $toolbar.hide();
} }
}, },
_createStatusbar: function ( $statusbar, km ) { _createStatusbar: function($statusbar, km) {
}, },
getKityMinder: function ( id, options ) { getKityMinder: function(id, options) {
var containers = this._createUI( id );
var km = this.getMinder( containers.$body.get( 0 ), options ); var containers = this._createUI(id);
this._createToolbar( containers.$toolbar, km ); var km = this.getMinder(containers.$body.get(0), options);
this._createStatusbar( containers.$statusbar, km ); this._createToolbar(containers.$toolbar, km);
this._createStatusbar(containers.$statusbar, km);
km.$container = containers.$container; km.$container = containers.$container;
this.loadUI( km ); this.loadUI(km);
return km.fire( 'interactchange' ); return km.fire('interactchange');
}, },
registerWidget: function ( name, pro, cb ) { registerWidget: function(name, pro, cb) {
_widgetData[ name ] = $.extend2( pro, { _widgetData[name] = $.extend2(pro, {
$root: '', $root: '',
_preventDefault: false, _preventDefault: false,
root: function ( $el ) { root: function($el) {
return this.$root || ( this.$root = $el ); return this.$root || (this.$root = $el);
}, },
preventDefault: function () { preventDefault: function() {
this._preventDefault = true; this._preventDefault = true;
}, },
clear: false clear: false
} ); });
if ( cb ) { if (cb) {
_widgetCallBack[ name ] = cb; _widgetCallBack[name] = cb;
} }
}, },
getWidgetData: function ( name ) { getWidgetData: function(name) {
return _widgetData[ name ]; return _widgetData[name];
}, },
setWidgetBody: function ( name, $widget, km ) { setWidgetBody: function(name, $widget, km) {
if ( !km._widgetData ) { if (!km._widgetData) {
utils.extend( km, { utils.extend(km, {
_widgetData: {}, _widgetData: {},
getWidgetData: function ( name ) { getWidgetData: function(name) {
return this._widgetData[ name ]; return this._widgetData[name];
}, },
getWidgetCallback: function ( widgetName ) { getWidgetCallback: function(widgetName) {
var me = this; var me = this;
return function () { return function() {
return _widgetCallBack[ widgetName ].apply( me, [ me, $widget ].concat( utils.argsToArray( arguments, 0 ) ) ); return _widgetCallBack[widgetName].apply(me, [me, $widget].concat(utils.argsToArray(arguments, 0)));
}; };
} }
} ); });
} }
var pro = _widgetData[ name ]; var pro = _widgetData[name];
if ( !pro ) { if (!pro) {
return null; return null;
} }
pro = km._widgetData[ name ]; pro = km._widgetData[name];
if ( !pro ) { if (!pro) {
pro = _widgetData[ name ]; pro = _widgetData[name];
pro = km._widgetData[ name ] = $.type( pro ) == 'function' ? pro : utils.clone( pro ); pro = km._widgetData[name] = $.type(pro) == 'function' ? pro : utils.clone(pro);
} }
pro.root( $widget.kmui().getBodyContainer() ); pro.root($widget.kmui().getBodyContainer());
//清除光标 //清除光标
km.fire('selectionclear'); km.fire('selectionclear');
pro.initContent( km, $widget ); pro.initContent(km, $widget);
//在dialog上阻止键盘冒泡,导致跟编辑输入冲突的问题 //在dialog上阻止键盘冒泡,导致跟编辑输入冲突的问题
$widget.on('keydown keyup keypress',function(e){ $widget.on('keydown keyup keypress', function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
if ( !pro._preventDefault ) { if (!pro._preventDefault) {
pro.initEvent( km, $widget ); pro.initEvent(km, $widget);
} }
if (pro.width) $widget.width( pro.width ); if (pro.width) $widget.width(pro.width);
}, },
setActiveWidget: function ( $widget ) { setActiveWidget: function($widget) {
_activeWidget = $widget; _activeWidget = $widget;
} }
}; };
}() ); }());
\ No newline at end of file \ No newline at end of file
...@@ -44,13 +44,26 @@ KityMinder.registerLayout('bottom', kity.createClass({ ...@@ -44,13 +44,26 @@ KityMinder.registerLayout('bottom', kity.createClass({
if (!childContentBox.width) continue; if (!childContentBox.width) continue;
//水平方向上的布局 //水平方向上的布局
x += childTreeBox.width / 2; x += childTreeBox.width / 2;
if (i > 1) { if (i > 0) {
x += children[i].getStyle('margin-left'); x += children[i].getStyle('margin-left');
} }
y = nodeContentBox.height + node.getStyle('margin-bottom') + children[i].getStyle('margin-top'); y = nodeContentBox.height + node.getStyle('margin-bottom') + children[i].getStyle('margin-top');
children[i].setLayoutTransform(new kity.Matrix().translate(x, y)); children[i].setLayoutTransform(new kity.Matrix().translate(x, y));
x += childTreeBox.width / 2 + children[i].getStyle('margin-right'); x += childTreeBox.width / 2 + children[i].getStyle('margin-right');
child.setLayoutVector(new kity.Vector(childContentBox.cx, childContentBox.bottom));
} }
} }
} }
})); }));
KityMinder.registerConnectProvider('bottom', function(node, parent) {
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var abs = Math.abs;
var pathData = [];
pathData.push('M', new kity.Point(pBox.cx, pBox.bottom));
pathData.push('L', new kity.Point(pBox.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, pBox.bottom + parent.getStyle('margin-bottom')));
pathData.push('L', new kity.Point(box.cx, box.top));
return pathData;
});
\ No newline at end of file
/* global Layout:true */
window.layoutSwitch = true;
KityMinder.registerLayout('filetree', kity.createClass({
base: Layout,
doLayout: function(node) {
var layout = this;
if (node.isLayoutRoot()) {
this.doLayoutRoot(node);
} else {
this.arrange(node);
}
},
doLayoutRoot: function(root) {
this.arrange(root);
},
arrange: function(node) {
var children = node.getChildren();
var _this = this;
if (!children.length) {
return false;
} else {
var totalTreeWidth = 0;
// 计算每个 child 的树所占的矩形区域
var childTreeBoxes = children.map(function(node, index, children) {
var box = _this.getTreeBox([node]);
return box;
});
var nodeContentBox = node.getContentBox();
var i, x, y, child, childTreeBox, childContentBox;
var transform = new kity.Matrix();
y = nodeContentBox.bottom + node.getStyle('margin-bottom');
for (var i = 0; i < children.length; i++) {
child = children[i];
childTreeBox = childTreeBoxes[i];
childContentBox = child.getContentBox();
if (!childContentBox.width) continue;
x = 10;
y += child.getStyle('margin-top');
child.setLayoutTransform(new kity.Matrix().translate(x, y));
y += childTreeBox.height + children[i].getStyle('margin-bottom');
child.setLayoutVector(new kity.Vector(childContentBox.left + 5, childContentBox.cy));
}
}
}
}));
KityMinder.registerConnectProvider('filetree', function(node, parent) {
var box = node.getLayoutBox(),
pBox = parent.getLayoutBox();
var abs = Math.abs;
var pathData = [];
var side = box.cx > pBox.cx ? 'right' : 'left';
var left = pBox.left + 5;
pathData.push('M', new kity.Point(left, pBox.bottom));
pathData.push('L', new kity.Point(left, box.cy));
pathData.push('L', new kity.Point(box.left, box.cy));
return pathData;
});
\ No newline at end of file
KityMinder.registerTheme('filetree', {
'root-color': '#430',
'root-background': '#e9df98',
'root-stroke': 'none',
'root-font-size': 24,
'root-padding': [15, 25],
'root-margin': 100,
'root-radius': 30,
'root-space': 10,
'main-color': '#333',
'main-background': '#a4c5c0',
'main-stroke': 'none',
'main-font-size': 16,
'main-padding': [6, 20],
'main-margin': [30, 0, 10, 0],
'main-radius': 10,
'main-space': 5,
'sub-color': 'black',
'sub-background': 'white',
'sub-stroke': 'none',
'sub-font-size': 12,
'sub-padding': [5, 10],
'sub-margin': [5, 15, 10, 5],
'sub-radius': 5,
'sub-space': 5,
'connect-color': 'white',
'connect-width': 2,
'connect-radius': 5,
'selected-background': 'rgb(254, 219, 0)'
});
\ 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