3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.1
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.dd.DragSource"></div>/**
16 * @class Ext.dd.DragSource
17 * @extends Ext.dd.DDProxy
18 * A simple class that provides the basic implementation needed to make any element draggable.
20 * @param {Mixed} el The container element
21 * @param {Object} config
23 Ext.dd.DragSource = function(el, config){
24 this.el = Ext.get(el);
29 Ext.apply(this, config);
32 this.proxy = new Ext.dd.StatusProxy();
34 Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
35 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
37 this.dragging = false;
40 Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
41 <div id="cfg-Ext.dd.DragSource-ddGroup"></div>/**
42 * @cfg {String} ddGroup
43 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
44 * interact with other drag drop objects in the same group (defaults to undefined).
46 <div id="cfg-Ext.dd.DragSource-dropAllowed"></div>/**
47 * @cfg {String} dropAllowed
48 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
50 dropAllowed : "x-dd-drop-ok",
51 <div id="cfg-Ext.dd.DragSource-dropNotAllowed"></div>/**
52 * @cfg {String} dropNotAllowed
53 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
55 dropNotAllowed : "x-dd-drop-nodrop",
57 <div id="method-Ext.dd.DragSource-getDragData"></div>/**
58 * Returns the data object associated with this drag source
59 * @return {Object} data An object containing arbitrary data
61 getDragData : function(e){
66 onDragEnter : function(e, id){
67 var target = Ext.dd.DragDropMgr.getDDById(id);
68 this.cachedTarget = target;
69 if(this.beforeDragEnter(target, e, id) !== false){
70 if(target.isNotifyTarget){
71 var status = target.notifyEnter(this, e, this.dragData);
72 this.proxy.setStatus(status);
74 this.proxy.setStatus(this.dropAllowed);
77 if(this.afterDragEnter){
78 <div id="method-Ext.dd.DragSource-afterDragEnter"></div>/**
79 * An empty function by default, but provided so that you can perform a custom action
80 * when the dragged item enters the drop target by providing an implementation.
81 * @param {Ext.dd.DragDrop} target The drop target
82 * @param {Event} e The event object
83 * @param {String} id The id of the dragged element
84 * @method afterDragEnter
86 this.afterDragEnter(target, e, id);
91 <div id="method-Ext.dd.DragSource-beforeDragEnter"></div>/**
92 * An empty function by default, but provided so that you can perform a custom action
93 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
94 * @param {Ext.dd.DragDrop} target The drop target
95 * @param {Event} e The event object
96 * @param {String} id The id of the dragged element
97 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
99 beforeDragEnter : function(target, e, id){
104 alignElWithMouse: function() {
105 Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
110 onDragOver : function(e, id){
111 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
112 if(this.beforeDragOver(target, e, id) !== false){
113 if(target.isNotifyTarget){
114 var status = target.notifyOver(this, e, this.dragData);
115 this.proxy.setStatus(status);
118 if(this.afterDragOver){
119 <div id="method-Ext.dd.DragSource-afterDragOver"></div>/**
120 * An empty function by default, but provided so that you can perform a custom action
121 * while the dragged item is over the drop target by providing an implementation.
122 * @param {Ext.dd.DragDrop} target The drop target
123 * @param {Event} e The event object
124 * @param {String} id The id of the dragged element
125 * @method afterDragOver
127 this.afterDragOver(target, e, id);
132 <div id="method-Ext.dd.DragSource-beforeDragOver"></div>/**
133 * An empty function by default, but provided so that you can perform a custom action
134 * while the dragged item is over the drop target and optionally cancel the onDragOver.
135 * @param {Ext.dd.DragDrop} target The drop target
136 * @param {Event} e The event object
137 * @param {String} id The id of the dragged element
138 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
140 beforeDragOver : function(target, e, id){
145 onDragOut : function(e, id){
146 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
147 if(this.beforeDragOut(target, e, id) !== false){
148 if(target.isNotifyTarget){
149 target.notifyOut(this, e, this.dragData);
152 if(this.afterDragOut){
153 <div id="method-Ext.dd.DragSource-afterDragOut"></div>/**
154 * An empty function by default, but provided so that you can perform a custom action
155 * after the dragged item is dragged out of the target without dropping.
156 * @param {Ext.dd.DragDrop} target The drop target
157 * @param {Event} e The event object
158 * @param {String} id The id of the dragged element
159 * @method afterDragOut
161 this.afterDragOut(target, e, id);
164 this.cachedTarget = null;
167 <div id="method-Ext.dd.DragSource-beforeDragOut"></div>/**
168 * An empty function by default, but provided so that you can perform a custom action before the dragged
169 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
170 * @param {Ext.dd.DragDrop} target The drop target
171 * @param {Event} e The event object
172 * @param {String} id The id of the dragged element
173 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
175 beforeDragOut : function(target, e, id){
180 onDragDrop : function(e, id){
181 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
182 if(this.beforeDragDrop(target, e, id) !== false){
183 if(target.isNotifyTarget){
184 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
185 this.onValidDrop(target, e, id);
187 this.onInvalidDrop(target, e, id);
190 this.onValidDrop(target, e, id);
193 if(this.afterDragDrop){
194 <div id="method-Ext.dd.DragSource-afterDragDrop"></div>/**
195 * An empty function by default, but provided so that you can perform a custom action
196 * after a valid drag drop has occurred by providing an implementation.
197 * @param {Ext.dd.DragDrop} target The drop target
198 * @param {Event} e The event object
199 * @param {String} id The id of the dropped element
200 * @method afterDragDrop
202 this.afterDragDrop(target, e, id);
205 delete this.cachedTarget;
208 <div id="method-Ext.dd.DragSource-beforeDragDrop"></div>/**
209 * An empty function by default, but provided so that you can perform a custom action before the dragged
210 * item is dropped onto the target and optionally cancel the onDragDrop.
211 * @param {Ext.dd.DragDrop} target The drop target
212 * @param {Event} e The event object
213 * @param {String} id The id of the dragged element
214 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
216 beforeDragDrop : function(target, e, id){
221 onValidDrop : function(target, e, id){
223 if(this.afterValidDrop){
225 * An empty function by default, but provided so that you can perform a custom action
226 * after a valid drop has occurred by providing an implementation.
227 * @param {Object} target The target DD
228 * @param {Event} e The event object
229 * @param {String} id The id of the dropped element
230 * @method afterInvalidDrop
232 this.afterValidDrop(target, e, id);
237 getRepairXY : function(e, data){
238 return this.el.getXY();
242 onInvalidDrop : function(target, e, id){
243 this.beforeInvalidDrop(target, e, id);
244 if(this.cachedTarget){
245 if(this.cachedTarget.isNotifyTarget){
246 this.cachedTarget.notifyOut(this, e, this.dragData);
248 this.cacheTarget = null;
250 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
252 if(this.afterInvalidDrop){
253 <div id="method-Ext.dd.DragSource-afterInvalidDrop"></div>/**
254 * An empty function by default, but provided so that you can perform a custom action
255 * after an invalid drop has occurred by providing an implementation.
256 * @param {Event} e The event object
257 * @param {String} id The id of the dropped element
258 * @method afterInvalidDrop
260 this.afterInvalidDrop(e, id);
265 afterRepair : function(){
267 this.el.highlight(this.hlColor || "c3daf9");
269 this.dragging = false;
272 <div id="method-Ext.dd.DragSource-beforeInvalidDrop"></div>/**
273 * An empty function by default, but provided so that you can perform a custom action after an invalid
275 * @param {Ext.dd.DragDrop} target The drop target
276 * @param {Event} e The event object
277 * @param {String} id The id of the dragged element
278 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
280 beforeInvalidDrop : function(target, e, id){
285 handleMouseDown : function(e){
289 var data = this.getDragData(e);
290 if(data && this.onBeforeDrag(data, e) !== false){
291 this.dragData = data;
293 Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
297 <div id="method-Ext.dd.DragSource-onBeforeDrag"></div>/**
298 * An empty function by default, but provided so that you can perform a custom action before the initial
299 * drag event begins and optionally cancel it.
300 * @param {Object} data An object containing arbitrary data to be shared with drop targets
301 * @param {Event} e The event object
302 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
304 onBeforeDrag : function(data, e){
308 <div id="method-Ext.dd.DragSource-onStartDrag"></div>/**
309 * An empty function by default, but provided so that you can perform a custom action once the initial
310 * drag event has begun. The drag cannot be canceled from this function.
311 * @param {Number} x The x position of the click on the dragged object
312 * @param {Number} y The y position of the click on the dragged object
314 onStartDrag : Ext.emptyFn,
317 startDrag : function(x, y){
319 this.dragging = true;
320 this.proxy.update("");
321 this.onInitDrag(x, y);
326 onInitDrag : function(x, y){
327 var clone = this.el.dom.cloneNode(true);
328 clone.id = Ext.id(); // prevent duplicate ids
329 this.proxy.update(clone);
330 this.onStartDrag(x, y);
334 <div id="method-Ext.dd.DragSource-getProxy"></div>/**
335 * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
336 * @return {Ext.dd.StatusProxy} proxy The StatusProxy
338 getProxy : function(){
342 <div id="method-Ext.dd.DragSource-hideProxy"></div>/**
343 * Hides the drag source's {@link Ext.dd.StatusProxy}
345 hideProxy : function(){
347 this.proxy.reset(true);
348 this.dragging = false;
352 triggerCacheRefresh : function(){
353 Ext.dd.DDM.refreshCache(this.groups);
356 // private - override to prevent hiding
357 b4EndDrag: function(e) {
360 // private - override to prevent moving
361 endDrag : function(e){
362 this.onEndDrag(this.dragData, e);
366 onEndDrag : function(data, e){
369 // private - pin to cursor
370 autoOffset : function(x, y) {
371 this.setDelta(-12, -20);
375 Ext.dd.DragSource.superclass.destroy.call(this);
376 Ext.destroy(this.proxy);