Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dijit / tree / _dndSelector.js

History | View | Annotate | Download (3.06 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dijit.tree._dndSelector"]){
9
dojo._hasResource["dijit.tree._dndSelector"]=true;
10
dojo.provide("dijit.tree._dndSelector");
11
dojo.require("dojo.dnd.common");
12
dojo.require("dijit.tree._dndContainer");
13
dojo.declare("dijit.tree._dndSelector",dijit.tree._dndContainer,{constructor:function(_1,_2){
14
this.selection={};
15
this.anchor=null;
16
this.simpleSelection=false;
17
this.events.push(dojo.connect(this.tree.domNode,"onmousedown",this,"onMouseDown"),dojo.connect(this.tree.domNode,"onmouseup",this,"onMouseUp"),dojo.connect(this.tree.domNode,"onmousemove",this,"onMouseMove"));
18
},singular:false,getSelectedNodes:function(){
19
return this.selection;
20
},selectNone:function(){
21
return this._removeSelection()._removeAnchor();
22
},destroy:function(){
23
this.inherited(arguments);
24
this.selection=this.anchor=null;
25
},onMouseDown:function(e){
26
if(!this.current){
27
return;
28
}
29
if(e.button==dojo.mouseButtons.RIGHT){
30
return;
31
}
32
var _3=dijit.getEnclosingWidget(this.current),id=_3.id+"-dnd";
33
if(!dojo.hasAttr(this.current,"id")){
34
dojo.attr(this.current,"id",id);
35
}
36
if(!this.singular&&!dojo.isCopyKey(e)&&!e.shiftKey&&(this.current.id in this.selection)){
37
this.simpleSelection=true;
38
dojo.stopEvent(e);
39
return;
40
}
41
if(this.singular){
42
if(this.anchor==this.current){
43
if(dojo.isCopyKey(e)){
44
this.selectNone();
45
}
46
}else{
47
this.selectNone();
48
this.anchor=this.current;
49
this._addItemClass(this.anchor,"Anchor");
50
this.selection[this.current.id]=this.current;
51
}
52
}else{
53
if(!this.singular&&e.shiftKey){
54
if(dojo.isCopyKey(e)){
55
}else{
56
}
57
}else{
58
if(dojo.isCopyKey(e)){
59
if(this.anchor==this.current){
60
delete this.selection[this.anchor.id];
61
this._removeAnchor();
62
}else{
63
if(this.current.id in this.selection){
64
this._removeItemClass(this.current,"Selected");
65
delete this.selection[this.current.id];
66
}else{
67
if(this.anchor){
68
this._removeItemClass(this.anchor,"Anchor");
69
this._addItemClass(this.anchor,"Selected");
70
}
71
this.anchor=this.current;
72
this._addItemClass(this.current,"Anchor");
73
this.selection[this.current.id]=this.current;
74
}
75
}
76
}else{
77
if(!(id in this.selection)){
78
this.selectNone();
79
this.anchor=this.current;
80
this._addItemClass(this.current,"Anchor");
81
this.selection[id]=this.current;
82
}
83
}
84
}
85
}
86
dojo.stopEvent(e);
87
},onMouseUp:function(e){
88
if(!this.simpleSelection){
89
return;
90
}
91
this.simpleSelection=false;
92
this.selectNone();
93
if(this.current){
94
this.anchor=this.current;
95
this._addItemClass(this.anchor,"Anchor");
96
this.selection[this.current.id]=this.current;
97
}
98
},onMouseMove:function(e){
99
this.simpleSelection=false;
100
},_removeSelection:function(){
101
var e=dojo.dnd._empty;
102
for(var i in this.selection){
103
if(i in e){
104
continue;
105
}
106
var _4=dojo.byId(i);
107
if(_4){
108
this._removeItemClass(_4,"Selected");
109
}
110
}
111
this.selection={};
112
return this;
113
},_removeAnchor:function(){
114
if(this.anchor){
115
this._removeItemClass(this.anchor,"Anchor");
116
this.anchor=null;
117
}
118
return this;
119
},forInSelectedItems:function(f,o){
120
o=o||dojo.global;
121
for(var id in this.selection){
122
f.call(o,this.getItem(id),id,this);
123
}
124
}});
125
}