1 | define(["dojo/_base/kernel", |
---|
2 | "dojo/_base/declare", |
---|
3 | "dojo/_base/lang", |
---|
4 | "dojo/_base/connect", |
---|
5 | "dojo/_base/array", |
---|
6 | "dojo/dom-class", |
---|
7 | "dojo/dnd/common", |
---|
8 | "dojo/dnd/Selector", |
---|
9 | "dojo/dnd/Manager" |
---|
10 | ],function(dojo, declare, lang, connect, array, domClass, dnd, Selector, Manager){ |
---|
11 | return declare( |
---|
12 | "dojox.mdnd.PureSource", |
---|
13 | Selector, |
---|
14 | { |
---|
15 | // summary: |
---|
16 | // A Source Object, which can be used only as a DnD source. |
---|
17 | // A Source can contained several dnd items. |
---|
18 | // A dnd item is not a source. |
---|
19 | |
---|
20 | horizontal: false, |
---|
21 | copyOnly: true, |
---|
22 | skipForm: false, |
---|
23 | withHandles: false, |
---|
24 | isSource: true, |
---|
25 | targetState: "Disabled", |
---|
26 | generateText: true, |
---|
27 | |
---|
28 | constructor: function(/*DOMNode|String*/node, /*dojo.dnd.__SourceArgs?*/params){ |
---|
29 | // summary: |
---|
30 | // Initialize a new PureSource. |
---|
31 | // node: |
---|
32 | // Node or node's id to build the source on. |
---|
33 | // params: |
---|
34 | // Any property of this class may be configured via the params |
---|
35 | // object which is mixed-in to the 'dojo.dnd.Source' instance. |
---|
36 | |
---|
37 | //console.log('dojox.mdnd.PureSource ::: constructor'); |
---|
38 | lang.mixin(this, lang.mixin({}, params)); |
---|
39 | var type = this.accept; |
---|
40 | |
---|
41 | // class-specific variables |
---|
42 | this.isDragging = false; |
---|
43 | this.mouseDown = false; |
---|
44 | |
---|
45 | // states |
---|
46 | this.sourceState = ""; |
---|
47 | domClass.add(this.node, "dojoDndSource"); |
---|
48 | if(this.horizontal){ |
---|
49 | domClass.add(this.node, "dojoDndHorizontal"); |
---|
50 | } |
---|
51 | // set up events |
---|
52 | this.topics = [ |
---|
53 | connect.subscribe("/dnd/cancel", this, "onDndCancel"), |
---|
54 | connect.subscribe("/dnd/drop", this, "onDndCancel") |
---|
55 | ]; |
---|
56 | }, |
---|
57 | |
---|
58 | onDndCancel: function(){ |
---|
59 | // summary: |
---|
60 | // Topic event processor for /dnd/cancel, called to cancel the Dnd |
---|
61 | // operation. |
---|
62 | // tags: |
---|
63 | // callback |
---|
64 | |
---|
65 | //console.log('dojox.mdnd.PureSource ::: onDndCancel'); |
---|
66 | this.isDragging = false; |
---|
67 | this.mouseDown = false; |
---|
68 | delete this.mouseButton; |
---|
69 | }, |
---|
70 | |
---|
71 | copyState: function(/*Boolean*/keyPressed){ |
---|
72 | // summary: |
---|
73 | // Returns true, if we need to copy items, false to move. |
---|
74 | // It is separated to be overwritten dynamically, if needed. |
---|
75 | // keyPressed: |
---|
76 | // The "copy" was pressed. |
---|
77 | // returns: |
---|
78 | // True, if we need to copy items, false to move. |
---|
79 | |
---|
80 | //console.log('dojox.mdnd.PureSource ::: copyState'); |
---|
81 | return this.copyOnly || keyPressed; // Boolean |
---|
82 | }, |
---|
83 | |
---|
84 | destroy: function(){ |
---|
85 | // summary: |
---|
86 | // Prepares the object to be garbage-collected. |
---|
87 | |
---|
88 | //console.log('dojox.mdnd.PureSource ::: destroy'); |
---|
89 | dojox.mdnd.PureSource.superclass.destroy.call(this); |
---|
90 | array.forEach(this.topics, connect.unsubscribe); |
---|
91 | this.targetAnchor = null; |
---|
92 | }, |
---|
93 | |
---|
94 | markupFactory: function(/*Object*/params, /*DomNode*/node){ |
---|
95 | // summary: |
---|
96 | // Markup methods. |
---|
97 | // params: |
---|
98 | // ??? |
---|
99 | // node: |
---|
100 | // ??? |
---|
101 | // returns: |
---|
102 | // New dojox.mdnd.PureSource instance. |
---|
103 | |
---|
104 | //console.log('dojox.mdnd.PureSource ::: markupFactory'); |
---|
105 | params._skipStartup = true; |
---|
106 | return new dojox.mdnd.PureSource(node, params); |
---|
107 | }, |
---|
108 | |
---|
109 | onMouseMove: function(/*Event*/e){ |
---|
110 | // summary: |
---|
111 | // Event processor for onmousemove. |
---|
112 | // e: |
---|
113 | // Mouse event. |
---|
114 | |
---|
115 | //console.log('dojox.mdnd.PureSource ::: onMouseMove'); |
---|
116 | if(this.isDragging){ |
---|
117 | return; |
---|
118 | } |
---|
119 | dojox.mdnd.PureSource.superclass.onMouseMove.call(this, e); |
---|
120 | var m = Manager.manager(); |
---|
121 | if(this.mouseDown && !this.isDragging && this.isSource){ |
---|
122 | var nodes = this.getSelectedNodes(); |
---|
123 | if(nodes.length){ |
---|
124 | m.startDrag(this, nodes, this.copyState(connect.isCopyKey(e))); |
---|
125 | this.isDragging = true; |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | }, |
---|
130 | |
---|
131 | onMouseDown: function(/*Event*/e){ |
---|
132 | // summary: |
---|
133 | // Event processor for onmousedown. |
---|
134 | // e: |
---|
135 | // Mouse event. |
---|
136 | // tags: |
---|
137 | // callback |
---|
138 | |
---|
139 | //console.log('dojox.mdnd.PureSource ::: onMouseDown'); |
---|
140 | if(this._legalMouseDown(e) && (!this.skipForm || !dnd.isFormElement(e))){ |
---|
141 | this.mouseDown = true; |
---|
142 | this.mouseButton = e.button; |
---|
143 | dojox.mdnd.PureSource.superclass.onMouseDown.call(this, e); |
---|
144 | } |
---|
145 | }, |
---|
146 | |
---|
147 | onMouseUp: function(/*Event*/e){ |
---|
148 | // summary: |
---|
149 | // Event processor for onmouseup. |
---|
150 | // e: |
---|
151 | // Mouse event |
---|
152 | // tags: |
---|
153 | // callback |
---|
154 | |
---|
155 | //console.log('.dnd.PureSource ::: onMouseUp'); |
---|
156 | if(this.mouseDown){ |
---|
157 | this.mouseDown = false; |
---|
158 | dojox.mdnd.PureSource.superclass.onMouseUp.call(this, e); |
---|
159 | } |
---|
160 | }, |
---|
161 | |
---|
162 | onOverEvent: function(){ |
---|
163 | // summary: |
---|
164 | // Called once, when mouse is over our container. |
---|
165 | // tags: |
---|
166 | // callback |
---|
167 | |
---|
168 | //console.log('dojox.mdnd.PureSource ::: onOverEvent'); |
---|
169 | dojox.mdnd.PureSource.superclass.onOverEvent.call(this); |
---|
170 | Manager.manager().overSource(this); |
---|
171 | }, |
---|
172 | |
---|
173 | onOutEvent: function(){ |
---|
174 | // summary: |
---|
175 | // Called once, when mouse is out our container. |
---|
176 | // tags: |
---|
177 | // callback |
---|
178 | |
---|
179 | //console.log('dojox.mdnd.PureSource ::: onOutEvent'); |
---|
180 | dojox.mdnd.PureSource.superclass.onOutEvent.call(this); |
---|
181 | Manager.manager().outSource(this); |
---|
182 | }, |
---|
183 | |
---|
184 | _markDndStatus: function(/*Boolean*/copy){ |
---|
185 | // summary: |
---|
186 | // Changes source's state based on "copy" status. |
---|
187 | // copy: |
---|
188 | // Copy status. |
---|
189 | // tags: |
---|
190 | // protected |
---|
191 | |
---|
192 | //console.log('dojox.mdnd.PureSource ::: _markDndStatus'); |
---|
193 | this._changeState("Source", copy ? "Copied" : "Moved"); |
---|
194 | }, |
---|
195 | |
---|
196 | _legalMouseDown: function(/*Event*/e){ |
---|
197 | // summary: |
---|
198 | // Checks if user clicked on "approved" items. |
---|
199 | // e: |
---|
200 | // Mouse event. |
---|
201 | // returns: |
---|
202 | // True if user clicked on "approved" items. |
---|
203 | // tags: |
---|
204 | // protected |
---|
205 | |
---|
206 | //console.log('dojox.mdnd.PureSource ::: _legalMouseDown'); |
---|
207 | if(!this.withHandles){ return true; } |
---|
208 | for(var node = e.target; node && !domClass.contains(node, "dojoDndItem"); node = node.parentNode){ |
---|
209 | if(domClass.contains(node, "dojoDndHandle")){ return true; } |
---|
210 | } |
---|
211 | return false; // Boolean |
---|
212 | } |
---|
213 | }); |
---|
214 | }); |
---|