~dongpo-deng/sahana-eden/test

« back to all changes in this revision

Viewing changes to static/scripts/ext-2.2.1/source/dd/DragSource.js

  • Committer: Deng Dongpo
  • Date: 2010-08-01 09:29:44 UTC
  • Revision ID: dongpo@dhcp-21193.iis.sinica.edu.tw-20100801092944-8t9obt4xtl7otesb
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 2.2.1
 
3
 * Copyright(c) 2006-2009, Ext JS, LLC.
 
4
 * licensing@extjs.com
 
5
 * 
 
6
 * http://extjs.com/license
 
7
 */
 
8
 
 
9
/**
 
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.
 
13
 * @constructor
 
14
 * @param {Mixed} el The container element
 
15
 * @param {Object} config
 
16
 */
 
17
Ext.dd.DragSource = function(el, config){
 
18
    this.el = Ext.get(el);
 
19
    if(!this.dragData){
 
20
        this.dragData = {};
 
21
    }
 
22
    
 
23
    Ext.apply(this, config);
 
24
    
 
25
    if(!this.proxy){
 
26
        this.proxy = new Ext.dd.StatusProxy();
 
27
    }
 
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});
 
30
    
 
31
    this.dragging = false;
 
32
};
 
33
 
 
34
Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
 
35
    /**
 
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).
 
39
     */
 
40
    /**
 
41
     * @cfg {String} dropAllowed
 
42
     * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
 
43
     */
 
44
    dropAllowed : "x-dd-drop-ok",
 
45
    /**
 
46
     * @cfg {String} dropNotAllowed
 
47
     * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
 
48
     */
 
49
    dropNotAllowed : "x-dd-drop-nodrop",
 
50
 
 
51
    /**
 
52
     * Returns the data object associated with this drag source
 
53
     * @return {Object} data An object containing arbitrary data
 
54
     */
 
55
    getDragData : function(e){
 
56
        return this.dragData;
 
57
    },
 
58
 
 
59
    // private
 
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);
 
67
            }else{
 
68
                this.proxy.setStatus(this.dropAllowed);
 
69
            }
 
70
            
 
71
            if(this.afterDragEnter){
 
72
                /**
 
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
 
79
                 */
 
80
                this.afterDragEnter(target, e, id);
 
81
            }
 
82
        }
 
83
    },
 
84
 
 
85
    /**
 
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
 
92
     */
 
93
    beforeDragEnter : function(target, e, id){
 
94
        return true;
 
95
    },
 
96
 
 
97
    // private
 
98
    alignElWithMouse: function() {
 
99
        Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
 
100
        this.proxy.sync();
 
101
    },
 
102
 
 
103
    // private
 
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);
 
110
            }
 
111
 
 
112
            if(this.afterDragOver){
 
113
                /**
 
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
 
120
                 */
 
121
                this.afterDragOver(target, e, id);
 
122
            }
 
123
        }
 
124
    },
 
125
 
 
126
    /**
 
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
 
133
     */
 
134
    beforeDragOver : function(target, e, id){
 
135
        return true;
 
136
    },
 
137
 
 
138
    // private
 
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);
 
144
            }
 
145
            this.proxy.reset();
 
146
            if(this.afterDragOut){
 
147
                /**
 
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
 
154
                 */
 
155
                this.afterDragOut(target, e, id);
 
156
            }
 
157
        }
 
158
        this.cachedTarget = null;
 
159
    },
 
160
 
 
161
    /**
 
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
 
168
     */
 
169
    beforeDragOut : function(target, e, id){
 
170
        return true;
 
171
    },
 
172
    
 
173
    // private
 
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);
 
180
                }else{
 
181
                    this.onInvalidDrop(target, e, id);
 
182
                }
 
183
            }else{
 
184
                this.onValidDrop(target, e, id);
 
185
            }
 
186
            
 
187
            if(this.afterDragDrop){
 
188
                /**
 
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
 
195
                 */
 
196
                this.afterDragDrop(target, e, id);
 
197
            }
 
