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
1a6a1dce
Commit
1a6a1dce
authored
Jan 24, 2014
by
campaign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils 添加getNodeCommonAncestor
parent
c8922806
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
59 deletions
+75
-59
node.js
src/core/node.js
+59
-59
utils.js
src/core/utils.js
+16
-0
No files found.
src/core/node.js
View file @
1a6a1dce
...
...
@@ -3,35 +3,30 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
this
.
parent
=
null
;
this
.
children
=
[];
this
.
data
=
{};
if
(
U
tils
.
isString
(
options
)
)
{
this
.
setData
(
'text'
,
options
)
;
if
(
u
tils
.
isString
(
options
)
)
{
this
.
setData
(
'text'
,
options
)
}
else
{
this
.
setData
(
options
);
}
this
.
rc
=
new
kity
.
Group
();
this
.
rc
.
minderNode
=
this
;
},
setPoint
:
function
(
x
,
y
)
{
if
(
arguments
.
length
===
0
)
{
this
.
setData
(
'point'
,
null
);
}
else
{
this
.
setData
(
'point'
,
{
x
:
x
,
y
:
y
}
);
}
setPoint
:
function
(
x
,
y
){
this
.
setData
(
'point'
,{
x
:
x
,
y
:
y
})
},
getPoint
:
function
()
{
return
this
.
getData
(
'point'
);
getPoint
:
function
()
{
return
this
.
getData
(
'point'
)
},
setText
:
function
(
text
)
{
this
.
setData
(
'text'
,
text
)
;
this
.
setData
(
'text'
,
text
)
},
getText
:
function
()
{
return
this
.
getData
(
'text'
)
;
return
this
.
getData
(
'text'
)
},
isRoot
:
function
()
{
return
this
.
getParent
()
==
=
null
?
true
:
false
;
return
this
.
getParent
()
==
null
?
true
:
false
;
},
getParent
:
function
()
{
return
this
.
parent
;
...
...
@@ -94,7 +89,17 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
node
.
root
=
parent
.
root
;
this
.
children
.
splice
(
index
,
0
,
node
);
// this.handelInsert( node );
},
//
// handelInsert: function ( node ) {
// var root = this.getRoot();
// if ( root.tnh ) {
// root.tnh.handelNodeInsert.call( root.tnh, node );
// }
// },
appendChild
:
function
(
node
)
{
return
this
.
insertChild
(
node
);
},
...
...
@@ -112,17 +117,25 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
if
(
index
>=
0
)
{
removed
=
this
.
children
.
splice
(
index
,
1
)[
0
];
removed
.
parent
=
null
;
// this.handelRemove( removed );
}
},
// handelRemove: function ( node ) {
// var root = this.getRoot();
// if ( root.tnh ) {
// root.tnh.handelNodeRemove.call( root.tnh, node );
// }
// },
getChild
:
function
(
index
)
{
return
this
.
children
[
index
];
},
getFirstChild
:
function
()
{
return
this
.
children
[
0
]
;
return
this
.
children
[
0
]
},
getLastChild
:
function
()
{
return
this
.
children
[
this
.
children
.
length
-
1
]
;
return
this
.
children
[
this
.
children
.
length
-
1
]
},
getData
:
function
(
name
)
{
if
(
name
===
undefined
)
{
...
...
@@ -132,17 +145,17 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
},
setData
:
function
(
name
,
value
)
{
if
(
name
===
undefined
)
{
this
.
data
=
{}
;
}
else
if
(
Utils
.
isObject
(
name
)
)
{
Utils
.
extend
(
this
.
data
,
name
);
}
else
{
if
(
value
===
undefined
)
{
this
.
data
[
name
]
=
null
;
delete
this
.
data
[
name
];
}
else
{
this
.
data
[
name
]
=
value
;
if
(
name
===
undefined
)
{
this
.
data
=
{}
}
else
if
(
utils
.
isObject
(
name
))
{
utils
.
extend
(
this
.
data
,
name
)
}
else
{
if
(
value
===
undefined
)
{
this
.
data
[
name
]
=
null
;
delete
this
.
data
[
name
]
}
else
{
this
.
data
[
name
]
=
value
;
}
}
},
...
...
@@ -150,20 +163,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return
this
.
rc
;
},
getCommonAncestor
:
function
(
node
)
{
if
(
this
===
node
)
{
return
this
.
parent
;
}
if
(
this
.
contains
(
node
)
)
{
return
this
;
}
if
(
node
.
contains
(
this
)
)
{
return
node
;
}
var
parent
=
this
.
parent
;
while
(
!
parent
.
contains
(
node
)
)
{
parent
=
parent
.
parent
;
}
return
parent
;
return
utils
.
getNodeCommonAncestor
(
this
,
node
)
},
contains
:
function
(
node
)
{
if
(
this
===
node
)
{
...
...
@@ -173,44 +173,44 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return
true
;
}
var
isContain
=
false
;
U
tils
.
each
(
this
.
getChildren
(),
function
(
i
,
n
)
{
u
tils
.
each
(
this
.
getChildren
(),
function
(
i
,
n
)
{
isContain
=
n
.
contains
(
node
);
if
(
isContain
===
true
)
{
return
false
;
return
false
}
}
);
return
isContain
;
},
clone
:
function
()
{
function
cloneNode
(
parent
,
isClonedNode
)
{
clone
:
function
()
{
function
cloneNode
(
parent
,
isClonedNode
)
{
var
_tmp
=
new
KM
.
MinderNode
();
_tmp
.
data
=
Utils
.
clonePlainObject
(
isClonedNode
.
getData
()
);
_tmp
.
data
=
utils
.
clonePlainObject
(
isClonedNode
.
getData
()
);
_tmp
.
parent
=
parent
;
if
(
parent
)
{
parent
.
children
.
push
(
_tmp
);
if
(
parent
)
{
parent
.
children
.
push
(
_tmp
);
}
for
(
var
i
=
0
,
ci
;
ci
=
isClonedNode
.
children
[
i
++
];
)
{
cloneNode
(
_tmp
,
ci
);
for
(
var
i
=
0
,
ci
;
ci
=
isClonedNode
.
children
[
i
++
];)
{
cloneNode
(
_tmp
,
ci
);
}
return
_tmp
;
}
return
function
()
{
return
cloneNode
(
null
,
this
);
return
function
()
{
return
cloneNode
(
null
,
this
);
}
}(),
equals
:
function
(
node
)
{
if
(
node
.
children
.
length
!=
this
.
children
.
length
)
{
equals
:
function
(
node
)
{
if
(
node
.
children
.
length
!=
this
.
children
.
length
)
{
return
false
;
}
if
(
utils
.
compareObject
(
node
.
getData
(),
this
.
getData
()
)
===
false
)
{
if
(
utils
.
compareObject
(
node
.
getData
(),
this
.
getData
())
===
false
)
{
return
false
;
}
for
(
var
i
=
0
,
ci
;
ci
=
this
.
children
[
i
++
];
)
{
if
(
ci
.
equals
(
node
)
===
false
)
{
for
(
var
i
=
0
,
ci
;
ci
=
this
.
children
[
i
++
];)
{
if
(
ci
.
equals
(
node
)
===
false
)
{
return
false
;
}
}
...
...
src/core/utils.js
View file @
1a6a1dce
...
...
@@ -169,6 +169,22 @@ var utils = Utils = KityMinder.Utils = {
if
(
this
.
isArray
(
obj
)
||
this
.
isString
(
obj
))
return
obj
.
length
===
0
;
for
(
var
key
in
obj
)
if
(
obj
.
hasOwnProperty
(
key
))
return
false
;
return
true
;
},
getNodeCommonAncestor
:
function
(
nodeA
,
nodeB
){
if
(
nodeA
===
nodeB
)
{
return
nodeA
.
parent
}
if
(
nodeA
.
contains
(
nodeB
)
)
{
return
this
}
if
(
nodeB
.
contains
(
nodeA
)
)
{
return
nodeB
}
var
parent
=
nodeA
.
parent
;
while
(
!
parent
.
contains
(
nodeB
)
)
{
parent
=
parent
.
parent
;
}
return
parent
;
}
};
...
...
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