Commit 1af03e5a authored by campaign's avatar campaign

修改了select的需求

parent fa45c9be
// 选区管理 // 选区管理
kity.extendClass( Minder, { kity.extendClass( Minder, function(){
_initSelection: function () { function highlightNode(km,node){
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 ) {
node.setData( "highlight", true ); node.setData( "highlight", true );
this.renderNode( node ); km.renderNode( node );
}, }
isNodeSelected: function ( node ) { function unhighlightNode(km,node){
return !!~this._selectedNodes.indexOf( node ); node.setData( "highlight", false );
}, km.renderNode( node );
}
selectSingle: function ( node ) { return {
return this.clearSelect().select( node ); _initSelection: function () {
}, this._selectedNodes = [];
},
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 );
},
clearSelect: function ( nodes ) { getSelectedNodes: function () {
if ( !nodes ) { //如果没有选中节点,默认是root节点
for ( var _i = 0; _i < this._selectedNodes.length; _i++ ) { if(this._selectedNodes.length == 0){
this.unhighlightNode( this._selectedNodes[ _i ] ); 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; return this;
} },
if ( false === nodes instanceof Array ) nodes = [ nodes ]; isNodeSelected: function ( node ) {
var originSelection = this._selectedNodes; return node.getData('highlight') === true
var newSelection = []; },
for ( var i = 0; i < originSelection.length; i++ ) { //当前选区中的节点在给定的节点范围内的保留选中状态,没在给定范围的取消选中,给定范围中的但没在当前选中范围的也做选中效果
if ( nodes.indexOf( originSelection[ i ] ) === -1 ) { toggleSelect: function ( nodes ) {
newSelection.push( originSelection[ i ] ); 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