root / trunk / web / dojo / dojox / mdnd / adapter / DndFromDojo.js @ 13
History | View | Annotate | Download (5.37 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
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.DndFromDojo"]){ |
||
9 | dojo._hasResource["dojox.mdnd.adapter.DndFromDojo"]=true; |
||
10 | dojo.provide("dojox.mdnd.adapter.DndFromDojo");
|
||
11 | dojo.require("dojox.mdnd.AreaManager");
|
||
12 | dojo.require("dojo.dnd.Manager");
|
||
13 | dojo.declare("dojox.mdnd.adapter.DndFromDojo",null,{dropIndicatorSize:{"w":0,"h":50},dropIndicatorSize:{"w":0,"h":50},_areaManager:null,_dojoManager:null,_currentArea:null,_oldArea:null,_moveHandler:null,_subscribeHandler:null,constructor:function(){ |
||
14 | this._areaManager=dojox.mdnd.areaManager();
|
||
15 | this._dojoManager=dojo.dnd.manager();
|
||
16 | this._currentArea=null; |
||
17 | this._moveHandler=null; |
||
18 | this.subscribeDnd();
|
||
19 | },subscribeDnd:function(){ |
||
20 | this._subscribeHandler=[dojo.subscribe("/dnd/start",this,"onDragStart"),dojo.subscribe("/dnd/drop/before",this,"onDrop"),dojo.subscribe("/dnd/cancel",this,"onDropCancel"),dojo.subscribe("/dnd/source/over",this,"onDndSource")]; |
||
21 | },unsubscribeDnd:function(){ |
||
22 | dojo.forEach(this._subscribeHandler,dojo.unsubscribe);
|
||
23 | },_getHoverArea:function(_1){ |
||
24 | var x=_1.x;
|
||
25 | var y=_1.y;
|
||
26 | this._oldArea=this._currentArea; |
||
27 | this._currentArea=null; |
||
28 | var _2=this._areaManager._areaList; |
||
29 | for(var i=0;i<_2.length;i++){ |
||
30 | var _3=_2[i];
|
||
31 | var _4=_3.coords.x;
|
||
32 | var _5=_4+_3.node.offsetWidth;
|
||
33 | var _6=_3.coords.y;
|
||
34 | var _7=_6+_3.node.offsetHeight;
|
||
35 | if(_4<=x&&x<=_5&&_6<=y&&y<=_7){
|
||
36 | this._areaManager._oldIndexArea=this._areaManager._currentIndexArea; |
||
37 | this._areaManager._currentIndexArea=i;
|
||
38 | this._currentArea=_3.node;
|
||
39 | break;
|
||
40 | } |
||
41 | } |
||
42 | if(this._currentArea!=this._oldArea){ |
||
43 | if(this._currentArea==null){ |
||
44 | this.onDragExit();
|
||
45 | }else{
|
||
46 | if(this._oldArea==null){ |
||
47 | this.onDragEnter();
|
||
48 | }else{
|
||
49 | this.onDragExit();
|
||
50 | this.onDragEnter();
|
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | },onDragStart:function(_8,_9,_a){ |
||
55 | this._dragNode=_9[0]; |
||
56 | this._copy=_a;
|
||
57 | this._source=_8;
|
||
58 | this._outSourceHandler=dojo.connect(this._dojoManager,"outSource",this,function(){ |
||
59 | if(this._moveHandler==null){ |
||
60 | this._moveHandler=dojo.connect(dojo.doc,"mousemove",this,"onMouseMove"); |
||
61 | } |
||
62 | }); |
||
63 | },onMouseMove:function(e){ |
||
64 | var _b={"x":e.pageX,"y":e.pageY}; |
||
65 | this._getHoverArea(_b);
|
||
66 | if(this._currentArea&&this._areaManager._accept){ |
||
67 | if(this._areaManager._dropIndicator.node.style.visibility=="hidden"){ |
||
68 | this._areaManager._dropIndicator.node.style.visibility=""; |
||
69 | dojo.addClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
70 | } |
||
71 | this._areaManager.placeDropIndicator(_b,this.dropIndicatorSize); |
||
72 | } |
||
73 | },onDragEnter:function(){ |
||
74 | var _c=this._dragNode.getAttribute("dndType"); |
||
75 | var _d=(_c)?_c.split(/\s*,\s*/):["text"]; |
||
76 | this._areaManager._isAccepted(_d,this._areaManager._areaList[this._areaManager._currentIndexArea].accept); |
||
77 | if(this._dojoManager.avatar){ |
||
78 | if(this._areaManager._accept){ |
||
79 | dojo.addClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
80 | }else{
|
||
81 | dojo.removeClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
82 | } |
||
83 | } |
||
84 | },onDragExit:function(){ |
||
85 | this._areaManager._accept=false; |
||
86 | if(this._dojoManager.avatar){ |
||
87 | dojo.removeClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
88 | } |
||
89 | if(this._currentArea==null){ |
||
90 | this._areaManager._dropMode.refreshItems(this._areaManager._areaList[this._areaManager._oldIndexArea],this._areaManager._oldDropIndex,this.dropIndicatorSize,false); |
||
91 | this._areaManager._resetAfterDrop();
|
||
92 | }else{
|
||
93 | this._areaManager._dropIndicator.remove();
|
||
94 | } |
||
95 | },isAccepted:function(_e,_f){ |
||
96 | var _10=(_e.getAttribute("dndType"))?_e.getAttribute("dndType"):"text"; |
||
97 | if(_10&&_10 in _f){ |
||
98 | return true; |
||
99 | }else{
|
||
100 | return false; |
||
101 | } |
||
102 | },onDndSource:function(_11){ |
||
103 | if(this._currentArea==null){ |
||
104 | return;
|
||
105 | } |
||
106 | if(_11){
|
||
107 | var _12=false; |
||
108 | if(this._dojoManager.target==_11){ |
||
109 | _12=true;
|
||
110 | }else{
|
||
111 | _12=this.isAccepted(this._dragNode,_11.accept); |
||
112 | } |
||
113 | if(_12){
|
||
114 | dojo.disconnect(this._moveHandler);
|
||
115 | this._currentArea=this._moveHandler=null; |
||
116 | var _13=this._areaManager._dropIndicator.node; |
||
117 | if(_13&&_13.parentNode!==null&&_13.parentNode.nodeType==1){ |
||
118 | _13.style.visibility="hidden";
|
||
119 | } |
||
120 | }else{
|
||
121 | this._resetAvatar();
|
||
122 | } |
||
123 | }else{
|
||
124 | if(!this._moveHandler){ |
||
125 | this._moveHandler=dojo.connect(dojo.doc,"mousemove",this,"onMouseMove"); |
||
126 | } |
||
127 | this._resetAvatar();
|
||
128 | } |
||
129 | },_resetAvatar:function(){ |
||
130 | if(this._dojoManager.avatar){ |
||
131 | if(this._areaManager._accept){ |
||
132 | dojo.addClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
133 | }else{
|
||
134 | dojo.removeClass(this._dojoManager.avatar.node,"dojoDndAvatarCanDrop"); |
||
135 | } |
||
136 | } |
||
137 | },onDropCancel:function(){ |
||
138 | if(this._currentArea==null){ |
||
139 | this._areaManager._resetAfterDrop();
|
||
140 | dojo.disconnect(this._moveHandler);
|
||
141 | dojo.disconnect(this._outSourceHandler);
|
||
142 | this._currentArea=this._moveHandler=this._outSourceHandler=null; |
||
143 | }else{
|
||
144 | if(this._areaManager._accept){ |
||
145 | this.onDrop(this._source,[this._dragNode],this._copy,this._currentArea); |
||
146 | }else{
|
||
147 | this._currentArea=null; |
||
148 | dojo.disconnect(this._outSourceHandler);
|
||
149 | dojo.disconnect(this._moveHandler);
|
||
150 | this._moveHandler=this._outSourceHandler=null; |
||
151 | } |
||
152 | } |
||
153 | },onDrop:function(_14,_15,_16){ |
||
154 | dojo.disconnect(this._moveHandler);
|
||
155 | dojo.disconnect(this._outSourceHandler);
|
||
156 | this._moveHandler=this._outSourceHandler=null; |
||
157 | if(this._currentArea){ |
||
158 | var _17=this._areaManager._currentDropIndex; |
||
159 | dojo.publish("/dnd/drop/after",[_14,_15,_16,this._currentArea,_17]); |
||
160 | this._currentArea=null; |
||
161 | } |
||
162 | if(this._areaManager._dropIndicator.node.style.visibility=="hidden"){ |
||
163 | this._areaManager._dropIndicator.node.style.visibility=""; |
||
164 | } |
||
165 | this._areaManager._resetAfterDrop();
|
||
166 | }}); |
||
167 | dojox.mdnd.adapter._dndFromDojo=null;
|
||
168 | (function(){
|
||
169 | dojox.mdnd.adapter._dndFromDojo=new dojox.mdnd.adapter.DndFromDojo();
|
||
170 | }()); |
||
171 | } |