Commit 37503c8d authored by Akikonata's avatar Akikonata

added expand and collapse

parent 1b81fb1f
......@@ -84,7 +84,7 @@
//默认是全部展开,0表示全部展开
,
defaultExpand: {
defaultLayer: 1,
defaultLayer: 2,
defaultSubShow: 5
}
};
......
......@@ -125,9 +125,9 @@ kity.extendClass( Minder, {
json = params.json || ( params.json = protocal.decode( local ) );
this._fire(new MinderEvent('importData',{
data:json
},true));
this._fire( new MinderEvent( 'importData', {
data: json
}, true ) );
if ( typeof json === 'object' && 'then' in json ) {
var self = this;
......@@ -163,7 +163,7 @@ kity.extendClass( Minder, {
this._root.setData();
this._root.setData( "currentstyle", curLayout );
importNode( this._root, json, this );
this.fire( 'beforeimport' );
this._fire( new MinderEvent( 'import', params, false ) );
this._firePharse( {
type: 'contentchange'
......
......@@ -3,7 +3,30 @@ KityMinder.registerModule( "Expand", function () {
STATE_EXPAND = 'expand',
STATE_COLLAPSE = 'collapse';
var layerTravel = function ( root, fn ) {
var _buffer = [ root ];
while ( _buffer.length !== 0 ) {
fn( _buffer[ 0 ] );
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
_buffer.shift();
}
}
// var setOptionValue = function ( root, layer, sub ) {
// var cur_layer = 1;
// var _buffer = root.getChildren();
// while ( cur_layer < layer ) {
// var layer_len = _buffer.length;
// for ( var i = 0; i < layer_len; i++ ) {
// var c = _buffer[ i ].getChildren();
// if ( c.length < sub || ( !sub ) ) {
// _buffer[ i ].expand();
// _buffer = _buffer.concat( c );
// }
// }
// _buffer.splice( 0, layer_len );
// cur_layer++;
// }
// }
/**
* 该函数返回一个策略,表示递归到节点指定的层数
*
......@@ -13,38 +36,38 @@ KityMinder.registerModule( "Expand", function () {
* @param {int} deep_level 指定的层数
* @param {Function} policy_after_level 超过的层数执行的策略
*/
function generateDeepPolicy( deep_level, policy_after_level ) {
function generateDeepPolicy( deep_level, policy_after_level ) {
return function ( node, state, policy, level ) {
var children, child, i;
return function ( node, state, policy, level ) {
var children, child, i;
node.setData( EXPAND_STATE_DATA, state );
level = level || 1;
node.setData( EXPAND_STATE_DATA, state );
level = level || 1;
children = node.getChildren();
children = node.getChildren();
for ( i = 0; i < children.length; i++ ) {
child = children[ i ];
for ( i = 0; i < children.length; i++ ) {
child = children[ i ];
if ( level <= deep_level ) {
policy( child, state, policy, level + 1 );
} else if ( policy_after_level ) {
policy_after_level( child, state, policy, level + 1 );
if ( level <= deep_level ) {
policy( child, state, policy, level + 1 );
} else if ( policy_after_level ) {
policy_after_level( child, state, policy, level + 1 );
}
}
}
};
}
};
}
/**
* 节点展开和收缩的策略常量
*
* 策略是一个处理函数,处理函数接受 3 个参数:
*
* @param {MinderNode} node 要处理的节点
* @param {Enum} state 取值为 "expand" | "collapse",表示要对节点进行的操作是展开还是收缩
* @param {Function} policy 提供当前策略的函数,方便递归调用
*/
/**
* 节点展开和收缩的策略常量
*
* 策略是一个处理函数,处理函数接受 3 个参数:
*
* @param {MinderNode} node 要处理的节点
* @param {Enum} state 取值为 "expand" | "collapse",表示要对节点进行的操作是展开还是收缩
* @param {Function} policy 提供当前策略的函数,方便递归调用
*/
var EXPAND_POLICY = MinderNode.EXPAND_POLICY = {
/**
......@@ -101,7 +124,10 @@ KityMinder.registerModule( "Expand", function () {
return {
base: Command,
execute: function ( km ) {
alert( '2' );
layerTravel( km.getRoot(), function ( n ) {
n.expand();
} );
km.initStyle();
},
queryState: function ( km ) {
return 0;
......@@ -112,7 +138,10 @@ KityMinder.registerModule( "Expand", function () {
return {
base: Command,
execute: function ( km ) {
alert( '1' );
layerTravel( km.getRoot(), function ( n ) {
n.collapse();
} );
km.initStyle();
},
queryState: function ( km ) {
return 0;
......@@ -121,8 +150,11 @@ KityMinder.registerModule( "Expand", function () {
} )() );
return {
'events': {
'import': function ( e ) {
//console.log( this.getRoot() );
'beforeimport': function ( e ) {
var _root = this.getRoot();
var options = this.getOptions();
var defaultExpand = options.defaultExpand;
//setOptionValue( _root, defaultExpand.defaultLayer, defaultExpand.defaultSubShow );
}
},
'commands': {
......
......@@ -510,6 +510,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
initStyle: function () {
//渲染根节点
var _root = minder.getRoot();
console.log( _root );
var historyPoint = _root.getPoint();
if ( historyPoint ) historyPoint = JSON.parse( JSON.stringify( historyPoint ) );
minder.handelNodeInsert( _root );
......@@ -545,7 +546,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
var mains = _root.getChildren();
for ( var i = 0; i < mains.length; i++ ) {
this.appendChildNode( _root, mains[ i ] );
if ( mains[ i ].isExpanded() && mains[ i ].getChildren().length > 0 ) {
if ( mains[ i ].isExpanded() && ( mains[ i ].getChildren().length > 0 ) ) {
minder.expandNode( mains[ i ] );
}
}
......@@ -568,7 +569,6 @@ KityMinder.registerModule( "LayoutDefault", function () {
while ( _buffer.length !== 0 ) {
var c = _buffer[ 0 ].getChildren();
if ( _buffer[ 0 ].isExpanded() && c.length !== 0 ) {
//_buffer[ 0 ].getLayout().shicon.switchState( true );
for ( var x = 0; x < c.length; x++ ) {
minder.appendChildNode( _buffer[ 0 ], c[ x ] );
}
......
......@@ -51,11 +51,6 @@ KityMinder.registerModule( "LayoutModule", function () {
this.getLayoutStyle( curStyle ).initStyle.call( this );
this.fire( 'afterinitstyle' );
},
restoreStyle: function () {
var curStyle = this.getCurrentStyle();
clearPaper();
var _root = this.getRoot();
},
appendChildNode: function ( parent, node, focus, index ) {
var curStyle = this.getCurrentStyle();
this.getLayoutStyle( curStyle ).appendChildNode.call( this, parent, node, focus, index );
......
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