Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
88266a3f
Commit
88266a3f
authored
May 07, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of github.com:fex-team/kityminder into dev
parents
d4f0e3d3
fdeb0a30
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
18 deletions
+65
-18
expand.js
src/module/expand.js
+65
-18
No files found.
src/module/expand.js
View file @
88266a3f
...
@@ -3,6 +3,39 @@ KityMinder.registerModule( "Expand", function () {
...
@@ -3,6 +3,39 @@ KityMinder.registerModule( "Expand", function () {
STATE_EXPAND
=
'expand'
,
STATE_EXPAND
=
'expand'
,
STATE_COLLAPSE
=
'collapse'
;
STATE_COLLAPSE
=
'collapse'
;
/**
* 该函数返回一个策略,表示递归到节点指定的层数
*
* 返回的策略表示把操作(展开/收起)进行到指定的层数
* 也可以给出一个策略指定超过层数的节点如何操作,默认不进行任何操作
*
* @param {int} deep_level 指定的层数
* @param {Function} policy_after_level 超过的层数执行的策略
*/
function
generateDeepPolicy
(
deep_level
,
policy_after_level
)
{
return
function
(
node
,
state
,
policy
,
level
)
{
var
children
,
child
,
i
;
node
.
setData
(
EXPAND_STATE_DATA
,
state
);
level
=
level
||
1
;
children
=
node
.
getChildren
();
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
);
}
}
};
}
/**
/**
* 节点展开和收缩的策略常量
* 节点展开和收缩的策略常量
*
*
...
@@ -13,39 +46,53 @@ KityMinder.registerModule( "Expand", function () {
...
@@ -13,39 +46,53 @@ KityMinder.registerModule( "Expand", function () {
* @param {Function} policy 提供当前策略的函数,方便递归调用
* @param {Function} policy 提供当前策略的函数,方便递归调用
*/
*/
MinderNode
.
EXAPND_POLICY
=
{
MinderNode
.
EXAPND_POLICY
=
{
/**
/**
* 策略 1:只修改当前节点的状态,不递归子节点的状态
* 策略 1:只修改当前节点的状态,不递归子节点的状态
*/
*/
KEEP_STATE
:
function
(
node
,
state
,
policy
)
{
KEEP_STATE
:
function
(
node
,
state
,
policy
)
{
node
.
setData
(
expandStateData
,
state
===
STATE_EXPAND
);
node
.
setData
(
EXPAND_STATE_DATA
,
state
);
},
},
generateDeepPolicy
:
generateDeepPolicy
,
/**
/**
* 策略 2:该函数返回一个策略,表示递归到节点指定的层数
* 策略 2:把操作进行到儿子
* 返回的策略表示把操作(展开/收起)进行到指定的层数
*
* @param {int} deep_level 指定的层数
*/
*/
DEEP_TO_LEVEL
:
function
(
deep_level
)
{
DEEP_TO_CHILD
:
generateDeepPolicy
(
1
),
return
function
(
node
,
state
,
policy
)
{
};
},
DEEP_TO_CHILD
:
function
()
{
},
DEEP_TO_LEAVE
:
function
()
{
}
/**
* 策略 3:把操作进行到叶子
*/
DEEP_TO_LEAF
:
generateDeepPolicy
(
Number
.
MAX_VALUE
)
};
};
// 将展开的操作和状态读取接口拓展到 MinderNode 上
kity
.
extendClass
(
MinderNode
,
{
kity
.
extendClass
(
MinderNode
,
{
/**
* 使用指定的策略展开节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
expand
:
function
(
policy
)
{
expand
:
function
(
policy
)
{
node
.
setData
(
EXPAND_STATE_DATA
,
STATE_EXPAND
);
policy
=
policy
||
EXAPND_POLICY
.
KEEP_STATE
;
policy
(
this
,
STATE_EXPAND
,
policy
);
return
this
;
},
},
collapse
:
function
()
{
node
.
setData
(
EXPAND_STATE_DATA
,
STATE_COLLAPSE
);
/**
* 使用指定的策略收起节点
* @param {Policy} policy 展开的策略,默认为 KEEP_STATE
*/
collapse
:
function
(
policy
)
{
policy
=
policy
||
EXAPND_POLICY
.
KEEP_STATE
;
policy
(
this
,
STATE_EXPAND
,
policy
);
return
this
;
},
},
/**
* 判断节点当前的状态是否为展开
*/
isExpanded
:
function
()
{
isExpanded
:
function
()
{
return
this
.
getData
(
EXPAND_STATE_DATA
)
===
STATE_EXPAND
;
return
this
.
getData
(
EXPAND_STATE_DATA
)
===
STATE_EXPAND
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment