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
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){
17 this.singular=_2.singular;
18 this.autoSync=_2.autoSync;
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){
33 },selectNone:function(){
34 return this._removeSelection()._removeAnchor();
35 },selectAll:function(){
36 this.forInItems(function(_3,id){
37 this._addItemClass(dojo.byId(id),"Selected");
40 return this._removeAnchor();
41 },deleteSelectedNodes:function(){
42 var e=dojo.dnd._empty;
43 for(var i in this.selection){
54 },forInSelectedItems:function(f,o){
56 var s=this.selection,e=dojo.dnd._empty;
61 f.call(o,this.getItem(i),i,this);
64 dojo.dnd.Selector.superclass.sync.call(this);
66 if(!this.getItem(this.anchor.id)){
70 var t=[],e=dojo.dnd._empty;
71 for(var i in this.selection){
79 dojo.forEach(t,function(i){
80 delete this.selection[i];
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);
90 this._removeItemClass(t.node,"Selected");
91 this._addItemClass(this.anchor,"Anchor");
93 if(this.anchor!=t.node){
94 this._removeItemClass(t.node,"Anchor");
95 this._addItemClass(t.node,"Selected");
98 this.selection[t.node.id]=1;
100 this._removeItemClass(t.node,"Selected");
101 this._removeItemClass(t.node,"Anchor");
105 dojo.dnd.Selector.superclass.insertNodes.call(this,_5,_6,_7);
106 this._normalizedCreator=_8;
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){
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){
128 if(!this.singular&&e.shiftKey){
129 if(!dojo.isCopyKey(e)){
130 this._removeSelection();
132 var c=this.getAllNodes();
136 this._addItemClass(this.anchor,"Anchor");
138 this.selection[this.anchor.id]=1;
139 if(this.anchor!=this.current){
141 for(;i<c.length;++i){
143 if(_d==this.anchor||_d==this.current){
147 for(++i;i<c.length;++i){
149 if(_d==this.anchor||_d==this.current){
152 this._addItemClass(_d,"Selected");
153 this.selection[_d.id]=1;
155 this._addItemClass(this.current,"Selected");
156 this.selection[this.current.id]=1;
161 if(this.anchor==this.current){
162 if(dojo.isCopyKey(e)){
167 this.anchor=this.current;
168 this._addItemClass(this.anchor,"Anchor");
169 this.selection[this.current.id]=1;
172 if(dojo.isCopyKey(e)){
173 if(this.anchor==this.current){
174 delete this.selection[this.anchor.id];
175 this._removeAnchor();
177 if(this.current.id in this.selection){
178 this._removeItemClass(this.current,"Selected");
179 delete this.selection[this.current.id];
182 this._removeItemClass(this.anchor,"Anchor");
183 this._addItemClass(this.anchor,"Selected");
185 this.anchor=this.current;
186 this._addItemClass(this.current,"Anchor");
187 this.selection[this.current.id]=1;
191 if(!(this.current.id in this.selection)){
193 this.anchor=this.current;
194 this._addItemClass(this.current,"Anchor");
195 this.selection[this.current.id]=1;
201 },onMouseUp:function(e){
202 if(!this.simpleSelection){
205 this.simpleSelection=false;
208 this.anchor=this.current;
209 this._addItemClass(this.anchor,"Anchor");
210 this.selection[this.current.id]=1;
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){
227 this._removeItemClass(_e,"Selected");
232 },_removeAnchor:function(){
234 this._removeItemClass(this.anchor,"Anchor");