4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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'>/**
19 </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.
85 Ext.define('Ext.dd.DropZone', {
86 extend: 'Ext.dd.DropTarget',
87 requires: ['Ext.dd.Registry'],
89 <span id='Ext-dd-DropZone-method-getTargetFromEvent'> /**
90 </span> * Returns a custom data object associated with the DOM node that is the target of the event. By default
91 * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
92 * provide your own custom lookup.
93 * @param {Event} e The event
94 * @return {Object} data The custom data
96 getTargetFromEvent : function(e){
97 return Ext.dd.Registry.getTargetFromEvent(e);
100 <span id='Ext-dd-DropZone-method-onNodeEnter'> /**
101 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
102 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
103 * This method has no default implementation and should be overridden to provide
104 * node-specific processing if necessary.
105 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
106 * {@link #getTargetFromEvent} for this node)
107 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
108 * @param {Event} e The event
109 * @param {Object} data An object containing arbitrary data supplied by the drag source
111 onNodeEnter : function(n, dd, e, data){
115 <span id='Ext-dd-DropZone-method-onNodeOver'> /**
116 </span> * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
117 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
118 * The default implementation returns this.dropNotAllowed, so it should be
119 * overridden to provide the proper feedback.
120 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
121 * {@link #getTargetFromEvent} for this node)
122 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
123 * @param {Event} e The event
124 * @param {Object} data An object containing arbitrary data supplied by the drag source
125 * @return {String} status The CSS class that communicates the drop status back to the source so that the
126 * underlying {@link Ext.dd.StatusProxy} can be updated
128 onNodeOver : function(n, dd, e, data){
129 return this.dropAllowed;
132 <span id='Ext-dd-DropZone-method-onNodeOut'> /**
133 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
134 * the drop node without dropping. This method has no default implementation and should be overridden to provide
135 * node-specific processing if necessary.
136 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
137 * {@link #getTargetFromEvent} for this node)
138 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
139 * @param {Event} e The event
140 * @param {Object} data An object containing arbitrary data supplied by the drag source
142 onNodeOut : function(n, dd, e, data){
146 <span id='Ext-dd-DropZone-method-onNodeDrop'> /**
147 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
148 * the drop node. The default implementation returns false, so it should be overridden to provide the
149 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
150 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
151 * {@link #getTargetFromEvent} for this node)
152 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
153 * @param {Event} e The event
154 * @param {Object} data An object containing arbitrary data supplied by the drag source
155 * @return {Boolean} True if the drop was valid, else false
157 onNodeDrop : function(n, dd, e, data){
161 <span id='Ext-dd-DropZone-method-onContainerOver'> /**
162 </span> * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
163 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
164 * it should be overridden to provide the proper feedback if necessary.
165 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
166 * @param {Event} e The event
167 * @param {Object} data An object containing arbitrary data supplied by the drag source
168 * @return {String} status The CSS class that communicates the drop status back to the source so that the
169 * underlying {@link Ext.dd.StatusProxy} can be updated
171 onContainerOver : function(dd, e, data){
172 return this.dropNotAllowed;
175 <span id='Ext-dd-DropZone-method-onContainerDrop'> /**
176 </span> * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
177 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
178 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
179 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
180 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
181 * @param {Event} e The event
182 * @param {Object} data An object containing arbitrary data supplied by the drag source
183 * @return {Boolean} True if the drop was valid, else false
185 onContainerDrop : function(dd, e, data){
189 <span id='Ext-dd-DropZone-method-notifyEnter'> /**
190 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
191 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
192 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
193 * you should override this method and provide a custom implementation.
194 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
195 * @param {Event} e The event
196 * @param {Object} data An object containing arbitrary data supplied by the drag source
197 * @return {String} status The CSS class that communicates the drop status back to the source so that the
198 * underlying {@link Ext.dd.StatusProxy} can be updated
200 notifyEnter : function(dd, e, data){
201 return this.dropNotAllowed;
204 <span id='Ext-dd-DropZone-method-notifyOver'> /**
205 </span> * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
206 * This method will be called on every mouse movement while the drag source is over the drop zone.
207 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
208 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
209 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
210 * registered node, it will call {@link #onContainerOver}.
211 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
212 * @param {Event} e The event
213 * @param {Object} data An object containing arbitrary data supplied by the drag source
214 * @return {String} status The CSS class that communicates the drop status back to the source so that the
215 * underlying {@link Ext.dd.StatusProxy} can be updated
217 notifyOver : function(dd, e, data){
218 var n = this.getTargetFromEvent(e);
219 if(!n) { // not over valid drop target
220 if(this.lastOverNode){
221 this.onNodeOut(this.lastOverNode, dd, e, data);
222 this.lastOverNode = null;
224 return this.onContainerOver(dd, e, data);
226 if(this.lastOverNode != n){
227 if(this.lastOverNode){
228 this.onNodeOut(this.lastOverNode, dd, e, data);
230 this.onNodeEnter(n, dd, e, data);
231 this.lastOverNode = n;
233 return this.onNodeOver(n, dd, e, data);
236 <span id='Ext-dd-DropZone-method-notifyOut'> /**
237 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
238 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
239 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
240 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
241 * @param {Event} e The event
242 * @param {Object} data An object containing arbitrary data supplied by the drag zone
244 notifyOut : function(dd, e, data){
245 if(this.lastOverNode){
246 this.onNodeOut(this.lastOverNode, dd, e, data);
247 this.lastOverNode = null;
251 <span id='Ext-dd-DropZone-method-notifyDrop'> /**
252 </span> * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
253 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
254 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
255 * otherwise it will call {@link #onContainerDrop}.
256 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
257 * @param {Event} e The event
258 * @param {Object} data An object containing arbitrary data supplied by the drag source
259 * @return {Boolean} False if the drop was invalid.
261 notifyDrop : function(dd, e, data){
262 if(this.lastOverNode){
263 this.onNodeOut(this.lastOverNode, dd, e, data);
264 this.lastOverNode = null;
266 var n = this.getTargetFromEvent(e);
268 this.onNodeDrop(n, dd, e, data) :
269 this.onContainerDrop(dd, e, data);
273 triggerCacheRefresh : function() {
274 Ext.dd.DDM.refreshCache(this.groups);