Commit af3b15e6 authored by Akikonata's avatar Akikonata

added collapse

parent 70549100
...@@ -12,6 +12,26 @@ KityMinder.registerModule( "Expand", function () { ...@@ -12,6 +12,26 @@ KityMinder.registerModule( "Expand", function () {
} }
} }
// var getCommonParents = function ( nodes ) {
// var _buffer = [];
// var resultSet = [];
// for ( var i = 0; i < nodes.length; i++ ) {
// _buffer.push( nodes[ i ] );
// }
// while ( _buffer.length !== 0 ) {
// var parent = _buffer[ 0 ].getParent();
// if ( parent.getType() === 'root' || _buffer.length === 1 ) {
// resultSet.push( _buffer[ 0 ] );
// } else {
// if ( _buffer.indexOf( parent ) === -1 ) {
// _buffer.push( parent );
// }
// }
// _buffer.shift();
// }
// return resultSet;
// }
// var setOptionValue = function ( root, layer, sub ) { // var setOptionValue = function ( root, layer, sub ) {
// var cur_layer = 1; // var cur_layer = 1;
...@@ -126,11 +146,29 @@ KityMinder.registerModule( "Expand", function () { ...@@ -126,11 +146,29 @@ KityMinder.registerModule( "Expand", function () {
return { return {
base: Command, base: Command,
execute: function ( km ) { execute: function ( km ) {
var selectedNodes = km.getSelectedNodes();
if ( selectedNodes.length === 0 ) {
layerTravel( km.getRoot(), function ( n ) { layerTravel( km.getRoot(), function ( n ) {
n.expand(); n.expand();
} ); } );
km.initStyle(); km.initStyle();
} else {
var selectedNode = km.getSelectedNode();
var children = selectedNode.getChildren();
if ( children.length === 0 ) {
return false;
}
layerTravel( selectedNode, function ( n ) {
if ( n !== selectedNode ) n.expand();
} );
if ( !selectedNode.isExpanded() ) {
km.expandNode( selectedNode );
} else {
for ( var i = 0; i < children.length; i++ ) {
if ( children[ i ].getChildren().length !== 0 ) km.expandNode( children[ i ] );
}
}
}
}, },
queryState: function ( km ) { queryState: function ( km ) {
return 0; return 0;
...@@ -141,11 +179,25 @@ KityMinder.registerModule( "Expand", function () { ...@@ -141,11 +179,25 @@ KityMinder.registerModule( "Expand", function () {
return { return {
base: Command, base: Command,
execute: function ( km ) { execute: function ( km ) {
var selectedNodes = km.getSelectedNodes();
if ( selectedNodes.length === 0 ) {
layerTravel( km.getRoot(), function ( n ) { layerTravel( km.getRoot(), function ( n ) {
n.collapse(); n.collapse();
} ); } );
km.initStyle(); km.initStyle();
} else {
var selectedNode = km.getSelectedNode();
var children = selectedNode.getChildren();
if ( children.length === 0 ) {
return false;
}
if ( selectedNode.isExpanded() ) {
layerTravel( selectedNode, function ( n ) {
if ( n !== selectedNode ) n.collapse();
} );
km.expandNode( selectedNode );
}
}
}, },
queryState: function ( km ) { queryState: function ( km ) {
return 0; return 0;
...@@ -156,11 +208,14 @@ KityMinder.registerModule( "Expand", function () { ...@@ -156,11 +208,14 @@ KityMinder.registerModule( "Expand", function () {
return { return {
'events': { 'events': {
'beforeimport': function ( e ) { 'beforeimport': function ( e ) {
var _root = this.getRoot(); // var _root = this.getRoot();
var options = this.getOptions(); // var options = this.getOptions();
var defaultExpand = options.defaultExpand; // var defaultExpand = options.defaultExpand;
//setOptionValue( _root, defaultExpand.defaultLayer, defaultExpand.defaultSubShow ); //setOptionValue( _root, defaultExpand.defaultLayer, defaultExpand.defaultSubShow );
} }
},
'addShortcutKeys': {
}, },
'commands': { 'commands': {
'ExpandNode': ExpandNodeCommand, 'ExpandNode': ExpandNodeCommand,
......
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