root / trunk / web / dojo / dojox / mdnd / adapter / DndToDojo.js @ 12
History | View | Annotate | Download (8.95 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.mdnd.adapter.DndToDojo"]){ |
9 |
dojo._hasResource["dojox.mdnd.adapter.DndToDojo"]=true; |
10 |
dojo.provide("dojox.mdnd.adapter.DndToDojo");
|
11 |
dojo.require("dojox.mdnd.PureSource");
|
12 |
dojo.require("dojox.mdnd.LazyManager");
|
13 |
dojo.declare("dojox.mdnd.adapter.DndToDojo",null,{_dojoList:null,_currentDojoArea:null,_dojoxManager:null,_dragStartHandler:null,_dropHandler:null,_moveHandler:null,_moveUpHandler:null,_draggedNode:null,constructor:function(){ |
14 |
this._dojoList=[];
|
15 |
this._currentDojoArea=null; |
16 |
this._dojoxManager=dojox.mdnd.areaManager();
|
17 |
this._dragStartHandler=dojo.subscribe("/dojox/mdnd/drag/start",this,function(_1,_2,_3){ |
18 |
this._draggedNode=_1;
|
19 |
this._moveHandler=dojo.connect(dojo.doc,"onmousemove",this,"onMouseMove"); |
20 |
}); |
21 |
this._dropHandler=dojo.subscribe("/dojox/mdnd/drop",this,function(_4,_5,_6){ |
22 |
if(this._currentDojoArea){ |
23 |
dojo.publish("/dojox/mdnd/adapter/dndToDojo/cancel",[this._currentDojoArea.node,this._currentDojoArea.type,this._draggedNode,this.accept]); |
24 |
} |
25 |
this._draggedNode=null; |
26 |
this._currentDojoArea=null; |
27 |
dojo.disconnect(this._moveHandler);
|
28 |
}); |
29 |
},_getIndexDojoArea:function(_7){ |
30 |
if(_7){
|
31 |
for(var i=0,l=this._dojoList.length;i<l;i++){ |
32 |
if(this._dojoList[i].node===_7){ |
33 |
return i;
|
34 |
} |
35 |
} |
36 |
} |
37 |
return -1; |
38 |
},_initCoordinates:function(_8){ |
39 |
if(_8){
|
40 |
var _9=dojo.position(_8,true),_a={}; |
41 |
_a.x=_9.x; |
42 |
_a.y=_9.y; |
43 |
_a.x1=_9.x+_9.w; |
44 |
_a.y1=_9.y+_9.h; |
45 |
return _a;
|
46 |
} |
47 |
return null; |
48 |
},register:function(_b,_c,_d){ |
49 |
if(this._getIndexDojoArea(_b)==-1){ |
50 |
var _e=this._initCoordinates(_b),_f={"node":_b,"type":_c,"dojo":(_d)?_d:false,"coords":_e}; |
51 |
this._dojoList.push(_f);
|
52 |
if(_d&&!this._lazyManager){ |
53 |
this._lazyManager=new dojox.mdnd.LazyManager(); |
54 |
} |
55 |
} |
56 |
},unregisterByNode:function(_10){ |
57 |
var _11=this._getIndexDojoArea(_10); |
58 |
if(_11!=-1){ |
59 |
this._dojoList.splice(_11,1); |
60 |
} |
61 |
},unregisterByType:function(_12){ |
62 |
if(_12){
|
63 |
var _13=[];
|
64 |
dojo.forEach(this._dojoList,function(_14,i){ |
65 |
if(_14.type!=_12){
|
66 |
_13.push(_14); |
67 |
} |
68 |
}); |
69 |
this._dojoList=_13;
|
70 |
} |
71 |
},unregister:function(){ |
72 |
this._dojoList=[];
|
73 |
},refresh:function(){ |
74 |
var _15=this._dojoList; |
75 |
this.unregister();
|
76 |
dojo.forEach(_15,function(_16){
|
77 |
_16.coords=this._initCoordinates(_16.node);
|
78 |
},this);
|
79 |
this._dojoList=_15;
|
80 |
},refreshByType:function(_17){ |
81 |
var _18=this._dojoList; |
82 |
this.unregister();
|
83 |
dojo.forEach(_18,function(_19){
|
84 |
if(_19.type==_17){
|
85 |
_19.coords=this._initCoordinates(_19.node);
|
86 |
} |
87 |
},this);
|
88 |
this._dojoList=_18;
|
89 |
},_getHoverDojoArea:function(_1a){ |
90 |
this._oldDojoArea=this._currentDojoArea; |
91 |
this._currentDojoArea=null; |
92 |
var x=_1a.x;
|
93 |
var y=_1a.y;
|
94 |
var _1b=this._dojoList.length; |
95 |
for(var i=0;i<_1b;i++){ |
96 |
var _1c=this._dojoList[i]; |
97 |
var _1d=_1c.coords;
|
98 |
if(_1d.x<=x&&x<=_1d.x1&&_1d.y<=y&&y<=_1d.y1){
|
99 |
this._currentDojoArea=_1c;
|
100 |
break;
|
101 |
} |
102 |
} |
103 |
},onMouseMove:function(e){ |
104 |
var _1e={"x":e.pageX,"y":e.pageY}; |
105 |
this._getHoverDojoArea(_1e);
|
106 |
if(this._currentDojoArea!=this._oldDojoArea){ |
107 |
if(this._currentDojoArea==null){ |
108 |
this.onDragExit(e);
|
109 |
}else{
|
110 |
if(this._oldDojoArea==null){ |
111 |
this.onDragEnter(e);
|
112 |
}else{
|
113 |
this.onDragExit(e);
|
114 |
this.onDragEnter(e);
|
115 |
} |
116 |
} |
117 |
} |
118 |
},isAccepted:function(_1f,_20){ |
119 |
return true; |
120 |
},onDragEnter:function(e){ |
121 |
if(this._currentDojoArea.dojo){ |
122 |
dojo.disconnect(this._dojoxManager._dragItem.handlers.pop());
|
123 |
dojo.disconnect(this._dojoxManager._dragItem.handlers.pop());
|
124 |
dojo.disconnect(this._dojoxManager._dragItem.item.events.pop());
|
125 |
dojo.body().removeChild(this._dojoxManager._cover);
|
126 |
dojo.body().removeChild(this._dojoxManager._cover2);
|
127 |
var _21=this._dojoxManager._dragItem.item.node; |
128 |
if(dojox.mdnd.adapter._dndFromDojo){
|
129 |
dojox.mdnd.adapter._dndFromDojo.unsubscribeDnd(); |
130 |
} |
131 |
dojo.style(_21,{"position":"relative","top":"0","left":"0"}); |
132 |
this._lazyManager.startDrag(e,_21);
|
133 |
var _22=dojo.connect(this._lazyManager.manager,"overSource",this,function(){ |
134 |
dojo.disconnect(_22); |
135 |
if(this._lazyManager.manager.canDropFlag){ |
136 |
this._dojoxManager._dropIndicator.node.style.display="none"; |
137 |
} |
138 |
}); |
139 |
this.cancelHandler=dojo.subscribe("/dnd/cancel",this,function(){ |
140 |
var _23=this._dojoxManager._dragItem.item; |
141 |
_23.events=[dojo.connect(_23.handle,"onmousedown",_23,"onMouseDown")]; |
142 |
dojo.body().appendChild(this._dojoxManager._cover);
|
143 |
dojo.body().appendChild(this._dojoxManager._cover2);
|
144 |
this._dojoxManager._cover.appendChild(_23.node);
|
145 |
var _24=this._dojoxManager._areaList[this._dojoxManager._sourceIndexArea]; |
146 |
var _25=this._dojoxManager._sourceDropIndex; |
147 |
var _26=null; |
148 |
if(_25!=_24.items.length&&_25!=-1){ |
149 |
_26=_24.items[this._dojoxManager._sourceDropIndex].item.node;
|
150 |
} |
151 |
if(this._dojoxManager._dropIndicator.node.style.display=="none"){ |
152 |
this._dojoxManager._dropIndicator.node.style.display==""; |
153 |
} |
154 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDrag",this._dojoxManager,"onDrag")); |
155 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDragEnd",this._dojoxManager,"onDrop")); |
156 |
this._draggedNode.style.display=""; |
157 |
this._dojoxManager.onDrop(this._draggedNode); |
158 |
dojo.unsubscribe(this.cancelHandler);
|
159 |
dojo.unsubscribe(this.dropHandler);
|
160 |
if(dojox.mdnd.adapter._dndFromDojo){
|
161 |
dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); |
162 |
} |
163 |
}); |
164 |
this.dropHandler=dojo.subscribe("/dnd/drop/before",this,function(_27){ |
165 |
dojo.unsubscribe(this.cancelHandler);
|
166 |
dojo.unsubscribe(this.dropHandler);
|
167 |
this.onDrop();
|
168 |
}); |
169 |
}else{
|
170 |
this.accept=this.isAccepted(this._dojoxManager._dragItem.item.node,this._currentDojoArea); |
171 |
if(this.accept){ |
172 |
dojo.disconnect(this._dojoxManager._dragItem.handlers.pop());
|
173 |
dojo.disconnect(this._dojoxManager._dragItem.handlers.pop());
|
174 |
this._dojoxManager._dropIndicator.node.style.display="none"; |
175 |
if(!this._moveUpHandler){ |
176 |
this._moveUpHandler=dojo.connect(dojo.doc,"onmouseup",this,"onDrop"); |
177 |
} |
178 |
} |
179 |
} |
180 |
dojo.publish("/dojox/mdnd/adapter/dndToDojo/over",[this._currentDojoArea.node,this._currentDojoArea.type,this._draggedNode,this.accept]); |
181 |
},onDragExit:function(e){ |
182 |
if(this._oldDojoArea.dojo){ |
183 |
dojo.unsubscribe(this.cancelHandler);
|
184 |
dojo.unsubscribe(this.dropHandler);
|
185 |
var _28=this._dojoxManager._dragItem.item; |
186 |
this._dojoxManager._dragItem.item.events.push(dojo.connect(_28.node.ownerDocument,"onmousemove",_28,"onMove")); |
187 |
dojo.body().appendChild(this._dojoxManager._cover);
|
188 |
dojo.body().appendChild(this._dojoxManager._cover2);
|
189 |
this._dojoxManager._cover.appendChild(_28.node);
|
190 |
var _29=_28.node.style;
|
191 |
_29.position="absolute";
|
192 |
_29.left=(_28.offsetDrag.l+e.pageX)+"px";
|
193 |
_29.top=(_28.offsetDrag.t+e.pageX)+"px";
|
194 |
_29.display="";
|
195 |
this._lazyManager.cancelDrag();
|
196 |
if(dojox.mdnd.adapter._dndFromDojo){
|
197 |
dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); |
198 |
} |
199 |
if(this._dojoxManager._dropIndicator.node.style.display=="none"){ |
200 |
this._dojoxManager._dropIndicator.node.style.display=""; |
201 |
} |
202 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDrag",this._dojoxManager,"onDrag")); |
203 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDragEnd",this._dojoxManager,"onDrop")); |
204 |
this._dojoxManager._dragItem.item.onMove(e);
|
205 |
}else{
|
206 |
if(this.accept){ |
207 |
if(this._moveUpHandler){ |
208 |
dojo.disconnect(this._moveUpHandler);
|
209 |
this._moveUpHandler=null; |
210 |
} |
211 |
if(this._dojoxManager._dropIndicator.node.style.display=="none"){ |
212 |
this._dojoxManager._dropIndicator.node.style.display=""; |
213 |
} |
214 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDrag",this._dojoxManager,"onDrag")); |
215 |
this._dojoxManager._dragItem.handlers.push(dojo.connect(this._dojoxManager._dragItem.item,"onDragEnd",this._dojoxManager,"onDrop")); |
216 |
this._dojoxManager._dragItem.item.onMove(e);
|
217 |
} |
218 |
} |
219 |
dojo.publish("/dojox/mdnd/adapter/dndToDojo/out",[this._oldDojoArea.node,this._oldDojoArea.type,this._draggedNode,this.accept]); |
220 |
},onDrop:function(e){ |
221 |
if(this._currentDojoArea.dojo){ |
222 |
if(dojox.mdnd.adapter._dndFromDojo){
|
223 |
dojox.mdnd.adapter._dndFromDojo.subscribeDnd(); |
224 |
} |
225 |
} |
226 |
if(this._dojoxManager._dropIndicator.node.style.display=="none"){ |
227 |
this._dojoxManager._dropIndicator.node.style.display=""; |
228 |
} |
229 |
if(this._dojoxManager._cover.parentNode&&this._dojoxManager._cover.parentNode.nodeType==1){ |
230 |
dojo.body().removeChild(this._dojoxManager._cover);
|
231 |
dojo.body().removeChild(this._dojoxManager._cover2);
|
232 |
} |
233 |
if(this._draggedNode.parentNode==this._dojoxManager._cover){ |
234 |
this._dojoxManager._cover.removeChild(this._draggedNode); |
235 |
} |
236 |
dojo.disconnect(this._moveHandler);
|
237 |
dojo.disconnect(this._moveUpHandler);
|
238 |
this._moveHandler=this._moveUpHandler=null; |
239 |
dojo.publish("/dojox/mdnd/adapter/dndToDojo/drop",[this._draggedNode,this._currentDojoArea.node,this._currentDojoArea.type]); |
240 |
dojo.removeClass(this._draggedNode,"dragNode"); |
241 |
var _2a=this._draggedNode.style; |
242 |
_2a.position="relative";
|
243 |
_2a.left="0";
|
244 |
_2a.top="0";
|
245 |
_2a.width="auto";
|
246 |
dojo.forEach(this._dojoxManager._dragItem.handlers,dojo.disconnect);
|
247 |
this._dojoxManager._deleteMoveableItem(this._dojoxManager._dragItem); |
248 |
this._draggedNode=null; |
249 |
this._currentDojoArea=null; |
250 |
this._dojoxManager._resetAfterDrop();
|
251 |
}}); |
252 |
dojox.mdnd.adapter._dndToDojo=null;
|
253 |
dojox.mdnd.adapter.dndToDojo=function(){ |
254 |
if(!dojox.mdnd.adapter._dndToDojo){
|
255 |
dojox.mdnd.adapter._dndToDojo=new dojox.mdnd.adapter.DndToDojo();
|
256 |
} |
257 |
return dojox.mdnd.adapter._dndToDojo;
|
258 |
}; |
259 |
} |