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
4b1aeed9
Commit
4b1aeed9
authored
Jun 17, 2014
by
techird
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add getCommonAncestor() method
parent
dd6d4317
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
18 deletions
+27
-18
node.js
src/core/node.js
+26
-1
utils.js
src/core/utils.js
+0
-16
node.js
src/module/node.js
+1
-1
No files found.
src/core/node.js
View file @
4b1aeed9
...
...
@@ -291,3 +291,28 @@ var MinderNode = KityMinder.MinderNode = kity.createClass('MinderNode', {
return
this
;
}
});
MinderNode
.
getCommonAncestor
=
function
(
nodeA
,
nodeB
)
{
switch
(
arguments
.
length
)
{
case
1
:
return
nodeA
;
case
2
:
if
(
nodeA
.
contains
(
nodeB
))
{
return
nodeA
;
}
if
(
nodeB
.
contains
(
nodeA
))
{
return
nodeB
;
}
var
ancestor
=
nodeA
.
parent
;
while
(
ancestor
&&
!
ancestor
.
contains
(
nodeB
))
{
ancestor
=
ancestor
.
parent
;
}
return
ancestor
;
default
:
return
Array
.
prototype
.
reduce
.
call
(
arguments
,
function
(
prev
,
current
)
{
return
MinderNode
.
getCommonAncestor
(
prev
,
current
);
},
nodeA
);
}
};
\ No newline at end of file
src/core/utils.js
View file @
4b1aeed9
...
...
@@ -172,22 +172,6 @@ var utils = Utils = KityMinder.Utils = {
if
(
obj
.
hasOwnProperty
(
key
))
return
false
;
return
true
;
},
getNodeCommonAncestor
:
function
(
nodeA
,
nodeB
)
{
if
(
nodeA
===
nodeB
)
{
return
nodeA
.
parent
;
}
if
(
nodeA
.
contains
(
nodeB
))
{
return
nodeB
;
}
if
(
nodeB
.
contains
(
nodeA
))
{
return
nodeB
;
}
var
parent
=
nodeA
.
parent
;
while
(
!
parent
.
contains
(
nodeB
))
{
parent
=
parent
.
parent
;
}
return
parent
;
},
loadFile
:
function
()
{
var
tmpList
=
[];
...
...
src/module/node.js
View file @
4b1aeed9
...
...
@@ -42,7 +42,7 @@ var RemoveNodeCommand = kity.createClass('RemoverNodeCommand', {
base
:
Command
,
execute
:
function
(
km
,
text
)
{
var
nodes
=
km
.
getSelectedNodes
();
var
ancestor
=
km
.
getSelectedAncestors
()[
0
]
;
var
ancestor
=
MinderNode
.
getCommonAncestor
.
apply
(
null
,
nodes
)
;
nodes
.
forEach
(
function
(
node
)
{
km
.
removeNode
(
node
);
...
...
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