4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-dd-DropZone-method-constructor'><span id='Ext-dd-DropZone'>/**
19 </span></span> * @class Ext.dd.DropZone
20 * @extends Ext.dd.DropTarget
22 This class provides a container DD instance that allows dropping on multiple child target nodes.
24 By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
25 However a simpler way to allow a DropZone to manage any number of target elements is to configure the
26 DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
27 mouse event to see if it has taken place within an element, or class of elements. This is easily done
28 by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
29 {@link Ext.DomQuery} selector.
31 Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
32 a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
33 {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
34 of these methods to provide application-specific behaviour for these events to update both
35 application state, and UI state.
37 For example to make a GridPanel a cooperating target with the example illustrated in
38 {@link Ext.dd.DragZone DragZone}, the following technique might be used:
40 myGridPanel.on('render', function() {
41 myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
43 // If the mouse is over a grid row, return that node. This is
44 // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
45 getTargetFromEvent: function(e) {
46 return e.getTarget(myGridPanel.getView().rowSelector);
49 // On entry into a target node, highlight that node.
50 onNodeEnter : function(target, dd, e, data){
51 Ext.fly(target).addCls('my-row-highlight-class');
54 // On exit from a target node, unhighlight that node.
55 onNodeOut : function(target, dd, e, data){
56 Ext.fly(target).removeCls('my-row-highlight-class');
59 // While over a target node, return the default drop allowed class which
60 // places a "tick" icon into the drag proxy.
61 onNodeOver : function(target, dd, e, data){
62 return Ext.dd.DropZone.prototype.dropAllowed;
65 // On node drop we can interrogate the target to find the underlying
66 // application object that is the real target of the dragged data.
67 // In this case, it is a Record in the GridPanel's Store.
68 // We can use the data set up by the DragZone's getDragData method to read
69 // any data we decided to attach in the DragZone's getDragData method.
70 onNodeDrop : function(target, dd, e, data){
71 var rowIndex = myGridPanel.getView().findRowIndex(target);
72 var r = myGridPanel.getStore().getAt(rowIndex);
73 Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
74 ' on Record id ' + r.id);
80 See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
81 cooperates with this DropZone.
84 * @param {Mixed} el The container element
85 * @param {Object} config
88 Ext.define('Ext.dd.DropZone', {
89 extend: 'Ext.dd.DropTarget',
90 requires: ['Ext.dd.Registry'],
92 <span id='Ext-dd-DropZone-method-getTargetFromEvent'> /**
93 </span> * Returns a custom data object associated with the DOM node that is the target of the event. By default
94 * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
95 * provide your own custom lookup.
96 * @param {Event} e The event
97 * @return {Object} data The custom data
99 getTargetFromEvent : function(e){
100 return Ext.dd.Registry.getTargetFromEvent(e);
103 <span id='Ext-dd-DropZone-method-onNodeEnter'> /**
104 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
105 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
106 * This method has no default implementation and should be overridden to provide
107 * node-specific processing if necessary.
108 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
109 * {@link #getTargetFromEvent} for this node)
110 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
111 * @param {Event} e The event
112 * @param {Object} data An object containing arbitrary data supplied by the drag source
114 onNodeEnter : function(n, dd, e, data){
118 <span id='Ext-dd-DropZone-method-onNodeOver'> /**
119 </span> * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
120 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
121 * The default implementation returns this.dropNotAllowed, so it should be
122 * overridden to provide the proper feedback.
123 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
124 * {@link #getTargetFromEvent} for this node)
125 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
126 * @param {Event} e The event
127 * @param {Object} data An object containing arbitrary data supplied by the drag source
128 * @return {String} status The CSS class that communicates the drop status back to the source so that the
129 * underlying {@link Ext.dd.StatusProxy} can be updated
131 onNodeOver : function(n, dd, e, data){
132 return this.dropAllowed;
135 <span id='Ext-dd-DropZone-method-onNodeOut'> /**
136 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
137 * the drop node without dropping. This method has no default implementation and should be overridden to provide
138 * node-specific processing if necessary.
139 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
140 * {@link #getTargetFromEvent} for this node)
141 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
142 * @param {Event} e The event
143 * @param {Object} data An object containing arbitrary data supplied by the drag source
145 onNodeOut : function(n, dd, e, data){
149 <span id='Ext-dd-DropZone-method-onNodeDrop'> /**
150 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
151 * the drop node. The default implementation returns false, so it should be overridden to provide the
152 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
153 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
154 * {@link #getTargetFromEvent} for this node)
155 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
156 * @param {Event} e The event
157 * @param {Object} data An object containing arbitrary data supplied by the drag source
158 * @return {Boolean} True if the drop was valid, else false
160 onNodeDrop : function(n, dd, e, data){
164 <span id='Ext-dd-DropZone-method-onContainerOver'> /**
165 </span> * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
166 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
167 * it should be overridden to provide the proper feedback if necessary.
168 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
169 * @param {Event} e The event
170 * @param {Object} data An object containing arbitrary data supplied by the drag source
171 * @return {String} status The CSS class that communicates the drop status back to the source so that the
172 * underlying {@link Ext.dd.StatusProxy} can be updated
174 onContainerOver : function(dd, e, data){
175 return this.dropNotAllowed;
178 <span id='Ext-dd-DropZone-method-onContainerDrop'> /**
179 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
180 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
181 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
182 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
183 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
184 * @param {Event} e The event
185 * @param {Object} data An object containing arbitrary data supplied by the drag source
186 * @return {Boolean} True if the drop was valid, else false
188 onContainerDrop : function(dd, e, data){
192 <span id='Ext-dd-DropZone-method-notifyEnter'> /**
193 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
194 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
195 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
196 * you should override this method and provide a custom implementation.
197 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
198 * @param {Event} e The event
199 * @param {Object} data An object containing arbitrary data supplied by the drag source
200 * @return {String} status The CSS class that communicates the drop status back to the source so that the
201 * underlying {@link Ext.dd.StatusProxy} can be updated
203 notifyEnter : function(dd, e, data){
204 return this.dropNotAllowed;
207 <span id='Ext-dd-DropZone-method-notifyOver'> /**
208 </span> * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
209 * This method will be called on every mouse movement while the drag source is over the drop zone.
210 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
211 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
212 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
213 * registered node, it will call {@link #onContainerOver}.
214 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
215 * @param {Event} e The event
216 * @param {Object} data An object containing arbitrary data supplied by the drag source
217 * @return {String} status The CSS class that communicates the drop status back to the source so that the
218 * underlying {@link Ext.dd.StatusProxy} can be updated
220 notifyOver : function(dd, e, data){
221 var n = this.getTargetFromEvent(e);
222 if(!n) { // not over valid drop target
223 if(this.lastOverNode){
224 this.onNodeOut(this.lastOverNode, dd, e, data);
225 this.lastOverNode = null;
227 return this.onContainerOver(dd, e, data);
229 if(this.lastOverNode != n){
230 if(this.lastOverNode){
231 this.onNodeOut(this.lastOverNode, dd, e, data);
233 this.onNodeEnter(n, dd, e, data);
234 this.lastOverNode = n;
236 return this.onNodeOver(n, dd, e, data);
239 <span id='Ext-dd-DropZone-method-notifyOut'> /**
240 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
241 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
242 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
243 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
244 * @param {Event} e The event
245 * @param {Object} data An object containing arbitrary data supplied by the drag zone
247 notifyOut : function(dd, e, data){
248 if(this.lastOverNode){
249 this.onNodeOut(this.lastOverNode, dd, e, data);
250 this.lastOverNode = null;
254 <span id='Ext-dd-DropZone-method-notifyDrop'> /**
255 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
256 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
257 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
258 * otherwise it will call {@link #onContainerDrop}.
259 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
260 * @param {Event} e The event
261 * @param {Object} data An object containing arbitrary data supplied by the drag source
262 * @return {Boolean} False if the drop was invalid.
264 notifyDrop : function(dd, e, data){
265 if(this.lastOverNode){
266 this.onNodeOut(this.lastOverNode, dd, e, data);
267 this.lastOverNode = null;
269 var n = this.getTargetFromEvent(e);
271 this.onNodeDrop(n, dd, e, data) :
272 this.onContainerDrop(dd, e, data);
276 triggerCacheRefresh : function() {
277 Ext.dd.DDM.refreshCache(this.groups);