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
1af03e5a
Commit
1af03e5a
authored
Jan 15, 2014
by
campaign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了select的需求
parent
fa45c9be
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
66 deletions
+56
-66
minder.select.js
src/core/minder.select.js
+56
-66
No files found.
src/core/minder.select.js
View file @
1af03e5a
// 选区管理
kity
.
extendClass
(
Minder
,
{
_initSelection
:
function
()
{
this
.
_selectedNodes
=
[];
},
getSelectedNodes
:
function
()
{
return
this
.
_selectedNodes
.
slice
(
0
);
},
select
:
function
(
nodes
)
{
var
selection
=
this
.
_selectedNodes
;
if
(
false
===
nodes
instanceof
Array
)
nodes
=
[
nodes
];
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
if
(
selection
.
indexOf
(
nodes
[
i
]
)
===
-
1
)
{
selection
.
push
(
nodes
[
i
]
);
this
.
highlightNode
(
nodes
[
i
]
);
}
}
return
this
;
},
highlightNode
:
function
(
node
)
{
kity
.
extendClass
(
Minder
,
function
(){
function
highlightNode
(
km
,
node
){
node
.
setData
(
"highlight"
,
true
);
this
.
renderNode
(
node
);
},
isNodeSelected
:
function
(
node
)
{
return
!!~
this
.
_selectedNodes
.
indexOf
(
node
);
},
selectSingle
:
function
(
node
)
{
return
this
.
clearSelect
().
select
(
node
);
},
toggleSelect
:
function
(
nodes
)
{
var
selection
=
this
.
_selectedNodes
;
var
needAdd
=
[],
needRemove
=
[];
if
(
false
===
nodes
instanceof
Array
)
nodes
=
[
nodes
];
for
(
var
i
=
0
;
i
<
nodes
.
length
;
i
++
)
{
if
(
selection
.
indexOf
(
nodes
[
i
]
)
===
-
1
)
{
needAdd
.
push
(
nodes
[
i
]
);
this
.
highlightNode
(
nodes
[
i
]
);
}
else
{
needRemove
.
push
(
nodes
[
i
]
);
this
.
unhighlightNode
(
nodes
[
i
]
);
}
}
return
this
.
clearSelect
(
needRemove
).
select
(
needAdd
);
},
km
.
renderNode
(
node
);
}
function
unhighlightNode
(
km
,
node
){
node
.
setData
(
"highlight"
,
false
);
km
.
renderNode
(
node
);
}
return
{
_initSelection
:
function
()
{
this
.
_selectedNodes
=
[];
},
clearSelect
:
function
(
nodes
)
{
if
(
!
nodes
)
{
for
(
var
_i
=
0
;
_i
<
this
.
_selectedNodes
.
length
;
_i
++
)
{
this
.
unhighlightNode
(
this
.
_selectedNodes
[
_i
]
);
getSelectedNodes
:
function
(
)
{
//如果没有选中节点,默认是root节点
if
(
this
.
_selectedNodes
.
length
==
0
)
{
this
.
_selectedNodes
.
push
(
this
.
getRoot
())
}
this
.
_selectedNodes
=
[];
//不能克隆返回,会对当前选区操作,从而影响querycommand
return
this
.
_selectedNodes
;
},
removeAllSelectedNodes
:
function
(){
utils
.
each
(
this
.
getSelectedNodes
(),
function
(
i
,
n
){
unhighlightNode
(
this
,
n
);
});
this
.
_selectedNodes
=
[]
},
select
:
function
(
nodes
)
{
this
.
removeAllSelectedNodes
();
var
me
=
this
;
utils
.
each
(
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
],
function
(
i
,
n
){
me
.
_selectedNodes
.
push
(
n
);
highlightNode
(
this
,
n
)
});
return
this
;
}
if
(
false
===
nodes
instanceof
Array
)
nodes
=
[
nodes
];
var
originSelection
=
this
.
_selectedNodes
;
var
newSelection
=
[];
for
(
var
i
=
0
;
i
<
originSelection
.
length
;
i
++
)
{
if
(
nodes
.
indexOf
(
originSelection
[
i
]
)
===
-
1
)
{
newSelection
.
push
(
originSelection
[
i
]
);
},
isNodeSelected
:
function
(
node
)
{
return
node
.
getData
(
'highlight'
)
===
true
},
//当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
toggleSelect
:
function
(
nodes
)
{
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
var
selectedNodes
=
this
.
getSelectedNodes
().
slice
(
0
);
this
.
removeAllSelectedNodes
();
for
(
var
i
=
0
,
n
;
n
=
selectedNodes
[
i
];){
var
index
=
utils
.
indexOf
(
nodes
,
n
);
if
(
index
!=
-
1
){
nodes
.
push
(
n
);
i
++
;
}
else
{
unhighlightNode
(
this
,
n
);
selectedNodes
.
splice
(
i
,
1
)
}
}
var
me
=
this
;
utils
.
each
(
nodes
,
function
(
i
,
n
){
highlightNode
(
me
,
n
)
});
this
.
_selectedNodes
=
nodes
;
}
this
.
_selectedNodes
=
newSelection
;
return
this
;
},
unhighlightNode
:
function
(
node
)
{
node
.
setData
(
"highlight"
,
false
);
this
.
renderNode
(
node
);
}
}
);
\ No newline at end of file
}()
);
\ No newline at end of file
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