198
        }
 
199
        delete this.cachedTarget;
 
200
    },
 
201
 
 
202
    /**
 
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
 
209
     */
 
210
    beforeDragDrop : function(target, e, id){
 
211
        return true;
 
212
    },
 
213
 
 
214
    // private
 
215
    onValidDrop : function(target, e, id){
 
216
        this.hideProxy();
 
217
        if(this.afterValidDrop){
 
218
            /**
 
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
 
225
             */
 
226
            this.afterValidDrop(target, e, id);
 
227
        }
 
228
    },
 
229
 
 
230
    // private
 
231
    getRepairXY : function(e, data){
 
232
        return this.el.getXY();  
 
233
    },
 
234
 
 
235
    // private
 
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);
 
241
            }
 
242
            this.cacheTarget = null;
 
243
        }
 
244
        this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
 
245
 
 
246
        if(this.afterInvalidDrop){
 
247
            /**
 
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
 
253
             */
 
254
            this.afterInvalidDrop(e, id);
 
255
        }
 
256
    },
 
257
 
 
258
    // private
 
259
    afterRepair : function(){
 
260
        if(Ext.enableFx){
 
261
            this.el.highlight(this.hlColor || "c3daf9");
 
262
        }
 
263
        this.dragging = false;
 
264
    },
 
265
 
 
266
    /**
 
267
     * An empty function by default, but provided so that you can perform a custom action after an invalid
 
268
     * drop has occurred.
 
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
 
273
     */
 
274
    beforeInvalidDrop : function(target, e, id){
 
275
        return true;
 
276
    },
 
277
 
 
278
    // private
 
279
    handleMouseDown : function(e){
 
280
        if(this.dragging) {
 
281
            return;
 
282
        }
 
283
        var data = this.getDragData(e);
 
284
        if(data && this.onBeforeDrag(data, e) !== false){
 
285
            this.dragData = data;
 
286
            this.proxy.stop();
 
287
            Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
 
288
        } 
 
289
    },
 
290
 
 
291
    /**
 
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
 
297
     */
 
298
    onBeforeDrag : function(data, e){
 
299
        return true;
 
300
    },
 
301
 
 
302
    /**
 
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
 
307
     */
 
308
    onStartDrag : Ext.emptyFn,
 
309
 
 
310
    // private override
 
311
    startDrag : function(x, y){
 
312
        this.proxy.reset();
 
313
        this.dragging = true;
 
314
        this.proxy.update("");
 
315
        this.onInitDrag(x, y);
 
316
        this.proxy.show();
 
317
    },
 
318
 
 
319
    // private
 
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);
 
325
        return true;
 
326
    },
 
327
 
 
328
    /**
 
329
     * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
 
330
     * @return {Ext.dd.StatusProxy} proxy The StatusProxy
 
331
     */
 
332
    getProxy : function(){
 
333
        return this.proxy;  
 
334
    },
 
335
 
 
336
    /**
 
337
     * Hides the drag source's {@link Ext.dd.StatusProxy}
 
338
     */
 
339
    hideProxy : function(){
 
340
        this.proxy.hide();  
 
341
        this.proxy.reset(true);
 
342
        this.dragging = false;
 
343
    },
 
344
 
 
345
    // private
 
346
    triggerCacheRefresh : function(){
 
347
        Ext.dd.DDM.refreshCache(this.groups);
 
348
    },
 
349
 
 
350
    // private - override to prevent hiding
 
351
    b4EndDrag: function(e) {
 
352
    },
 
353
 
 
354
    // private - override to prevent moving
 
355
    endDrag : function(e){
 
356
        this.onEndDrag(this.dragData, e);
 
357
    },
 
358
 
 
359
    // private
 
360
    onEndDrag : function(data, e){
 
361
    },
 
362
    
 
363
    // private - pin to cursor
 
364
    autoOffset : function(x, y) {
 
365
        this.setDelta(-12, -20);
 
366
    }    
 
367
});
 
 
b'\\ No newline at end of file'