Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / layout / dnd / PlottedDnd.js @ 12

History | View | Annotate | Download (10.5 KB)

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["dojox.layout.dnd.PlottedDnd"]){
9
dojo._hasResource["dojox.layout.dnd.PlottedDnd"]=true;
10
dojo.provide("dojox.layout.dnd.PlottedDnd");
11
dojo.require("dojo.dnd.Source");
12
dojo.require("dojo.dnd.Manager");
13
dojo.require("dojox.layout.dnd.Avatar");
14
dojo.declare("dojox.layout.dnd.PlottedDnd",[dojo.dnd.Source],{GC_OFFSET_X:dojo.dnd.manager().OFFSET_X,GC_OFFSET_Y:dojo.dnd.manager().OFFSET_Y,constructor:function(_1,_2){
15
this.childBoxes=null;
16
this.dropIndicator=new dojox.layout.dnd.DropIndicator("dndDropIndicator","div");
17
this.withHandles=_2.withHandles;
18
this.handleClasses=_2.handleClasses;
19
this.opacity=_2.opacity;
20
this.allowAutoScroll=_2.allowAutoScroll;
21
this.dom=_2.dom;
22
this.singular=true;
23
this.skipForm=true;
24
this._over=false;
25
this.defaultHandleClass="GcDndHandle";
26
this.isDropped=false;
27
this._timer=null;
28
this.isOffset=(_2.isOffset)?true:false;
29
this.offsetDrag=(_2.offsetDrag)?_2.offsetDrag:{x:0,y:0};
30
this.hideSource=_2.hideSource?_2.hideSource:true;
31
this._drop=this.dropIndicator.create();
32
},_calculateCoords:function(_3){
33
dojo.forEach(this.node.childNodes,function(_4){
34
var c=dojo.coords(_4,true);
35
_4.coords={xy:c,w:_4.offsetWidth/2,h:_4.offsetHeight/2,mw:c.w};
36
if(_3){
37
_4.coords.mh=c.h;
38
}
39
},this);
40
},_legalMouseDown:function(e){
41
if(!this.withHandles){
42
return true;
43
}
44
for(var _5=(e.target);_5&&_5!=this.node;_5=_5.parentNode){
45
if(dojo.hasClass(_5,this.defaultHandleClass)){
46
return true;
47
}
48
}
49
return false;
50
},setDndItemSelectable:function(_6,_7){
51
for(var _8=_6;_8&&_6!=this.node;_8=_8.parentNode){
52
if(dojo.hasClass(_8,"dojoDndItem")){
53
dojo.setSelectable(_8,_7);
54
return;
55
}
56
}
57
},getDraggedWidget:function(_9){
58
var _a=_9;
59
while(_a&&_a.nodeName.toLowerCase()!="body"&&!dojo.hasClass(_a,"dojoDndItem")){
60
_a=_a.parentNode;
61
}
62
return (_a)?dijit.byNode(_a):null;
63
},isAccepted:function(_b){
64
var _c=(_b)?_b.getAttribute("dndtype"):null;
65
return (_c&&_c in this.accept);
66
},onDndStart:function(_d,_e,_f){
67
this.firstIndicator=(_d==this);
68
this._calculateCoords(true);
69
var m=dojo.dnd.manager();
70
if(_e[0].coords){
71
this._drop.style.height=_e[0].coords.mh+"px";
72
dojo.style(m.avatar.node,"width",_e[0].coords.mw+"px");
73
}else{
74
this._drop.style.height=m.avatar.node.clientHeight+"px";
75
}
76
this.dndNodes=_e;
77
dojox.layout.dnd.PlottedDnd.superclass.onDndStart.call(this,_d,_e,_f);
78
if(_d==this&&this.hideSource){
79
dojo.forEach(_e,function(n){
80
dojo.style(n,"display","none");
81
});
82
}
83
},onDndCancel:function(){
84
var m=dojo.dnd.manager();
85
if(m.source==this&&this.hideSource){
86
var _10=this.getSelectedNodes();
87
dojo.forEach(_10,function(n){
88
dojo.style(n,"display","");
89
});
90
}
91
dojox.layout.dnd.PlottedDnd.superclass.onDndCancel.call(this);
92
this.deleteDashedZone();
93
},onDndDrop:function(_11,_12,_13,_14){
94
try{
95
if(!this.isAccepted(_12[0])){
96
this.onDndCancel();
97
}else{
98
if(_11==this&&this._over&&this.dropObject){
99
this.current=this.dropObject.c;
100
}
101
dojox.layout.dnd.PlottedDnd.superclass.onDndDrop.call(this,_11,_12,_13,_14);
102
this._calculateCoords(true);
103
}
104
}
105
catch(e){
106
console.warn(e);
107
}
108
},onMouseDown:function(e){
109
if(this.current==null){
110
this.selection={};
111
}else{
112
if(this.current==this.anchor){
113
this.anchor=null;
114
}
115
}
116
if(this.current!==null){
117
var c=dojo.coords(this.current,true);
118
this.current.coords={xy:c,w:this.current.offsetWidth/2,h:this.current.offsetHeight/2,mh:c.h,mw:c.w};
119
this._drop.style.height=this.current.coords.mh+"px";
120
if(this.isOffset){
121
if(this.offsetDrag.x==0&&this.offsetDrag.y==0){
122
var _15=true;
123
var _16=dojo.coords(this._getChildByEvent(e));
124
this.offsetDrag.x=_16.x-e.pageX;
125
this.offsetDrag.y=_16.y-e.clientY;
126
}
127
if(this.offsetDrag.y<16&&this.current!=null){
128
this.offsetDrag.y=this.GC_OFFSET_Y;
129
}
130
var m=dojo.dnd.manager();
131
m.OFFSET_X=this.offsetDrag.x;
132
m.OFFSET_Y=this.offsetDrag.y;
133
if(_15){
134
this.offsetDrag.x=0;
135
this.offsetDrag.y=0;
136
}
137
}
138
}
139
if(dojo.dnd.isFormElement(e)){
140
this.setDndItemSelectable(e.target,true);
141
}else{
142
this.containerSource=true;
143
var _17=this.getDraggedWidget(e.target);
144
if(_17&&_17.dragRestriction){
145
}else{
146
dojox.layout.dnd.PlottedDnd.superclass.onMouseDown.call(this,e);
147
}
148
}
149
},onMouseUp:function(e){
150
dojox.layout.dnd.PlottedDnd.superclass.onMouseUp.call(this,e);
151
this.containerSource=false;
152
if(!dojo.isIE&&this.mouseDown){
153
this.setDndItemSelectable(e.target,true);
154
}
155
var m=dojo.dnd.manager();
156
m.OFFSET_X=this.GC_OFFSET_X;
157
m.OFFSET_Y=this.GC_OFFSET_Y;
158
},onMouseMove:function(e){
159
var m=dojo.dnd.manager();
160
if(this.isDragging){
161
var _18=false;
162
if(this.current!=null||(this.current==null&&!this.dropObject)){
163
if(this.isAccepted(m.nodes[0])||this.containerSource){
164
_18=this.setIndicatorPosition(e);
165
}
166
}
167
if(this.current!=this.targetAnchor||_18!=this.before){
168
this._markTargetAnchor(_18);
169
m.canDrop(!this.current||m.source!=this||!(this.current.id in this.selection));
170
}
171
if(this.allowAutoScroll){
172
this._checkAutoScroll(e);
173
}
174
}else{
175
if(this.mouseDown&&this.isSource){
176
var _19=this.getSelectedNodes();
177
if(_19.length){
178
m.startDrag(this,_19,this.copyState(dojo.isCopyKey(e)));
179
}
180
}
181
if(this.allowAutoScroll){
182
this._stopAutoScroll();
183
}
184
}
185
},_markTargetAnchor:function(_1a){
186
if(this.current==this.targetAnchor&&this.before==_1a){
187
return;
188
}
189
this.targetAnchor=this.current;
190
this.targetBox=null;
191
this.before=_1a;
192
},_unmarkTargetAnchor:function(){
193
if(!this.targetAnchor){
194
return;
195
}
196
this.targetAnchor=null;
197
this.targetBox=null;
198
this.before=true;
199
},setIndicatorPosition:function(e){
200
var _1b=false;
201
if(this.current){
202
if(!this.current.coords||this.allowAutoScroll){
203
this.current.coords={xy:dojo.coords(this.current,true),w:this.current.offsetWidth/2,h:this.current.offsetHeight/2};
204
}
205
_1b=this.horizontal?(e.pageX-this.current.coords.xy.x)<this.current.coords.w:(e.pageY-this.current.coords.xy.y)<this.current.coords.h;
206
this.insertDashedZone(_1b);
207
}else{
208
if(!this.dropObject){
209
this.insertDashedZone(false);
210
}
211
}
212
return _1b;
213
},onOverEvent:function(){
214
this._over=true;
215
dojox.layout.dnd.PlottedDnd.superclass.onOverEvent.call(this);
216
if(this.isDragging){
217
var m=dojo.dnd.manager();
218
if(!this.current&&!this.dropObject&&this.getSelectedNodes()[0]&&this.isAccepted(m.nodes[0])){
219
this.insertDashedZone(false);
220
}
221
}
222
},onOutEvent:function(){
223
this._over=false;
224
this.containerSource=false;
225
dojox.layout.dnd.PlottedDnd.superclass.onOutEvent.call(this);
226
if(this.dropObject){
227
this.deleteDashedZone();
228
}
229
},deleteDashedZone:function(){
230
this._drop.style.display="none";
231
var _1c=this._drop.nextSibling;
232
while(_1c!=null){
233
_1c.coords.xy.y-=parseInt(this._drop.style.height);
234
_1c=_1c.nextSibling;
235
}
236
delete this.dropObject;
237
},insertDashedZone:function(_1d){
238
if(this.dropObject){
239
if(_1d==this.dropObject.b&&((this.current&&this.dropObject.c==this.current.id)||(!this.current&&!this.dropObject.c))){
240
return;
241
}else{
242
this.deleteDashedZone();
243
}
244
}
245
this.dropObject={n:this._drop,c:this.current?this.current.id:null,b:_1d};
246
if(this.current){
247
dojo.place(this._drop,this.current,_1d?"before":"after");
248
if(!this.firstIndicator){
249
var _1e=this._drop.nextSibling;
250
while(_1e!=null){
251
_1e.coords.xy.y+=parseInt(this._drop.style.height);
252
_1e=_1e.nextSibling;
253
}
254
}else{
255
this.firstIndicator=false;
256
}
257
}else{
258
this.node.appendChild(this._drop);
259
}
260
this._drop.style.display="";
261
},insertNodes:function(_1f,_20,_21,_22){
262
if(this.dropObject){
263
dojo.style(this.dropObject.n,"display","none");
264
dojox.layout.dnd.PlottedDnd.superclass.insertNodes.call(this,true,_20,true,this.dropObject.n);
265
this.deleteDashedZone();
266
}else{
267
return dojox.layout.dnd.PlottedDnd.superclass.insertNodes.call(this,_1f,_20,_21,_22);
268
}
269
var _23=dijit.byId(_20[0].getAttribute("widgetId"));
270
if(_23){
271
dojox.layout.dnd._setGcDndHandle(_23,this.withHandles,this.handleClasses);
272
if(this.hideSource){
273
dojo.style(_23.domNode,"display","");
274
}
275
}
276
},_checkAutoScroll:function(e){
277
if(this._timer){
278
clearTimeout(this._timer);
279
}
280
this._stopAutoScroll();
281
var _24=this.dom,y=this._sumAncestorProperties(_24,"offsetTop");
282
if((e.pageY-_24.offsetTop+30)>_24.clientHeight){
283
this.autoScrollActive=true;
284
this._autoScrollDown(_24);
285
}else{
286
if((_24.scrollTop>0)&&(e.pageY-y)<30){
287
this.autoScrollActive=true;
288
this._autoScrollUp(_24);
289
}
290
}
291
},_autoScrollUp:function(_25){
292
if(this.autoScrollActive&&_25.scrollTop>0){
293
_25.scrollTop-=30;
294
this._timer=setTimeout(dojo.hitch(this,"_autoScrollUp",_25),100);
295
}
296
},_autoScrollDown:function(_26){
297
if(this.autoScrollActive&&(_26.scrollTop<(_26.scrollHeight-_26.clientHeight))){
298
_26.scrollTop+=30;
299
this._timer=setTimeout(dojo.hitch(this,"_autoScrollDown",_26),100);
300
}
301
},_stopAutoScroll:function(){
302
this.autoScrollActive=false;
303
},_sumAncestorProperties:function(_27,_28){
304
_27=dojo.byId(_27);
305
if(!_27){
306
return 0;
307
}
308
var _29=0;
309
while(_27){
310
var val=_27[_28];
311
if(val){
312
_29+=val-0;
313
if(_27==dojo.body()){
314
break;
315
}
316
}
317
_27=_27.parentNode;
318
}
319
return _29;
320
}});
321
dojox.layout.dnd._setGcDndHandle=function(_2a,_2b,_2c,_2d){
322
var cls="GcDndHandle";
323
if(!_2d){
324
dojo.query(".GcDndHandle",_2a.domNode).removeClass(cls);
325
}
326
if(!_2b){
327
dojo.addClass(_2a.domNode,cls);
328
}else{
329
var _2e=false;
330
for(var i=_2c.length-1;i>=0;i--){
331
var _2f=dojo.query("."+_2c[i],_2a.domNode)[0];
332
if(_2f){
333
_2e=true;
334
if(_2c[i]!=cls){
335
var _30=dojo.query("."+cls,_2a.domNode);
336
if(_30.length==0){
337
dojo.removeClass(_2a.domNode,cls);
338
}else{
339
_30.removeClass(cls);
340
}
341
dojo.addClass(_2f,cls);
342
}
343
}
344
}
345
if(!_2e){
346
dojo.addClass(_2a.domNode,cls);
347
}
348
}
349
};
350
dojo.declare("dojox.layout.dnd.DropIndicator",null,{constructor:function(cn,tag){
351
this.tag=tag||"div";
352
this.style=cn||null;
353
},isInserted:function(){
354
return (this.node.parentNode&&this.node.parentNode.nodeType==1);
355
},create:function(){
356
if(this.node&&this.isInserted()){
357
return this.node;
358
}
359
var h="90px",el=dojo.doc.createElement(this.tag);
360
if(this.style){
361
el.className=this.style;
362
el.style.height=h;
363
}else{
364
dojo.style(el,{position:"relative",border:"1px dashed #F60",margin:"2px",height:h});
365
}
366
this.node=el;
367
return el;
368
},destroy:function(){
369
if(!this.node||!this.isInserted()){
370
return;
371
}
372
this.node.parentNode.removeChild(this.node);
373
this.node=null;
374
}});
375
dojo.extend(dojo.dnd.Manager,{canDrop:function(_31){
376
var _32=this.target&&_31;
377
if(this.canDropFlag!=_32){
378
this.canDropFlag=_32;
379
if(this.avatar){
380
this.avatar.update();
381
}
382
}
383
},makeAvatar:function(){
384
return (this.source.declaredClass=="dojox.layout.dnd.PlottedDnd")?new dojox.layout.dnd.Avatar(this,this.source.opacity):new dojo.dnd.Avatar(this);
385
}});
386
if(dojo.isIE){
387
dojox.layout.dnd.handdleIE=[dojo.subscribe("/dnd/start",null,function(){
388
IEonselectstart=document.body.onselectstart;
389
document.body.onselectstart=function(){
390
return false;
391
};
392
}),dojo.subscribe("/dnd/cancel",null,function(){
393
document.body.onselectstart=IEonselectstart;
394
}),dojo.subscribe("/dnd/drop",null,function(){
395
document.body.onselectstart=IEonselectstart;
396
})];
397
dojo.addOnWindowUnload(function(){
398
dojo.forEach(dojox.layout.dnd.handdleIE,dojo.unsubscribe);
399
});
400
}
401
}