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