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
69b9d074
Commit
69b9d074
authored
Feb 26, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提取计算选择祖先的方法
parent
2a0f726f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
30 deletions
+34
-30
minder.select.js
src/core/minder.select.js
+33
-0
dragtree.js
src/module/dragtree.js
+1
-30
No files found.
src/core/minder.select.js
View file @
69b9d074
...
@@ -67,6 +67,39 @@ kity.extendClass( Minder, function () {
...
@@ -67,6 +67,39 @@ kity.extendClass( Minder, function () {
},
},
isSingleSelect
:
function
()
{
isSingleSelect
:
function
()
{
return
this
.
_selectedNodes
.
length
==
1
;
return
this
.
_selectedNodes
.
length
==
1
;
},
getSelectedAncestors
:
function
()
{
var
nodes
=
this
.
getSelectedNodes
().
slice
(
0
),
ancestors
=
[],
judge
;
// 根节点不参与计算
var
rootIndex
=
nodes
.
indexOf
(
this
.
getRoot
()
);
if
(
~
rootIndex
)
{
nodes
.
splice
(
rootIndex
,
1
);
}
// 判断 nodes 列表中是否存在 judge 的祖先
function
hasAncestor
(
nodes
,
judge
)
{
for
(
var
i
=
nodes
.
length
-
1
;
i
>=
0
;
--
i
)
{
if
(
nodes
[
i
].
isAncestorOf
(
judge
)
)
return
true
;
}
return
false
;
}
// 按照拓扑排序
nodes
.
sort
(
function
(
node1
,
node2
)
{
return
node1
.
getLevel
()
-
node2
.
getLevel
();
}
);
// 因为是拓扑有序的,所以只需往上查找
while
(
(
judge
=
nodes
.
pop
()
)
)
{
if
(
!
hasAncestor
(
nodes
,
judge
)
)
{
ancestors
.
push
(
judge
);
}
}
return
ancestors
;
}
}
};
};
}()
);
}()
);
\ No newline at end of file
src/module/dragtree.js
View file @
69b9d074
...
@@ -75,36 +75,7 @@ var DragBox = kity.createClass( "DragBox", {
...
@@ -75,36 +75,7 @@ var DragBox = kity.createClass( "DragBox", {
// 2. 从后往前枚举排序的结果,如果发现枚举目标之前存在其祖先,
// 2. 从后往前枚举排序的结果,如果发现枚举目标之前存在其祖先,
// 则排除枚举目标作为拖放源,否则加入拖放源
// 则排除枚举目标作为拖放源,否则加入拖放源
_calcDragSources
:
function
()
{
_calcDragSources
:
function
()
{
var
nodes
=
this
.
_minder
.
getSelectedNodes
().
slice
(
0
),
this
.
_dragSources
=
this
.
_minder
.
getSelectedAncestors
();
ancestors
=
[],
judge
;
// 根节点不参与计算
var
rootIndex
=
nodes
.
indexOf
(
this
.
_minder
.
getRoot
()
);
if
(
~
rootIndex
)
{
nodes
.
splice
(
rootIndex
,
1
);
}
// 判断 nodes 列表中是否存在 judge 的祖先
function
hasAncestor
(
nodes
,
judge
)
{
for
(
var
i
=
nodes
.
length
-
1
;
i
>=
0
;
--
i
)
{
if
(
nodes
[
i
].
isAncestorOf
(
judge
)
)
return
true
;
}
return
false
;
}
// 按照拓扑排序
nodes
.
sort
(
function
(
node1
,
node2
)
{
return
node1
.
getLevel
()
-
node2
.
getLevel
();
}
);
// 因为是拓扑有序的,所以只需往上查找
while
(
(
judge
=
nodes
.
pop
()
)
)
{
if
(
!
hasAncestor
(
nodes
,
judge
)
)
{
ancestors
.
push
(
judge
);
}
}
this
.
_dragSources
=
ancestors
;
},
},
...
...
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