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-DragSource'>/**
19 </span> * @class Ext.dd.DragSource
20 * @extends Ext.dd.DDProxy
21 * A simple class that provides the basic implementation needed to make any element draggable.
23 Ext.define('Ext.dd.DragSource', {
24 extend: 'Ext.dd.DDProxy',
27 'Ext.dd.DragDropManager'
30 <span id='Ext-dd-DragSource-cfg-ddGroup'> /**
31 </span> * @cfg {String} ddGroup
32 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
33 * interact with other drag drop objects in the same group.
36 <span id='Ext-dd-DragSource-cfg-dropAllowed'> /**
37 </span> * @cfg {String} [dropAllowed="x-dd-drop-ok"]
38 * The CSS class returned to the drag source when drop is allowed.
40 dropAllowed : Ext.baseCSSPrefix + 'dd-drop-ok',
41 <span id='Ext-dd-DragSource-cfg-dropNotAllowed'> /**
42 </span> * @cfg {String} [dropNotAllowed="x-dd-drop-nodrop"]
43 * The CSS class returned to the drag source when drop is not allowed.
45 dropNotAllowed : Ext.baseCSSPrefix + 'dd-drop-nodrop',
47 <span id='Ext-dd-DragSource-cfg-animRepair'> /**
48 </span> * @cfg {Boolean} animRepair
49 * If true, animates the proxy element back to the position of the handle element used to trigger the drag.
53 <span id='Ext-dd-DragSource-cfg-repairHighlightColor'> /**
54 </span> * @cfg {String} repairHighlightColor
55 * The color to use when visually highlighting the drag source in the afterRepair
56 * method after a failed drop (defaults to light blue). The color must be a 6 digit hex value, without
59 repairHighlightColor: 'c3daf9',
61 <span id='Ext-dd-DragSource-method-constructor'> /**
62 </span> * Creates new drag-source.
64 * @param {String/HTMLElement/Ext.Element} el The container element or ID of it.
65 * @param {Object} config (optional) Config object.
67 constructor: function(el, config) {
68 this.el = Ext.get(el);
73 Ext.apply(this, config);
76 this.proxy = Ext.create('Ext.dd.StatusProxy', {
77 animRepair: this.animRepair
80 this.callParent([this.el.dom, this.ddGroup || this.group,
81 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true}]);
83 this.dragging = false;
86 <span id='Ext-dd-DragSource-method-getDragData'> /**
87 </span> * Returns the data object associated with this drag source
88 * @return {Object} data An object containing arbitrary data
90 getDragData : function(e){
95 onDragEnter : function(e, id){
96 var target = Ext.dd.DragDropManager.getDDById(id);
97 this.cachedTarget = target;
98 if (this.beforeDragEnter(target, e, id) !== false) {
99 if (target.isNotifyTarget) {
100 var status = target.notifyEnter(this, e, this.dragData);
101 this.proxy.setStatus(status);
103 this.proxy.setStatus(this.dropAllowed);
106 if (this.afterDragEnter) {
107 <span id='Ext-dd-DragSource-method-afterDragEnter'> /**
108 </span> * An empty function by default, but provided so that you can perform a custom action
109 * when the dragged item enters the drop target by providing an implementation.
110 * @param {Ext.dd.DragDrop} target The drop target
111 * @param {Event} e The event object
112 * @param {String} id The id of the dragged element
113 * @method afterDragEnter
115 this.afterDragEnter(target, e, id);
120 <span id='Ext-dd-DragSource-method-beforeDragEnter'> /**
121 </span> * An empty function by default, but provided so that you can perform a custom action
122 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
123 * @param {Ext.dd.DragDrop} target The drop target
124 * @param {Event} e The event object
125 * @param {String} id The id of the dragged element
126 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
128 beforeDragEnter: function(target, e, id) {
133 alignElWithMouse: function() {
134 this.callParent(arguments);
139 onDragOver: function(e, id) {
140 var target = this.cachedTarget || Ext.dd.DragDropManager.getDDById(id);
141 if (this.beforeDragOver(target, e, id) !== false) {
142 if(target.isNotifyTarget){
143 var status = target.notifyOver(this, e, this.dragData);
144 this.proxy.setStatus(status);
147 if (this.afterDragOver) {
148 <span id='Ext-dd-DragSource-method-afterDragOver'> /**
149 </span> * An empty function by default, but provided so that you can perform a custom action
150 * while the dragged item is over the drop target by providing an implementation.
151 * @param {Ext.dd.DragDrop} target The drop target
152 * @param {Event} e The event object
153 * @param {String} id The id of the dragged element
154 * @method afterDragOver
156 this.afterDragOver(target, e, id);
161 <span id='Ext-dd-DragSource-method-beforeDragOver'> /**
162 </span> * An empty function by default, but provided so that you can perform a custom action
163 * while the dragged item is over the drop target and optionally cancel the onDragOver.
164 * @param {Ext.dd.DragDrop} target The drop target
165 * @param {Event} e The event object
166 * @param {String} id The id of the dragged element
167 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
169 beforeDragOver: function(target, e, id) {
174 onDragOut: function(e, id) {
175 var target = this.cachedTarget || Ext.dd.DragDropManager.getDDById(id);
176 if (this.beforeDragOut(target, e, id) !== false) {
177 if (target.isNotifyTarget) {
178 target.notifyOut(this, e, this.dragData);
181 if (this.afterDragOut) {
182 <span id='Ext-dd-DragSource-method-afterDragOut'> /**
183 </span> * An empty function by default, but provided so that you can perform a custom action
184 * after the dragged item is dragged out of the target without dropping.
185 * @param {Ext.dd.DragDrop} target The drop target
186 * @param {Event} e The event object
187 * @param {String} id The id of the dragged element
188 * @method afterDragOut
190 this.afterDragOut(target, e, id);
193 this.cachedTarget = null;
196 <span id='Ext-dd-DragSource-method-beforeDragOut'> /**
197 </span> * An empty function by default, but provided so that you can perform a custom action before the dragged
198 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
199 * @param {Ext.dd.DragDrop} target The drop target
200 * @param {Event} e The event object
201 * @param {String} id The id of the dragged element
202 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
204 beforeDragOut: function(target, e, id){
209 onDragDrop: function(e, id){
210 var target = this.cachedTarget || Ext.dd.DragDropManager.getDDById(id);
211 if (this.beforeDragDrop(target, e, id) !== false) {
212 if (target.isNotifyTarget) {
213 if (target.notifyDrop(this, e, this.dragData) !== false) { // valid drop?
214 this.onValidDrop(target, e, id);
216 this.onInvalidDrop(target, e, id);
219 this.onValidDrop(target, e, id);
222 if (this.afterDragDrop) {
223 <span id='Ext-dd-DragSource-method-afterDragDrop'> /**
224 </span> * An empty function by default, but provided so that you can perform a custom action
225 * after a valid drag drop has occurred by providing an implementation.
226 * @param {Ext.dd.DragDrop} target The drop target
227 * @param {Event} e The event object
228 * @param {String} id The id of the dropped element
229 * @method afterDragDrop
231 this.afterDragDrop(target, e, id);
234 delete this.cachedTarget;
237 <span id='Ext-dd-DragSource-method-beforeDragDrop'> /**
238 </span> * An empty function by default, but provided so that you can perform a custom action before the dragged
239 * item is dropped onto the target and optionally cancel the onDragDrop.
240 * @param {Ext.dd.DragDrop} target The drop target
241 * @param {Event} e The event object
242 * @param {String} id The id of the dragged element
243 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
245 beforeDragDrop: function(target, e, id){
250 onValidDrop: function(target, e, id){
252 if(this.afterValidDrop){
253 <span id='Ext-dd-DragSource-method-afterValidDrop'> /**
254 </span> * An empty function by default, but provided so that you can perform a custom action
255 * after a valid drop has occurred by providing an implementation.
256 * @param {Object} target The target DD
257 * @param {Event} e The event object
258 * @param {String} id The id of the dropped element
259 * @method afterValidDrop
261 this.afterValidDrop(target, e, id);
266 getRepairXY: function(e, data){
267 return this.el.getXY();
271 onInvalidDrop: function(target, e, id) {
272 this.beforeInvalidDrop(target, e, id);
273 if (this.cachedTarget) {
274 if(this.cachedTarget.isNotifyTarget){
275 this.cachedTarget.notifyOut(this, e, this.dragData);
277 this.cacheTarget = null;
279 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
281 if (this.afterInvalidDrop) {
282 <span id='Ext-dd-DragSource-method-afterInvalidDrop'> /**
283 </span> * An empty function by default, but provided so that you can perform a custom action
284 * after an invalid drop has occurred by providing an implementation.
285 * @param {Event} e The event object
286 * @param {String} id The id of the dropped element
287 * @method afterInvalidDrop
289 this.afterInvalidDrop(e, id);
294 afterRepair: function() {
297 me.el.highlight(me.repairHighlightColor);
302 <span id='Ext-dd-DragSource-method-beforeInvalidDrop'> /**
303 </span> * An empty function by default, but provided so that you can perform a custom action after an invalid
305 * @param {Ext.dd.DragDrop} target The drop target
306 * @param {Event} e The event object
307 * @param {String} id The id of the dragged element
308 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
310 beforeInvalidDrop: function(target, e, id) {
315 handleMouseDown: function(e) {
319 var data = this.getDragData(e);
320 if (data && this.onBeforeDrag(data, e) !== false) {
321 this.dragData = data;
323 this.callParent(arguments);
327 <span id='Ext-dd-DragSource-method-onBeforeDrag'> /**
328 </span> * An empty function by default, but provided so that you can perform a custom action before the initial
329 * drag event begins and optionally cancel it.
330 * @param {Object} data An object containing arbitrary data to be shared with drop targets
331 * @param {Event} e The event object
332 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
334 onBeforeDrag: function(data, e){
338 <span id='Ext-dd-DragSource-method-onStartDrag'> /**
339 </span> * An empty function by default, but provided so that you can perform a custom action once the initial
340 * drag event has begun. The drag cannot be canceled from this function.
341 * @param {Number} x The x position of the click on the dragged object
342 * @param {Number} y The y position of the click on the dragged object
345 onStartDrag: Ext.emptyFn,
348 startDrag: function(x, y) {
350 this.dragging = true;
351 this.proxy.update("");
352 this.onInitDrag(x, y);
357 onInitDrag: function(x, y) {
358 var clone = this.el.dom.cloneNode(true);
359 clone.id = Ext.id(); // prevent duplicate ids
360 this.proxy.update(clone);
361 this.onStartDrag(x, y);
365 <span id='Ext-dd-DragSource-method-getProxy'> /**
366 </span> * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
367 * @return {Ext.dd.StatusProxy} proxy The StatusProxy
369 getProxy: function() {
373 <span id='Ext-dd-DragSource-method-hideProxy'> /**
374 </span> * Hides the drag source's {@link Ext.dd.StatusProxy}
376 hideProxy: function() {
378 this.proxy.reset(true);
379 this.dragging = false;
383 triggerCacheRefresh: function() {
384 Ext.dd.DDM.refreshCache(this.groups);
387 // private - override to prevent hiding
388 b4EndDrag: function(e) {
391 // private - override to prevent moving
392 endDrag : function(e){
393 this.onEndDrag(this.dragData, e);
397 onEndDrag : function(data, e){
400 // private - pin to cursor
401 autoOffset : function(x, y) {
402 this.setDelta(-12, -20);
407 Ext.destroy(this.proxy);