Commit 1af03e5a authored by campaign's avatar campaign

修改了select的需求

parent fa45c9be
// 选区管理
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment