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