Commit 00505709 authored by techird's avatar techird

Merge branch 'dev' into gh-pages

parents 8cf3fa4e dc35c4bb
......@@ -8,6 +8,7 @@
"white": false,
"quotmark": false,
"predef" : [
"module",
"require",
"console",
"kity",
......
Kity Minder
==========
基于 Kity 库开发的在线脑图编辑器。
\ No newline at end of file
##简介
KityMinder是百度F³团队(原UEditor团队)的又一力作。作为一款在线的脑图编辑工具,它有着不输给Native编辑工具(如xMind,MindManager等)的最佳用户体验。同时,它充分发挥了Web云存储的优势,可以直接将编辑中的脑图同步到云端。 此外,借由独创的“云盘分享”功能,用户可以一键将当前编辑的脑图直接生成在线链接共享给其他用户,实现无缝沟通。
KM是基于SVG技术实现,使用JavaScript+html实现。支持绝大多数的主流浏览器。
支持列表如下
1. chrome
2. firefox
3. safari
4. ie9-11
##项目链接
[直接使用链接](http://kitygraph.github.io/kityminder/dist/)
##联系我们
邮件:kity@baidu.com
讨论群:374918234
......
<!DOCTYPE html>
<html>
<head>
<script src="../dist/jquery-2.1.0.min.js"></script>
<script src="../kity/dist/kitygraph.all.js"></script>
<script src="../configure.js"></script>
<script src="../dist/dev.js"></script>
<script src="../lang/zh-cn/zh-cn.js" charset="utf-8"></script>
<link href="../themes/default/css/import.css" type="text/css" rel="stylesheet">
<style>
.km_receiver{
width:0;
height:0;
}
.km-minderNode{
cursor:default;
}
.kmui-container {
height: 100%;
}
html, body, div {
margin: 0;
padding: 0;
}
</style>
</head>
<body >
<div id="kityminder" style="height:100%;width:100%" onselectstart="return false">
</div>
</body>
<script>
window.km = KM.getKityMinder('kityminder');
</script>
</html>
\ No newline at end of file
<?php
$dependency = Array(
'src/core/kityminder.js'
'src/core/kityminder.js'
,'src/core/utils.js'
,'src/core/command.js'
,'src/core/node.js'
......@@ -71,6 +71,7 @@ $dependency = Array(
,'src/protocal/svg.js'
);
$content = "";
......
Subproject commit ebccc80ba41995fa718b1fb0b8f7d79938501ed1
Subproject commit 26f9836718affd92c95196be698b14b1c6da4a95
......@@ -42,8 +42,8 @@ KityMinder.LANG[ 'zh-cn' ] = {
}
},
'node': {
'appendsiblingnode': '插入兄弟节点',
'appendchildnode': '插入子节点',
'appendsiblingnode': '插入同级节点',
'appendchildnode': '插入子节点',
'removenode': '删除节点'
}
......
......@@ -131,7 +131,7 @@ KM.registerToolbarUI( 'forecolor', function ( name ) {
title: this.getLang( 'tooltips' )[ name ] || '',
click: function () {
var color = kity.Color.parse(getCurrentColor()).toHEX();
if(!color == '#000000'){
if( color != '#000000'){
me.execCommand( name, color );
}
}
......
......@@ -62,18 +62,8 @@ KM.registerUI( 'contextmenu', function () {
$menu.kmui().hide();
});
me.on('beforemousedown',function(e){
var isRightMB;
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
if(e.isRightMB()){
e.stopPropagationImmediately();
}
})
} );
......
......@@ -37,10 +37,11 @@ KM.registerToolbarUI( 'saveto', function ( name ) {
var renderBox = me.getRenderContainer().getRenderBox( "top" );
var renderContainer = me.getRenderContainer();
var transform = renderContainer.getTransform();
renderContainer.resetTransform();
renderContainer.setTransform( new kity.Matrix().translate( -renderBox.x, -renderBox.y ) );
var loop = 0;
var svg = $( svghtml ).attr( {
width: renderBox.x + renderBox.width,
height: renderBox.y + renderBox.height,
width: renderBox.width,
height: renderBox.height,
viewBox: null
} );
var div = $( "<div></div>" ).append( svg );
......
var Command = kity.createClass( "Command", {
constructor: function () {
this._isContentChange = true;
this._isSelectionChange = false;
},
constructor: function () {
this._isContentChange = true;
this._isSelectionChange = false;
},
execute: function ( minder, args ) {
execute: function ( minder, args ) {
},
},
setContentChanged: function ( val ) {
this._isContentChange = !! val;
},
setContentChanged: function ( val ) {
this._isContentChange = !! val;
},
isContentChanged: function () {
return this._isContentChange;
},
isContentChanged: function () {
return this._isContentChange;
},
setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val;
},
setSelectionChanged: function ( val ) {
this._isSelectionChange = !! val;
},
isSelectionChanged: function () {
return this._isContentChange;
},
isSelectionChanged: function () {
return this._isContentChange;
},
queryState: function ( km ) {
return 0;
},
queryState: function ( km ) {
return 0;
},
queryValue: function ( km ) {
return 0;
},
isNeedUndo: function () {
return true;
}
queryValue: function ( km ) {
return 0;
},
isNeedUndo: function () {
return true;
}
} );
\ No newline at end of file
......@@ -41,5 +41,16 @@ var MinderEvent = kity.createClass( 'MindEvent', {
},
preventDefault:function(){
this.originEvent.preventDefault();
},
isRightMB:function(){
var isRightMB = false;
if(!this.originEvent){
return false;
}
if ("which" in this.originEvent)
isRightMB = this.originEvent.which == 3;
else if ("button" in this.originEvent)
isRightMB = this.originEvent.button == 2;
return isRightMB;
}
} );
\ No newline at end of file
var KityMinder =
window.KM =
window.KityMinder = function () {
var instanceMap = {}, instanceId = 0;
return {
version: '1.0.0',
createMinder: function ( renderTarget, options ) {
options = options || {};
options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
var minder = new Minder( options );
this.addMinder( options.renderTo, minder );
return minder;
},
addMinder: function ( target, minder ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
instanceMap[ id ] = minder;
},
getMinder: function ( target, options ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
return instanceMap[ id ] || this.createMinder( target, options );
},
//挂接多语言
LANG: {}
}
var KityMinder = window.KM = window.KityMinder = function () {
var instanceMap = {}, instanceId = 0;
return {
version: '1.0.0',
createMinder: function ( renderTarget, options ) {
options = options || {};
options.renderTo = Utils.isString( renderTarget ) ? document.getElementById( renderTarget ) : renderTarget;
var minder = new Minder( options );
this.addMinder( options.renderTo, minder );
return minder;
},
addMinder: function ( target, minder ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
instanceMap[ id ] = minder;
},
getMinder: function ( target, options ) {
var id;
if ( typeof ( target ) === 'string' ) {
id = target;
} else {
id = target.id || ( "KM_INSTANCE_" + instanceId++ );
}
return instanceMap[ id ] || this.createMinder( target, options );
},
//挂接多语言
LANG: {}
};
}();
\ No newline at end of file
......@@ -27,6 +27,7 @@ kity.extendClass( Minder, {
_firePharse: function ( e ) {
var beforeEvent, preEvent, executeEvent;
beforeEvent = new MinderEvent( 'before' + e.type, e, true );
if ( this._fire( beforeEvent ) ) {
return;
......@@ -44,6 +45,7 @@ kity.extendClass( Minder, {
},
_interactChange: function ( e ) {
var minder = this;
clearTimeout( this._interactTimeout );
this._interactTimeout = setTimeout( function () {
var stoped = minder._fire( new MinderEvent( 'beforeinteractchange' ) );
......@@ -59,10 +61,23 @@ kity.extendClass( Minder, {
callbacks.push( callback );
},
_fire: function ( e ) {
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ];
if ( !callbacks ) {
return false;
var status = this.getStatus();
var callbacks = this._eventCallbacks[ e.type.toLowerCase() ] || [];
if(status){
callbacks = callbacks.concat(this._eventCallbacks[ status + '.' + e.type.toLowerCase() ] || []);
}
if(callbacks.length == 0){
return;
}
for ( var i = 0; i < callbacks.length; i++ ) {
callbacks[ i ].call( this, e );
if ( e.shouldStopPropagationImmediately() ) {
......@@ -72,17 +87,19 @@ kity.extendClass( Minder, {
return e.shouldStopPropagation();
},
on: function ( name, callback ) {
var types = name.split( ' ' );
for ( var i = 0; i < types.length; i++ ) {
this._listen( types[ i ].toLowerCase(), callback );
}
var km = this;
utils.each(name.split(/\s+/),function(i,n){
km._listen( n.toLowerCase(), callback );
});
return this;
},
off: function ( name, callback ) {
var types = name.split( ' ' );
var types = name.split( /\s+/);
var i, j, callbacks, removeIndex;
for ( i = 0; i < types.length; i++ ) {
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
callbacks = this._eventCallbacks[ types[ i ].toLowerCase() ];
if ( callbacks ) {
removeIndex = null;
for ( j = 0; j < callbacks.length; j++ ) {
......
......@@ -5,6 +5,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
this._initEvents();
this._initMinder();
this._initSelection();
this._initStatus();
this._initShortcutKey();
this._initContextmenu();
this._initModules();
......@@ -109,6 +110,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
return false
}
me.on( 'keydown', function ( e ) {
var originEvent = e.originEvent;
var keyCode = originEvent.keyCode || originEvent.which;
for ( var i in shortcutkeys ) {
......@@ -119,10 +121,7 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
current++;
}
});
//todo 暂时通过receiver判断
if(me.isTextEditStatus()){
return;
}
if(current == keys.length){
if ( me.queryCommandState( i ) != -1 )
me.execCommand( i );
......@@ -147,6 +146,25 @@ var Minder = KityMinder.Minder = kity.createClass( "KityMinder", {
},
getContextmenu:function(){
return this.contextmenus;
},
_initStatus:function(){
this._status = "normal";
this._rollbackStatus = "normal";
},
setStatus:function(status){
if(status){
this._rollbackStatus = this._status;
this._status = status;
}else{
this._status = '';
}
return this;
},
rollbackStatus:function(){
this._status = this._rollbackStatus;
},
getStatus:function(){
return this._status;
}
} );
......
......@@ -26,6 +26,9 @@ KityMinder.registerModule( "basestylemodule", function () {
queryState: function ( ) {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('bold')){
result = 1;
......@@ -58,6 +61,9 @@ KityMinder.registerModule( "basestylemodule", function () {
queryState: function ( ) {
var nodes = km.getSelectedNodes(),
result = 0;
if(nodes.length == 0){
return -1;
}
utils.each(nodes,function(i,n){
if(n.getData('italic')){
result = 1;
......
......@@ -261,10 +261,10 @@ KityMinder.registerModule( "DragTree", function () {
this._dragBox.dragStart( e.getPosition() );
}
},
mousemove: function ( e ) {
'mousemove': function ( e ) {
this._dragBox.dragMove( e.getPosition() );
},
mouseup: function ( e ) {
'mouseup': function ( e ) {
this._dragBox.dragEnd();
}
},
......
......@@ -26,16 +26,9 @@ KityMinder.registerModule( "TextEditModule", function () {
this.getPaper().addShape(sel);
},
"events": {
'beforemousedown':function(e){
var isRightMB;
'normal.beforemousedown textedit.beforemousedown':function(e){
if ("which" in e.originEvent) // Gecko (Firefox), WebKit (Safari/Chrome) & Opera
isRightMB = e.originEvent.which == 3;
else if ("button" in e.originEvent) // IE, Opera
isRightMB = e.originEvent.button == 2;
if(isRightMB){
if(e.isRightMB()){
e.stopPropagationImmediately();
return;
}
......@@ -48,6 +41,7 @@ KityMinder.registerModule( "TextEditModule", function () {
node = selectionShape.getData('relatedNode');
e.stopPropagationImmediately();
}
km.setStatus('normal')
}
if(node){
var textShape = node.getTextShape();
......@@ -56,6 +50,7 @@ KityMinder.registerModule( "TextEditModule", function () {
if ( this.isSingleSelect() && node.isSelected()) {// && e.kityEvent.targetShape.getType().toLowerCase()== 'text'
sel.collapse();
node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
......@@ -74,10 +69,11 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setShow();
selectionByClick = false;
}
km.setStatus('textedit')
}
}
},
'mouseup':function(e){
'normal.mouseup textedit.mouseup':function(e){
if(mouseDownStatus){
if(!sel.collapsed ){
try{
......@@ -93,7 +89,7 @@ KityMinder.registerModule( "TextEditModule", function () {
mouseDownStatus = false;
oneTime = 0;
},
'beforemousemove':function(e){
'textedit.beforemousemove':function(e){
if(mouseDownStatus){
e.stopPropagationImmediately();
......@@ -112,7 +108,7 @@ KityMinder.registerModule( "TextEditModule", function () {
}
},
'dblclick':function(e){
'normal.dblclick textedit.dblclick':function(e){
var text = e.kityEvent.targetShape;
if ( text.getType().toLowerCase()== 'text') {
......@@ -121,8 +117,8 @@ KityMinder.registerModule( "TextEditModule", function () {
sel.setEndOffset(text.getContent().length);
sel.setShow();
receiver.setContainerTxt(text.getContent()).updateSelectionShow(1)
.updateRange(range).setTextEditStatus(true)
.updateRange(range).setTextEditStatus(true);
km.setStatus('textedit');
}
},
'restoreScene':function(){
......@@ -131,6 +127,7 @@ KityMinder.registerModule( "TextEditModule", function () {
'stopTextEdit':function(){
sel.setHide();
receiver.clear().setTextEditStatus(false);
km.setStatus('normal');
},
"resize": function ( e ) {
sel.setHide();
......@@ -148,6 +145,7 @@ KityMinder.registerModule( "TextEditModule", function () {
textShape.setStyle('cursor','default');
node.getTextShape().setStyle('cursor','text');
km.setStatus('textedit');
receiver.setTextEditStatus(true)
.setSelection(sel)
.setKityMinder(this)
......@@ -185,8 +183,12 @@ KityMinder.registerModule( "TextEditModule", function () {
}
receiver.clear().setTextEditStatus(false);
if(this.getStatus() == 'textedit'){
this.setStatus('normal')
}
},
'selectionclear':function(){
km.setStatus('normal');
receiver.setTextEditStatus(false).clear()
}
}
......
......@@ -3,6 +3,7 @@ Minder.Receiver = kity.createClass('Receiver',{
clear : function(){
this.container.innerHTML = '';
this.selection && this.selection.setHide();
this.range && this.range.nativeSel.removeAllRanges();
this.index = 0;
return this;
},
......@@ -21,7 +22,7 @@ Minder.Receiver = kity.createClass('Receiver',{
_div.className = 'km_receiver';
this.container = document.body.insertBefore(_div,document.body.firstChild);
utils.addCssRule('km_receiver_css',' .km_receiver{position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);}');//
this.km.on('beforekeyup', utils.proxy(this.keyboardEvents,this));
this.km.on('textedit.beforekeyup textedit.keydown', utils.proxy(this.keyboardEvents,this));
this.timer = null;
this.index = 0;
},
......@@ -72,51 +73,65 @@ Minder.Receiver = kity.createClass('Receiver',{
var me = this;
var orgEvt = e.originEvent;
var keyCode = orgEvt.keyCode;
switch(e.type){
var keys = KityMinder.keymap;
switch(e.type){
case 'keydown':
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.selection.setHide();
this.clear().setTextEditStatus(false);
this.km.setStatus('normal');
e.preventDefault();
break;
}
break;
case 'beforekeyup':
if(this.isTextEditStatus()){
switch(keyCode){
case keymap.Enter:
case keymap.Tab:
if(this.keydownNode === this.minderNode){
this.setTextEditStatus(false);
this.clear();
}
e.preventDefault();
return;
case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
return;
switch(keyCode){
case keymap.Enter:
case keymap.Tab:
if(this.keydownNode === this.minderNode){
this.rollbackStatus();
this.setTextEditStatus(false);
this.clear();
}
e.preventDefault();
return;
case keymap.Shift:
case keymap.Control:
case keymap.Alt:
case keymap.Cmd:
return;
}
var text = this.container.textContent.replace(/\u200b/g,'');
}
var text = this.container.textContent.replace(/\u200b/g,'');
if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
if(this.textShape.getOpacity() == 0){
this.textShape.setOpacity(1);
}
this.textShape.setContent(text);
this.setContainerStyle();
this.minderNode.setText(text);
if(text.length == 0){
this.textShape.setContent('a');
this.textShape.setOpacity(0);
}
this.km.updateLayout(this.minderNode);
this.setBaseOffset();
this.updateTextData();
this.updateIndex();
this.updateSelection();
this.timer = setTimeout(function(){
me.selection.setShow()
this.timer = setTimeout(function(){
me.selection.setShow()
},500);
return true;
}
return true;
}
},
updateIndex:function(){
this.index = this.range.getStart().startOffset;
......
......@@ -51,6 +51,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.setData( 'fontcolor', color );
n.getTextShape().fill( color )
} )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
}
} ),
......@@ -64,6 +67,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.getTextShape().setAttr( 'font-family', family );
km.updateLayout( n )
} )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
}
} ),
"fontsize": kity.createClass( "fontsizeCommand", {
......@@ -76,6 +82,9 @@ KityMinder.registerModule( "fontmodule", function () {
n.getTextShape().setSize( size );
km.updateLayout( n )
} )
},
queryState:function(km){
return km.getSelectedNodes().length == 0 ? -1 : 0
}
} )
},
......
......@@ -27,24 +27,30 @@ var ViewDragger = kity.createClass( "ViewDragger", {
lastPosition = null,
currentPosition = null;
this._minder.on( 'beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
lastPosition = e.getPosition();
e.stopPropagation();
e.originEvent.preventDefault();
}
this._minder.on( 'normal.beforemousedown', function ( e ) {
// 点击未选中的根节点临时开启
else if ( e.getTargetNode() == this.getRoot() &&
if ( e.getTargetNode() == this.getRoot() &&
( !this.getRoot().isSelected() || !this.isSingleSelect() ) ) {
lastPosition = e.getPosition();
dragger.setEnabled( true );
isRootDrag = true;
var me = this;
setTimeout(function() {
me.setStatus('hand');
}, 1);
}
} );
this._minder.on( 'hand.beforemousedown', function ( e ) {
// 已经被用户打开拖放模式
if ( dragger.isEnabled() ) {
lastPosition = e.getPosition();
e.stopPropagation();
e.originEvent.preventDefault();
}
} )
.on( 'beforemousemove', function ( e ) {
.on( 'hand.beforemousemove', function ( e ) {
if ( lastPosition ) {
currentPosition = e.getPosition();
......@@ -56,23 +62,34 @@ var ViewDragger = kity.createClass( "ViewDragger", {
}
} )
.on( 'mouseup', function ( e ) {
.on( 'hand.mouseup', function ( e ) {
lastPosition = null;
// 临时拖动需要还原状态
if ( isRootDrag ) {
dragger.setEnabled( false );
isRootDrag = false;
this.rollbackStatus();
}
} );
}
} );
KityMinder.registerModule( 'Hand', function () {
var km = this;
var ToggleHandCommand = kity.createClass( "ToggleHandCommand", {
base: Command,
execute: function ( minder ) {
minder._viewDragger.setEnabled( !minder._viewDragger.isEnabled() );
if ( minder._viewDragger.isEnabled() ) {
minder.setStatus( 'hand' );
} else {
minder.rollbackStatus();
}
},
queryState: function ( minder ) {
return minder._viewDragger.isEnabled() ? 1 : 0;
......@@ -103,9 +120,9 @@ KityMinder.registerModule( 'Hand', function () {
e.originEvent.preventDefault();
},
dblclick: function() {
dblclick: function () {
var viewport = this.getPaper().getViewPort();
var offset = this.getRoot().getRenderContainer(this.getRenderContainer()).getTransform().getTranslate();
var offset = this.getRoot().getRenderContainer( this.getRenderContainer() ).getTransform().getTranslate();
var dx = viewport.center.x - offset.x,
dy = viewport.center.y - offset.y;
//this.getRenderContainer().fxTranslate(dx, dy, 300);
......
......@@ -66,26 +66,10 @@ KityMinder.registerModule( "KeyboardModule", function () {
contentchange: function () {
buildPositionNetwork( this.getRoot() );
},
keydown: function ( e ) {
"normal.keydown": function ( e ) {
var keys = KityMinder.keymap;
if ( this.receiver.isTextEditStatus() ) {
switch ( e.originEvent.keyCode ) {
case keys.Enter:
case keys.Tab:
this.fire( 'stopTextEdit' );
e.preventDefault();
break;
case keys.Backspace:
case keys.Del:
case keys.Left:
case keys.Up:
case keys.Right:
case keys.Down:
break;
}
return;
}
var node = e.getTargetNode();
this.receiver.keydownNode = node;
switch ( e.originEvent.keyCode ) {
......
......@@ -348,6 +348,12 @@ KityMinder.registerModule( "LayoutBottom", function () {
default:
break;
}
this._fire( new MinderEvent( "beforeRenderNode", {
node: node
}, false ) );
this._fire( new MinderEvent( "RenderNode", {
node: node
}, false ) );
},
updateLayout: function ( node ) {
this._fire( new MinderEvent( "beforeRenderNode", {
......@@ -408,9 +414,11 @@ KityMinder.registerModule( "LayoutBottom", function () {
appendChildNode: function ( parent, node, sibling ) {
node.clearLayout();
var parentLayout = parent.getLayout();
var expand = parent.getData( "expand" );
//设置分支类型
if ( parent.getType() === "root" ) {
node.setType( "main" );
node.setData( "expand", true );
minder.handelNodeInsert( node );
} else {
node.setType( "sub" );
......@@ -490,8 +498,15 @@ KityMinder.registerModule( "LayoutBottom", function () {
}
},
expandNode: function ( ico ) {
var isExpand = ico.icon.switchState();
var node = ico.icon._node;
var isExpand, node;
if ( ico instanceof MinderNode ) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
node.setData( "expand", isExpand );
var _buffer = node.getChildren();
var _cleanbuffer = [];
......
......@@ -412,6 +412,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
default:
break;
}
this._fire( new MinderEvent( "beforeRenderNode", {
node: node
}, false ) );
this._fire( new MinderEvent( "RenderNode", {
node: node
}, false ) );
},
updateLayout: function ( node ) {
this._fire( new MinderEvent( "beforeRenderNode", {
......@@ -537,6 +543,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
node.setType( "main" );
} else {
node.setType( "sub" );
var isExpand = parent.getData( "expand" );
if ( isExpand === undefined ) {
isExpand = true;
parent.setData( "expand", isExpand );
}
// if ( !isExpand ) {
// return false;
// }
}
//计算位置等流程
updateBg( node );
......@@ -600,8 +614,15 @@ KityMinder.registerModule( "LayoutDefault", function () {
}
},
expandNode: function ( ico ) {
var isExpand = ico.icon.switchState();
var node = ico.icon._node;
var isExpand, node;
if ( ico instanceof MinderNode ) {
node = ico;
isExpand = node.getLayout().shicon.switchState();
} else {
isExpand = ico.icon.switchState();
node = ico.icon._node;
}
node.setData( "expand", isExpand );
var _buffer = node.getChildren();
var _cleanbuffer = [];
......
......@@ -106,6 +106,9 @@ KityMinder.registerModule( "LayoutModule", function () {
base: Command,
execute: function ( km, node ) {
var parent = km.getSelectedNode();
if ( parent.getType() !== "root" && parent.getChildren().length !== 0 && parent.getData( "expand" ) === false ) {
km.expandNode( parent );
}
km.appendChildNode( parent, node );
km.select( node, true );
return node;
......@@ -129,7 +132,6 @@ KityMinder.registerModule( "LayoutModule", function () {
node.setType( "main" );
km.appendChildNode( selectedNode, node );
} else {
node.setType( "sub" );
km.appendSiblingNode( selectedNode, node );
}
km.select( node, true );
......@@ -203,29 +205,26 @@ KityMinder.registerModule( "LayoutModule", function () {
this.initStyle( this.getRoot() );
}
},
'contextmenu':[
{
label:this.getLang('node.appendsiblingnode'),
exec:function(){
this.execCommand('appendsiblingnode',new MinderNode(this.getLang('topic')))
},
cmdName:'appendsiblingnode'
},
{
label:this.getLang('node.appendchildnode'),
exec:function(){
this.execCommand('appendchildnode',new MinderNode(this.getLang('topic')))
},
cmdName:'appendchildnode'
},
{
label:this.getLang('node.removenode'),
cmdName:'removenode'
},{
divider:1
}
'contextmenu': [ {
label: this.getLang( 'node.appendsiblingnode' ),
exec: function () {
this.execCommand( 'appendsiblingnode', new MinderNode( this.getLang( 'topic' ) ) )
},
cmdName: 'appendsiblingnode'
}, {
label: this.getLang( 'node.appendchildnode' ),
exec: function () {
this.execCommand( 'appendchildnode', new MinderNode( this.getLang( 'topic' ) ) )
},
cmdName: 'appendchildnode'
}, {
label: this.getLang( 'node.removenode' ),
cmdName: 'removenode'
}, {
divider: 1
}
],
],
"defaultOptions": {
"defaultlayoutstyle": "default",
"node": {
......
......@@ -93,7 +93,7 @@ KityMinder.registerModule( "Select", function () {
var lastDownNode = null;
return {
"events": {
mousedown: function ( e ) {
"normal.mousedown textedit.mousedown": function ( e ) {
var downNode = e.getTargetNode();
// 没有点中节点:
......@@ -101,6 +101,7 @@ KityMinder.registerModule( "Select", function () {
if ( !downNode ) {
this.removeAllSelectedNodes();
marqueeActivator.selectStart( e );
this.setStatus('normal')
}
// 点中了节点,并且按了 shift 键:
......@@ -122,8 +123,8 @@ KityMinder.registerModule( "Select", function () {
lastDownNode = downNode;
}
},
mousemove: marqueeActivator.selectMove,
mouseup: function ( e ) {
"normal.mousemove textedit.mousemove": marqueeActivator.selectMove,
"normal.mouseup textedit.mouseup": function ( e ) {
var upNode = e.getTargetNode();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的
......
......@@ -142,7 +142,7 @@
return obj.root()[_prefix + className].apply(obj.root(), arguments)
} else {
$el && obj.root($el);
obj.init && obj.init(!options || $.isPlainObject(options) ? $.extend2(options || {}, obj.defaultOpt || {}, true) : options);
obj.init && obj.init(utils.clonePlainObject(!options || $.isPlainObject(options) ? $.extend2(options || {}, obj.defaultOpt || {}, true) : options));
try{
obj.root().find('a').click(function (evt) {
evt.preventDefault()
......
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