]>
Commit | Line | Data |
---|---|---|
2f01fe57 AD |
1 | /* |
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["dojo.dnd.Selector"]){ | |
9 | dojo._hasResource["dojo.dnd.Selector"]=true; | |
10 | dojo.provide("dojo.dnd.Selector"); | |
11 | dojo.require("dojo.dnd.common"); | |
12 | dojo.require("dojo.dnd.Container"); | |
13 | dojo.declare("dojo.dnd.Selector",dojo.dnd.Container,{constructor:function(_1,_2){ | |
14 | if(!_2){ | |
15 | _2={}; | |
16 | } | |
17 | this.singular=_2.singular; | |
18 | this.autoSync=_2.autoSync; | |
19 | this.selection={}; | |
20 | this.anchor=null; | |
21 | this.simpleSelection=false; | |
22 | this.events.push(dojo.connect(this.node,"onmousedown",this,"onMouseDown"),dojo.connect(this.node,"onmouseup",this,"onMouseUp")); | |
23 | },singular:false,getSelectedNodes:function(){ | |
24 | var t=new dojo.NodeList(); | |
25 | var e=dojo.dnd._empty; | |
26 | for(var i in this.selection){ | |
27 | if(i in e){ | |
28 | continue; | |
29 | } | |
30 | t.push(dojo.byId(i)); | |
31 | } | |
32 | return t; | |
33 | },selectNone:function(){ | |
34 | return this._removeSelection()._removeAnchor(); | |
35 | },selectAll:function(){ | |
36 | this.forInItems(function(_3,id){ | |
37 | this._addItemClass(dojo.byId(id),"Selected"); | |
38 | this.selection[id]=1; | |
39 | },this); | |
40 | return this._removeAnchor(); | |
41 | },deleteSelectedNodes:function(){ | |
42 | var e=dojo.dnd._empty; | |
43 | for(var i in this.selection){ | |
44 | if(i in e){ | |
45 | continue; | |
46 | } | |
47 | var n=dojo.byId(i); | |
48 | this.delItem(i); | |
49 | dojo.destroy(n); | |
50 | } | |
51 | this.anchor=null; | |
52 | this.selection={}; | |
53 | return this; | |
54 | },forInSelectedItems:function(f,o){ | |
55 | o=o||dojo.global; | |
56 | var s=this.selection,e=dojo.dnd._empty; | |
57 | for(var i in s){ | |
58 | if(i in e){ | |
59 | continue; | |
60 | } | |
61 | f.call(o,this.getItem(i),i,this); | |
62 | } | |
63 | },sync:function(){ | |
64 | dojo.dnd.Selector.superclass.sync.call(this); | |
65 | if(this.anchor){ | |
66 | if(!this.getItem(this.anchor.id)){ | |
67 | this.anchor=null; | |
68 | } | |
69 | } | |
70 | var t=[],e=dojo.dnd._empty; | |
71 | for(var i in this.selection){ | |
72 | if(i in e){ | |
73 | continue; | |
74 | } | |
75 | if(!this.getItem(i)){ | |
76 | t.push(i); | |
77 | } | |
78 | } | |
79 | dojo.forEach(t,function(i){ | |
80 | delete this.selection[i]; | |
81 | },this); | |
82 | return this; | |
83 | },insertNodes:function(_4,_5,_6,_7){ | |
84 | var _8=this._normalizedCreator; | |
85 | this._normalizedCreator=function(_9,_a){ | |
86 | var t=_8.call(this,_9,_a); | |
87 | if(_4){ | |
88 | if(!this.anchor){ | |
89 | this.anchor=t.node; | |
90 | this._removeItemClass(t.node,"Selected"); | |
91 | this._addItemClass(this.anchor,"Anchor"); | |
92 | }else{ | |
93 | if(this.anchor!=t.node){ | |
94 | this._removeItemClass(t.node,"Anchor"); | |
95 | this._addItemClass(t.node,"Selected"); | |
96 | } | |
97 | } | |
98 | this.selection[t.node.id]=1; | |
99 | }else{ | |
100 | this._removeItemClass(t.node,"Selected"); | |
101 | this._removeItemClass(t.node,"Anchor"); | |
102 | } | |
103 | return t; | |
104 | }; | |
105 | dojo.dnd.Selector.superclass.insertNodes.call(this,_5,_6,_7); | |
106 | this._normalizedCreator=_8; | |
107 | return this; | |
108 | },destroy:function(){ | |
109 | dojo.dnd.Selector.superclass.destroy.call(this); | |
110 | this.selection=this.anchor=null; | |
111 | },markupFactory:function(_b,_c){ | |
112 | _b._skipStartup=true; | |
113 | return new dojo.dnd.Selector(_c,_b); | |
114 | },onMouseDown:function(e){ | |
115 | if(this.autoSync){ | |
116 | this.sync(); | |
117 | } | |
118 | if(!this.current){ | |
119 | return; | |
120 | } | |
121 | if(!this.singular&&!dojo.isCopyKey(e)&&!e.shiftKey&&(this.current.id in this.selection)){ | |
122 | this.simpleSelection=true; | |
123 | if(e.button===dojo.mouseButtons.LEFT){ | |
124 | dojo.stopEvent(e); | |
125 | } | |
126 | return; | |
127 | } | |
128 | if(!this.singular&&e.shiftKey){ | |
129 | if(!dojo.isCopyKey(e)){ | |
130 | this._removeSelection(); | |
131 | } | |
132 | var c=this.getAllNodes(); | |
133 | if(c.length){ | |
134 | if(!this.anchor){ | |
135 | this.anchor=c[0]; | |
136 | this._addItemClass(this.anchor,"Anchor"); | |
137 | } | |
138 | this.selection[this.anchor.id]=1; | |
139 | if(this.anchor!=this.current){ | |
140 | var i=0; | |
141 | for(;i<c.length;++i){ | |
142 | var _d=c[i]; | |
143 | if(_d==this.anchor||_d==this.current){ | |
144 | break; | |
145 | } | |
146 | } | |
147 | for(++i;i<c.length;++i){ | |
148 | var _d=c[i]; | |
149 | if(_d==this.anchor||_d==this.current){ | |
150 | break; | |
151 | } | |
152 | this._addItemClass(_d,"Selected"); | |
153 | this.selection[_d.id]=1; | |
154 | } | |
155 | this._addItemClass(this.current,"Selected"); | |
156 | this.selection[this.current.id]=1; | |
157 | } | |
158 | } | |
159 | }else{ | |
160 | if(this.singular){ | |
161 | if(this.anchor==this.current){ | |
162 | if(dojo.isCopyKey(e)){ | |
163 | this.selectNone(); | |
164 | } | |
165 | }else{ | |
166 | this.selectNone(); | |
167 | this.anchor=this.current; | |
168 | this._addItemClass(this.anchor,"Anchor"); | |
169 | this.selection[this.current.id]=1; | |
170 | } | |
171 | }else{ | |
172 | if(dojo.isCopyKey(e)){ | |
173 | if(this.anchor==this.current){ | |
174 | delete this.selection[this.anchor.id]; | |
175 | this._removeAnchor(); | |
176 | }else{ | |
177 | if(this.current.id in this.selection){ | |
178 | this._removeItemClass(this.current,"Selected"); | |
179 | delete this.selection[this.current.id]; | |
180 | }else{ | |
181 | if(this.anchor){ | |
182 | this._removeItemClass(this.anchor,"Anchor"); | |
183 | this._addItemClass(this.anchor,"Selected"); | |
184 | } | |
185 | this.anchor=this.current; | |
186 | this._addItemClass(this.current,"Anchor"); | |
187 | this.selection[this.current.id]=1; | |
188 | } | |
189 | } | |
190 | }else{ | |
191 | if(!(this.current.id in this.selection)){ | |
192 | this.selectNone(); | |
193 | this.anchor=this.current; | |
194 | this._addItemClass(this.current,"Anchor"); | |
195 | this.selection[this.current.id]=1; | |
196 | } | |
197 | } | |
198 | } | |
199 | } | |
200 | dojo.stopEvent(e); | |
201 | },onMouseUp:function(e){ | |
202 | if(!this.simpleSelection){ | |
203 | return; | |
204 | } | |
205 | this.simpleSelection=false; | |
206 | this.selectNone(); | |
207 | if(this.current){ | |
208 | this.anchor=this.current; | |
209 | this._addItemClass(this.anchor,"Anchor"); | |
210 | this.selection[this.current.id]=1; | |
211 | } | |
212 | },onMouseMove:function(e){ | |
213 | this.simpleSelection=false; | |
214 | },onOverEvent:function(){ | |
215 | this.onmousemoveEvent=dojo.connect(this.node,"onmousemove",this,"onMouseMove"); | |
216 | },onOutEvent:function(){ | |
217 | dojo.disconnect(this.onmousemoveEvent); | |
218 | delete this.onmousemoveEvent; | |
219 | },_removeSelection:function(){ | |
220 | var e=dojo.dnd._empty; | |
221 | for(var i in this.selection){ | |
222 | if(i in e){ | |
223 | continue; | |
224 | } | |
225 | var _e=dojo.byId(i); | |
226 | if(_e){ | |
227 | this._removeItemClass(_e,"Selected"); | |
228 | } | |
229 | } | |
230 | this.selection={}; | |
231 | return this; | |
232 | },_removeAnchor:function(){ | |
233 | if(this.anchor){ | |
234 | this._removeItemClass(this.anchor,"Anchor"); | |
235 | this.anchor=null; | |
236 | } | |
237 | return this; | |
238 | }}); | |
239 | } |