3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.dd.DragSource
11
* @extends Ext.dd.DDProxy
12
* A simple class that provides the basic implementation needed to make any element draggable.
14
* @param {Mixed} el The container element
15
* @param {Object} config
17
Ext.dd.DragSource = function(el, config){
18
this.el = Ext.get(el);
23
Ext.apply(this, config);
26
this.proxy = new Ext.dd.StatusProxy();
28
Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
29
{dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
31
this.dragging = false;
34
Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
36
* @cfg {String} ddGroup
37
* A named drag drop group to which this object belongs. If a group is specified, then this object will only
38
* interact with other drag drop objects in the same group (defaults to undefined).
41
* @cfg {String} dropAllowed
42
* The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
44
dropAllowed : "x-dd-drop-ok",
46
* @cfg {String} dropNotAllowed
47
* The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
49
dropNotAllowed : "x-dd-drop-nodrop",
52
* Returns the data object associated with this drag source
53
* @return {Object} data An object containing arbitrary data
55
getDragData : function(e){
60
onDragEnter : function(e, id){
61
var target = Ext.dd.DragDropMgr.getDDById(id);
62
this.cachedTarget = target;
63
if(this.beforeDragEnter(target, e, id) !== false){
64
if(target.isNotifyTarget){
65
var status = target.notifyEnter(this, e, this.dragData);
66
this.proxy.setStatus(status);
68
this.proxy.setStatus(this.dropAllowed);
71
if(this.afterDragEnter){
73
* An empty function by default, but provided so that you can perform a custom action
74
* when the dragged item enters the drop target by providing an implementation.
75
* @param {Ext.dd.DragDrop} target The drop target
76
* @param {Event} e The event object
77
* @param {String} id The id of the dragged element
78
* @method afterDragEnter
80
this.afterDragEnter(target, e, id);
86
* An empty function by default, but provided so that you can perform a custom action
87
* before the dragged item enters the drop target and optionally cancel the onDragEnter.
88
* @param {Ext.dd.DragDrop} target The drop target
89
* @param {Event} e The event object
90
* @param {String} id The id of the dragged element
91
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
93
beforeDragEnter : function(target, e, id){
98
alignElWithMouse: function() {
99
Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
104
onDragOver : function(e, id){
105
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
106
if(this.beforeDragOver(target, e, id) !== false){
107
if(target.isNotifyTarget){
108
var status = target.notifyOver(this, e, this.dragData);
109
this.proxy.setStatus(status);
112
if(this.afterDragOver){
114
* An empty function by default, but provided so that you can perform a custom action
115
* while the dragged item is over the drop target by providing an implementation.
116
* @param {Ext.dd.DragDrop} target The drop target
117
* @param {Event} e The event object
118
* @param {String} id The id of the dragged element
119
* @method afterDragOver
121
this.afterDragOver(target, e, id);
127
* An empty function by default, but provided so that you can perform a custom action
128
* while the dragged item is over the drop target and optionally cancel the onDragOver.
129
* @param {Ext.dd.DragDrop} target The drop target
130
* @param {Event} e The event object
131
* @param {String} id The id of the dragged element
132
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
134
beforeDragOver : function(target, e, id){
139
onDragOut : function(e, id){
140
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
141
if(this.beforeDragOut(target, e, id) !== false){
142
if(target.isNotifyTarget){
143
target.notifyOut(this, e, this.dragData);
146
if(this.afterDragOut){
148
* An empty function by default, but provided so that you can perform a custom action
149
* after the dragged item is dragged out of the target without dropping.
150
* @param {Ext.dd.DragDrop} target The drop target
151
* @param {Event} e The event object
152
* @param {String} id The id of the dragged element
153
* @method afterDragOut
155
this.afterDragOut(target, e, id);
158
this.cachedTarget = null;
162
* An empty function by default, but provided so that you can perform a custom action before the dragged
163
* item is dragged out of the target without dropping, and optionally cancel the onDragOut.
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
beforeDragOut : function(target, e, id){
174
onDragDrop : function(e, id){
175
var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
176
if(this.beforeDragDrop(target, e, id) !== false){
177
if(target.isNotifyTarget){
178
if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
179
this.onValidDrop(target, e, id);
181
this.onInvalidDrop(target, e, id);
184
this.onValidDrop(target, e, id);
187
if(this.afterDragDrop){
189
* An empty function by default, but provided so that you can perform a custom action
190
* after a valid drag drop has occurred by providing an implementation.
191
* @param {Ext.dd.DragDrop} target The drop target
192
* @param {Event} e The event object
193
* @param {String} id The id of the dropped element
194
* @method afterDragDrop
196
this.afterDragDrop(target, e, id);
199
delete this.cachedTarget;
203
* An empty function by default, but provided so that you can perform a custom action before the dragged
204
* item is dropped onto the target and optionally cancel the onDragDrop.
205
* @param {Ext.dd.DragDrop} target The drop target
206
* @param {Event} e The event object
207
* @param {String} id The id of the dragged element
208
* @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
210
beforeDragDrop : function(target, e, id){
215
onValidDrop : function(target, e, id){
217
if(this.afterValidDrop){
219
* An empty function by default, but provided so that you can perform a custom action
220
* after a valid drop has occurred by providing an implementation.
221
* @param {Object} target The target DD
222
* @param {Event} e The event object
223
* @param {String} id The id of the dropped element
224
* @method afterInvalidDrop
226
this.afterValidDrop(target, e, id);
231
getRepairXY : function(e, data){
232
return this.el.getXY();
236
onInvalidDrop : function(target, e, id){
237
this.beforeInvalidDrop(target, e, id);
238
if(this.cachedTarget){
239
if(this.cachedTarget.isNotifyTarget){
240
this.cachedTarget.notifyOut(this, e, this.dragData);
242
this.cacheTarget = null;
244
this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
246
if(this.afterInvalidDrop){
248
* An empty function by default, but provided so that you can perform a custom action
249
* after an invalid drop has occurred by providing an implementation.
250
* @param {Event} e The event object
251
* @param {String} id The id of the dropped element
252
* @method afterInvalidDrop
254
this.afterInvalidDrop(e, id);
259
afterRepair : function(){
261
this.el.highlight(this.hlColor || "c3daf9");
263
this.dragging = false;
267
* An empty function by default, but provided so that you can perform a custom action after an invalid
269
* @param {Ext.dd.DragDrop} target The drop target
270
* @param {Event} e The event object
271
* @param {String} id The id of the dragged element
272
* @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
274
beforeInvalidDrop : function(target, e, id){
279
handleMouseDown : function(e){
283
var data = this.getDragData(e);
284
if(data && this.onBeforeDrag(data, e) !== false){
285
this.dragData = data;
287
Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
292
* An empty function by default, but provided so that you can perform a custom action before the initial
293
* drag event begins and optionally cancel it.
294
* @param {Object} data An object containing arbitrary data to be shared with drop targets
295
* @param {Event} e The event object
296
* @return {Boolean} isValid True if the drag event is valid, else false to cancel
298
onBeforeDrag : function(data, e){
303
* An empty function by default, but provided so that you can perform a custom action once the initial
304
* drag event has begun. The drag cannot be canceled from this function.
305
* @param {Number} x The x position of the click on the dragged object
306
* @param {Number} y The y position of the click on the dragged object
308
onStartDrag : Ext.emptyFn,
311
startDrag : function(x, y){
313
this.dragging = true;
314
this.proxy.update("");
315
this.onInitDrag(x, y);
320
onInitDrag : function(x, y){
321
var clone = this.el.dom.cloneNode(true);
322
clone.id = Ext.id(); // prevent duplicate ids
323
this.proxy.update(clone);
324
this.onStartDrag(x, y);
329
* Returns the drag source's underlying {@link Ext.dd.StatusProxy}
330
* @return {Ext.dd.StatusProxy} proxy The StatusProxy
332
getProxy : function(){
337
* Hides the drag source's {@link Ext.dd.StatusProxy}
339
hideProxy : function(){
341
this.proxy.reset(true);
342
this.dragging = false;
346
triggerCacheRefresh : function(){
347
Ext.dd.DDM.refreshCache(this.groups);
350
// private - override to prevent hiding
351
b4EndDrag: function(e) {
354
// private - override to prevent moving
355
endDrag : function(e){
356
this.onEndDrag(this.dragData, e);
360
onEndDrag : function(data, e){
363
// private - pin to cursor
364
autoOffset : function(x, y) {
365
this.setDelta(-12, -20);
b'\\ No newline at end of file'