Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / pkgs / ext-dd-debug.js
1 /*!
2  * Ext JS Library 3.0.3
3  * Copyright(c) 2006-2009 Ext JS, LLC
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /*
8  * These classes are derivatives of the similarly named classes in the YUI Library.
9  * The original license:
10  * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
11  * Code licensed under the BSD License:
12  * http://developer.yahoo.net/yui/license.txt
13  */
14
15 (function() {
16
17 var Event=Ext.EventManager;
18 var Dom=Ext.lib.Dom;
19
20 /**
21  * @class Ext.dd.DragDrop
22  * Defines the interface and base operation of items that that can be
23  * dragged or can be drop targets.  It was designed to be extended, overriding
24  * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
25  * Up to three html elements can be associated with a DragDrop instance:
26  * <ul>
27  * <li>linked element: the element that is passed into the constructor.
28  * This is the element which defines the boundaries for interaction with
29  * other DragDrop objects.</li>
30  * <li>handle element(s): The drag operation only occurs if the element that
31  * was clicked matches a handle element.  By default this is the linked
32  * element, but there are times that you will want only a portion of the
33  * linked element to initiate the drag operation, and the setHandleElId()
34  * method provides a way to define this.</li>
35  * <li>drag element: this represents the element that would be moved along
36  * with the cursor during a drag operation.  By default, this is the linked
37  * element itself as in {@link Ext.dd.DD}.  setDragElId() lets you define
38  * a separate element that would be moved, as in {@link Ext.dd.DDProxy}.
39  * </li>
40  * </ul>
41  * This class should not be instantiated until the onload event to ensure that
42  * the associated elements are available.
43  * The following would define a DragDrop obj that would interact with any
44  * other DragDrop obj in the "group1" group:
45  * <pre>
46  *  dd = new Ext.dd.DragDrop("div1", "group1");
47  * </pre>
48  * Since none of the event handlers have been implemented, nothing would
49  * actually happen if you were to run the code above.  Normally you would
50  * override this class or one of the default implementations, but you can
51  * also override the methods you want on an instance of the class...
52  * <pre>
53  *  dd.onDragDrop = function(e, id) {
54  *  &nbsp;&nbsp;alert("dd was dropped on " + id);
55  *  }
56  * </pre>
57  * @constructor
58  * @param {String} id of the element that is linked to this instance
59  * @param {String} sGroup the group of related DragDrop objects
60  * @param {object} config an object containing configurable attributes
61  *                Valid properties for DragDrop:
62  *                    padding, isTarget, maintainOffset, primaryButtonOnly
63  */
64 Ext.dd.DragDrop = function(id, sGroup, config) {
65     if(id) {
66         this.init(id, sGroup, config);
67     }
68 };
69
70 Ext.dd.DragDrop.prototype = {
71
72     /**
73      * Set to false to enable a DragDrop object to fire drag events while dragging
74      * over its own Element. Defaults to true - DragDrop objects do not by default
75      * fire drag events to themselves.
76      * @property ignoreSelf
77      * @type Boolean
78      */
79
80     /**
81      * The id of the element associated with this object.  This is what we
82      * refer to as the "linked element" because the size and position of
83      * this element is used to determine when the drag and drop objects have
84      * interacted.
85      * @property id
86      * @type String
87      */
88     id: null,
89
90     /**
91      * Configuration attributes passed into the constructor
92      * @property config
93      * @type object
94      */
95     config: null,
96
97     /**
98      * The id of the element that will be dragged.  By default this is same
99      * as the linked element , but could be changed to another element. Ex:
100      * Ext.dd.DDProxy
101      * @property dragElId
102      * @type String
103      * @private
104      */
105     dragElId: null,
106
107     /**
108      * The ID of the element that initiates the drag operation.  By default
109      * this is the linked element, but could be changed to be a child of this
110      * element.  This lets us do things like only starting the drag when the
111      * header element within the linked html element is clicked.
112      * @property handleElId
113      * @type String
114      * @private
115      */
116     handleElId: null,
117
118     /**
119      * An object who's property names identify HTML tags to be considered invalid as drag handles.
120      * A non-null property value identifies the tag as invalid. Defaults to the 
121      * following value which prevents drag operations from being initiated by &lt;a> elements:<pre><code>
122 {
123     A: "A"
124 }</code></pre>
125      * @property invalidHandleTypes
126      * @type Object
127      */
128     invalidHandleTypes: null,
129
130     /**
131      * An object who's property names identify the IDs of elements to be considered invalid as drag handles.
132      * A non-null property value identifies the ID as invalid. For example, to prevent
133      * dragging from being initiated on element ID "foo", use:<pre><code>
134 {
135     foo: true
136 }</code></pre>
137      * @property invalidHandleIds
138      * @type Object
139      */
140     invalidHandleIds: null,
141
142     /**
143      * An Array of CSS class names for elements to be considered in valid as drag handles.
144      * @property invalidHandleClasses
145      * @type Array
146      */
147     invalidHandleClasses: null,
148
149     /**
150      * The linked element's absolute X position at the time the drag was
151      * started
152      * @property startPageX
153      * @type int
154      * @private
155      */
156     startPageX: 0,
157
158     /**
159      * The linked element's absolute X position at the time the drag was
160      * started
161      * @property startPageY
162      * @type int
163      * @private
164      */
165     startPageY: 0,
166
167     /**
168      * The group defines a logical collection of DragDrop objects that are
169      * related.  Instances only get events when interacting with other
170      * DragDrop object in the same group.  This lets us define multiple
171      * groups using a single DragDrop subclass if we want.
172      * @property groups
173      * @type object An object in the format {'group1':true, 'group2':true}
174      */
175     groups: null,
176
177     /**
178      * Individual drag/drop instances can be locked.  This will prevent
179      * onmousedown start drag.
180      * @property locked
181      * @type boolean
182      * @private
183      */
184     locked: false,
185
186     /**
187      * Lock this instance
188      * @method lock
189      */
190     lock: function() { this.locked = true; },
191
192     /**
193      * When set to true, other DD objects in cooperating DDGroups do not receive
194      * notification events when this DD object is dragged over them. Defaults to false.
195      * @property moveOnly
196      * @type boolean
197      */
198     moveOnly: false,
199
200     /**
201      * Unlock this instace
202      * @method unlock
203      */
204     unlock: function() { this.locked = false; },
205
206     /**
207      * By default, all instances can be a drop target.  This can be disabled by
208      * setting isTarget to false.
209      * @property isTarget
210      * @type boolean
211      */
212     isTarget: true,
213
214     /**
215      * The padding configured for this drag and drop object for calculating
216      * the drop zone intersection with this object.
217      * @property padding
218      * @type int[] An array containing the 4 padding values: [top, right, bottom, left]
219      */
220     padding: null,
221
222     /**
223      * Cached reference to the linked element
224      * @property _domRef
225      * @private
226      */
227     _domRef: null,
228
229     /**
230      * Internal typeof flag
231      * @property __ygDragDrop
232      * @private
233      */
234     __ygDragDrop: true,
235
236     /**
237      * Set to true when horizontal contraints are applied
238      * @property constrainX
239      * @type boolean
240      * @private
241      */
242     constrainX: false,
243
244     /**
245      * Set to true when vertical contraints are applied
246      * @property constrainY
247      * @type boolean
248      * @private
249      */
250     constrainY: false,
251
252     /**
253      * The left constraint
254      * @property minX
255      * @type int
256      * @private
257      */
258     minX: 0,
259
260     /**
261      * The right constraint
262      * @property maxX
263      * @type int
264      * @private
265      */
266     maxX: 0,
267
268     /**
269      * The up constraint
270      * @property minY
271      * @type int
272      * @type int
273      * @private
274      */
275     minY: 0,
276
277     /**
278      * The down constraint
279      * @property maxY
280      * @type int
281      * @private
282      */
283     maxY: 0,
284
285     /**
286      * Maintain offsets when we resetconstraints.  Set to true when you want
287      * the position of the element relative to its parent to stay the same
288      * when the page changes
289      *
290      * @property maintainOffset
291      * @type boolean
292      */
293     maintainOffset: false,
294
295     /**
296      * Array of pixel locations the element will snap to if we specified a
297      * horizontal graduation/interval.  This array is generated automatically
298      * when you define a tick interval.
299      * @property xTicks
300      * @type int[]
301      */
302     xTicks: null,
303
304     /**
305      * Array of pixel locations the element will snap to if we specified a
306      * vertical graduation/interval.  This array is generated automatically
307      * when you define a tick interval.
308      * @property yTicks
309      * @type int[]
310      */
311     yTicks: null,
312
313     /**
314      * By default the drag and drop instance will only respond to the primary
315      * button click (left button for a right-handed mouse).  Set to true to
316      * allow drag and drop to start with any mouse click that is propogated
317      * by the browser
318      * @property primaryButtonOnly
319      * @type boolean
320      */
321     primaryButtonOnly: true,
322
323     /**
324      * The availabe property is false until the linked dom element is accessible.
325      * @property available
326      * @type boolean
327      */
328     available: false,
329
330     /**
331      * By default, drags can only be initiated if the mousedown occurs in the
332      * region the linked element is.  This is done in part to work around a
333      * bug in some browsers that mis-report the mousedown if the previous
334      * mouseup happened outside of the window.  This property is set to true
335      * if outer handles are defined.
336      *
337      * @property hasOuterHandles
338      * @type boolean
339      * @default false
340      */
341     hasOuterHandles: false,
342
343     /**
344      * Code that executes immediately before the startDrag event
345      * @method b4StartDrag
346      * @private
347      */
348     b4StartDrag: function(x, y) { },
349
350     /**
351      * Abstract method called after a drag/drop object is clicked
352      * and the drag or mousedown time thresholds have beeen met.
353      * @method startDrag
354      * @param {int} X click location
355      * @param {int} Y click location
356      */
357     startDrag: function(x, y) { /* override this */ },
358
359     /**
360      * Code that executes immediately before the onDrag event
361      * @method b4Drag
362      * @private
363      */
364     b4Drag: function(e) { },
365
366     /**
367      * Abstract method called during the onMouseMove event while dragging an
368      * object.
369      * @method onDrag
370      * @param {Event} e the mousemove event
371      */
372     onDrag: function(e) { /* override this */ },
373
374     /**
375      * Abstract method called when this element fist begins hovering over
376      * another DragDrop obj
377      * @method onDragEnter
378      * @param {Event} e the mousemove event
379      * @param {String|DragDrop[]} id In POINT mode, the element
380      * id this is hovering over.  In INTERSECT mode, an array of one or more
381      * dragdrop items being hovered over.
382      */
383     onDragEnter: function(e, id) { /* override this */ },
384
385     /**
386      * Code that executes immediately before the onDragOver event
387      * @method b4DragOver
388      * @private
389      */
390     b4DragOver: function(e) { },
391
392     /**
393      * Abstract method called when this element is hovering over another
394      * DragDrop obj
395      * @method onDragOver
396      * @param {Event} e the mousemove event
397      * @param {String|DragDrop[]} id In POINT mode, the element
398      * id this is hovering over.  In INTERSECT mode, an array of dd items
399      * being hovered over.
400      */
401     onDragOver: function(e, id) { /* override this */ },
402
403     /**
404      * Code that executes immediately before the onDragOut event
405      * @method b4DragOut
406      * @private
407      */
408     b4DragOut: function(e) { },
409
410     /**
411      * Abstract method called when we are no longer hovering over an element
412      * @method onDragOut
413      * @param {Event} e the mousemove event
414      * @param {String|DragDrop[]} id In POINT mode, the element
415      * id this was hovering over.  In INTERSECT mode, an array of dd items
416      * that the mouse is no longer over.
417      */
418     onDragOut: function(e, id) { /* override this */ },
419
420     /**
421      * Code that executes immediately before the onDragDrop event
422      * @method b4DragDrop
423      * @private
424      */
425     b4DragDrop: function(e) { },
426
427     /**
428      * Abstract method called when this item is dropped on another DragDrop
429      * obj
430      * @method onDragDrop
431      * @param {Event} e the mouseup event
432      * @param {String|DragDrop[]} id In POINT mode, the element
433      * id this was dropped on.  In INTERSECT mode, an array of dd items this
434      * was dropped on.
435      */
436     onDragDrop: function(e, id) { /* override this */ },
437
438     /**
439      * Abstract method called when this item is dropped on an area with no
440      * drop target
441      * @method onInvalidDrop
442      * @param {Event} e the mouseup event
443      */
444     onInvalidDrop: function(e) { /* override this */ },
445
446     /**
447      * Code that executes immediately before the endDrag event
448      * @method b4EndDrag
449      * @private
450      */
451     b4EndDrag: function(e) { },
452
453     /**
454      * Fired when we are done dragging the object
455      * @method endDrag
456      * @param {Event} e the mouseup event
457      */
458     endDrag: function(e) { /* override this */ },
459
460     /**
461      * Code executed immediately before the onMouseDown event
462      * @method b4MouseDown
463      * @param {Event} e the mousedown event
464      * @private
465      */
466     b4MouseDown: function(e) {  },
467
468     /**
469      * Event handler that fires when a drag/drop obj gets a mousedown
470      * @method onMouseDown
471      * @param {Event} e the mousedown event
472      */
473     onMouseDown: function(e) { /* override this */ },
474
475     /**
476      * Event handler that fires when a drag/drop obj gets a mouseup
477      * @method onMouseUp
478      * @param {Event} e the mouseup event
479      */
480     onMouseUp: function(e) { /* override this */ },
481
482     /**
483      * Override the onAvailable method to do what is needed after the initial
484      * position was determined.
485      * @method onAvailable
486      */
487     onAvailable: function () {
488     },
489
490     /**
491      * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
492      * @type Object
493      */
494     defaultPadding : {left:0, right:0, top:0, bottom:0},
495
496     /**
497      * Initializes the drag drop object's constraints to restrict movement to a certain element.
498  *
499  * Usage:
500  <pre><code>
501  var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
502                 { dragElId: "existingProxyDiv" });
503  dd.startDrag = function(){
504      this.constrainTo("parent-id");
505  };
506  </code></pre>
507  * Or you can initalize it using the {@link Ext.Element} object:
508  <pre><code>
509  Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
510      startDrag : function(){
511          this.constrainTo("parent-id");
512      }
513  });
514  </code></pre>
515      * @param {Mixed} constrainTo The element to constrain to.
516      * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
517      * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
518      * an object containing the sides to pad. For example: {right:10, bottom:10}
519      * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
520      */
521     constrainTo : function(constrainTo, pad, inContent){
522         if(typeof pad == "number"){
523             pad = {left: pad, right:pad, top:pad, bottom:pad};
524         }
525         pad = pad || this.defaultPadding;
526         var b = Ext.get(this.getEl()).getBox();
527         var ce = Ext.get(constrainTo);
528         var s = ce.getScroll();
529         var c, cd = ce.dom;
530         if(cd == document.body){
531             c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()};
532         }else{
533             var xy = ce.getXY();
534             c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
535         }
536
537
538         var topSpace = b.y - c.y;
539         var leftSpace = b.x - c.x;
540
541         this.resetConstraints();
542         this.setXConstraint(leftSpace - (pad.left||0), // left
543                 c.width - leftSpace - b.width - (pad.right||0), //right
544                                 this.xTickSize
545         );
546         this.setYConstraint(topSpace - (pad.top||0), //top
547                 c.height - topSpace - b.height - (pad.bottom||0), //bottom
548                                 this.yTickSize
549         );
550     },
551
552     /**
553      * Returns a reference to the linked element
554      * @method getEl
555      * @return {HTMLElement} the html element
556      */
557     getEl: function() {
558         if (!this._domRef) {
559             this._domRef = Ext.getDom(this.id);
560         }
561
562         return this._domRef;
563     },
564
565     /**
566      * Returns a reference to the actual element to drag.  By default this is
567      * the same as the html element, but it can be assigned to another
568      * element. An example of this can be found in Ext.dd.DDProxy
569      * @method getDragEl
570      * @return {HTMLElement} the html element
571      */
572     getDragEl: function() {
573         return Ext.getDom(this.dragElId);
574     },
575
576     /**
577      * Sets up the DragDrop object.  Must be called in the constructor of any
578      * Ext.dd.DragDrop subclass
579      * @method init
580      * @param id the id of the linked element
581      * @param {String} sGroup the group of related items
582      * @param {object} config configuration attributes
583      */
584     init: function(id, sGroup, config) {
585         this.initTarget(id, sGroup, config);
586         Event.on(this.id, "mousedown", this.handleMouseDown, this);
587         // Event.on(this.id, "selectstart", Event.preventDefault);
588     },
589
590     /**
591      * Initializes Targeting functionality only... the object does not
592      * get a mousedown handler.
593      * @method initTarget
594      * @param id the id of the linked element
595      * @param {String} sGroup the group of related items
596      * @param {object} config configuration attributes
597      */
598     initTarget: function(id, sGroup, config) {
599
600         // configuration attributes
601         this.config = config || {};
602
603         // create a local reference to the drag and drop manager
604         this.DDM = Ext.dd.DDM;
605         // initialize the groups array
606         this.groups = {};
607
608         // assume that we have an element reference instead of an id if the
609         // parameter is not a string
610         if (typeof id !== "string") {
611             id = Ext.id(id);
612         }
613
614         // set the id
615         this.id = id;
616
617         // add to an interaction group
618         this.addToGroup((sGroup) ? sGroup : "default");
619
620         // We don't want to register this as the handle with the manager
621         // so we just set the id rather than calling the setter.
622         this.handleElId = id;
623
624         // the linked element is the element that gets dragged by default
625         this.setDragElId(id);
626
627         // by default, clicked anchors will not start drag operations.
628         this.invalidHandleTypes = { A: "A" };
629         this.invalidHandleIds = {};
630         this.invalidHandleClasses = [];
631
632         this.applyConfig();
633
634         this.handleOnAvailable();
635     },
636
637     /**
638      * Applies the configuration parameters that were passed into the constructor.
639      * This is supposed to happen at each level through the inheritance chain.  So
640      * a DDProxy implentation will execute apply config on DDProxy, DD, and
641      * DragDrop in order to get all of the parameters that are available in
642      * each object.
643      * @method applyConfig
644      */
645     applyConfig: function() {
646
647         // configurable properties:
648         //    padding, isTarget, maintainOffset, primaryButtonOnly
649         this.padding           = this.config.padding || [0, 0, 0, 0];
650         this.isTarget          = (this.config.isTarget !== false);
651         this.maintainOffset    = (this.config.maintainOffset);
652         this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
653
654     },
655
656     /**
657      * Executed when the linked element is available
658      * @method handleOnAvailable
659      * @private
660      */
661     handleOnAvailable: function() {
662         this.available = true;
663         this.resetConstraints();
664         this.onAvailable();
665     },
666
667      /**
668      * Configures the padding for the target zone in px.  Effectively expands
669      * (or reduces) the virtual object size for targeting calculations.
670      * Supports css-style shorthand; if only one parameter is passed, all sides
671      * will have that padding, and if only two are passed, the top and bottom
672      * will have the first param, the left and right the second.
673      * @method setPadding
674      * @param {int} iTop    Top pad
675      * @param {int} iRight  Right pad
676      * @param {int} iBot    Bot pad
677      * @param {int} iLeft   Left pad
678      */
679     setPadding: function(iTop, iRight, iBot, iLeft) {
680         // this.padding = [iLeft, iRight, iTop, iBot];
681         if (!iRight && 0 !== iRight) {
682             this.padding = [iTop, iTop, iTop, iTop];
683         } else if (!iBot && 0 !== iBot) {
684             this.padding = [iTop, iRight, iTop, iRight];
685         } else {
686             this.padding = [iTop, iRight, iBot, iLeft];
687         }
688     },
689
690     /**
691      * Stores the initial placement of the linked element.
692      * @method setInitPosition
693      * @param {int} diffX   the X offset, default 0
694      * @param {int} diffY   the Y offset, default 0
695      */
696     setInitPosition: function(diffX, diffY) {
697         var el = this.getEl();
698
699         if (!this.DDM.verifyEl(el)) {
700             return;
701         }
702
703         var dx = diffX || 0;
704         var dy = diffY || 0;
705
706         var p = Dom.getXY( el );
707
708         this.initPageX = p[0] - dx;
709         this.initPageY = p[1] - dy;
710
711         this.lastPageX = p[0];
712         this.lastPageY = p[1];
713
714
715         this.setStartPosition(p);
716     },
717
718     /**
719      * Sets the start position of the element.  This is set when the obj
720      * is initialized, the reset when a drag is started.
721      * @method setStartPosition
722      * @param pos current position (from previous lookup)
723      * @private
724      */
725     setStartPosition: function(pos) {
726         var p = pos || Dom.getXY( this.getEl() );
727         this.deltaSetXY = null;
728
729         this.startPageX = p[0];
730         this.startPageY = p[1];
731     },
732
733     /**
734      * Add this instance to a group of related drag/drop objects.  All
735      * instances belong to at least one group, and can belong to as many
736      * groups as needed.
737      * @method addToGroup
738      * @param sGroup {string} the name of the group
739      */
740     addToGroup: function(sGroup) {
741         this.groups[sGroup] = true;
742         this.DDM.regDragDrop(this, sGroup);
743     },
744
745     /**
746      * Remove's this instance from the supplied interaction group
747      * @method removeFromGroup
748      * @param {string}  sGroup  The group to drop
749      */
750     removeFromGroup: function(sGroup) {
751         if (this.groups[sGroup]) {
752             delete this.groups[sGroup];
753         }
754
755         this.DDM.removeDDFromGroup(this, sGroup);
756     },
757
758     /**
759      * Allows you to specify that an element other than the linked element
760      * will be moved with the cursor during a drag
761      * @method setDragElId
762      * @param id {string} the id of the element that will be used to initiate the drag
763      */
764     setDragElId: function(id) {
765         this.dragElId = id;
766     },
767
768     /**
769      * Allows you to specify a child of the linked element that should be
770      * used to initiate the drag operation.  An example of this would be if
771      * you have a content div with text and links.  Clicking anywhere in the
772      * content area would normally start the drag operation.  Use this method
773      * to specify that an element inside of the content div is the element
774      * that starts the drag operation.
775      * @method setHandleElId
776      * @param id {string} the id of the element that will be used to
777      * initiate the drag.
778      */
779     setHandleElId: function(id) {
780         if (typeof id !== "string") {
781             id = Ext.id(id);
782         }
783         this.handleElId = id;
784         this.DDM.regHandle(this.id, id);
785     },
786
787     /**
788      * Allows you to set an element outside of the linked element as a drag
789      * handle
790      * @method setOuterHandleElId
791      * @param id the id of the element that will be used to initiate the drag
792      */
793     setOuterHandleElId: function(id) {
794         if (typeof id !== "string") {
795             id = Ext.id(id);
796         }
797         Event.on(id, "mousedown",
798                 this.handleMouseDown, this);
799         this.setHandleElId(id);
800
801         this.hasOuterHandles = true;
802     },
803
804     /**
805      * Remove all drag and drop hooks for this element
806      * @method unreg
807      */
808     unreg: function() {
809         Event.un(this.id, "mousedown",
810                 this.handleMouseDown);
811         this._domRef = null;
812         this.DDM._remove(this);
813     },
814
815     destroy : function(){
816         this.unreg();
817     },
818
819     /**
820      * Returns true if this instance is locked, or the drag drop mgr is locked
821      * (meaning that all drag/drop is disabled on the page.)
822      * @method isLocked
823      * @return {boolean} true if this obj or all drag/drop is locked, else
824      * false
825      */
826     isLocked: function() {
827         return (this.DDM.isLocked() || this.locked);
828     },
829
830     /**
831      * Fired when this object is clicked
832      * @method handleMouseDown
833      * @param {Event} e
834      * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
835      * @private
836      */
837     handleMouseDown: function(e, oDD){
838         if (this.primaryButtonOnly && e.button != 0) {
839             return;
840         }
841
842         if (this.isLocked()) {
843             return;
844         }
845
846         this.DDM.refreshCache(this.groups);
847
848         var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e));
849         if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) )  {
850         } else {
851             if (this.clickValidator(e)) {
852
853                 // set the initial element position
854                 this.setStartPosition();
855
856
857                 this.b4MouseDown(e);
858                 this.onMouseDown(e);
859
860                 this.DDM.handleMouseDown(e, this);
861
862                 this.DDM.stopEvent(e);
863             } else {
864
865
866             }
867         }
868     },
869
870     clickValidator: function(e) {
871         var target = e.getTarget();
872         return ( this.isValidHandleChild(target) &&
873                     (this.id == this.handleElId ||
874                         this.DDM.handleWasClicked(target, this.id)) );
875     },
876
877     /**
878      * Allows you to specify a tag name that should not start a drag operation
879      * when clicked.  This is designed to facilitate embedding links within a
880      * drag handle that do something other than start the drag.
881      * @method addInvalidHandleType
882      * @param {string} tagName the type of element to exclude
883      */
884     addInvalidHandleType: function(tagName) {
885         var type = tagName.toUpperCase();
886         this.invalidHandleTypes[type] = type;
887     },
888
889     /**
890      * Lets you to specify an element id for a child of a drag handle
891      * that should not initiate a drag
892      * @method addInvalidHandleId
893      * @param {string} id the element id of the element you wish to ignore
894      */
895     addInvalidHandleId: function(id) {
896         if (typeof id !== "string") {
897             id = Ext.id(id);
898         }
899         this.invalidHandleIds[id] = id;
900     },
901
902     /**
903      * Lets you specify a css class of elements that will not initiate a drag
904      * @method addInvalidHandleClass
905      * @param {string} cssClass the class of the elements you wish to ignore
906      */
907     addInvalidHandleClass: function(cssClass) {
908         this.invalidHandleClasses.push(cssClass);
909     },
910
911     /**
912      * Unsets an excluded tag name set by addInvalidHandleType
913      * @method removeInvalidHandleType
914      * @param {string} tagName the type of element to unexclude
915      */
916     removeInvalidHandleType: function(tagName) {
917         var type = tagName.toUpperCase();
918         // this.invalidHandleTypes[type] = null;
919         delete this.invalidHandleTypes[type];
920     },
921
922     /**
923      * Unsets an invalid handle id
924      * @method removeInvalidHandleId
925      * @param {string} id the id of the element to re-enable
926      */
927     removeInvalidHandleId: function(id) {
928         if (typeof id !== "string") {
929             id = Ext.id(id);
930         }
931         delete this.invalidHandleIds[id];
932     },
933
934     /**
935      * Unsets an invalid css class
936      * @method removeInvalidHandleClass
937      * @param {string} cssClass the class of the element(s) you wish to
938      * re-enable
939      */
940     removeInvalidHandleClass: function(cssClass) {
941         for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
942             if (this.invalidHandleClasses[i] == cssClass) {
943                 delete this.invalidHandleClasses[i];
944             }
945         }
946     },
947
948     /**
949      * Checks the tag exclusion list to see if this click should be ignored
950      * @method isValidHandleChild
951      * @param {HTMLElement} node the HTMLElement to evaluate
952      * @return {boolean} true if this is a valid tag type, false if not
953      */
954     isValidHandleChild: function(node) {
955
956         var valid = true;
957         // var n = (node.nodeName == "#text") ? node.parentNode : node;
958         var nodeName;
959         try {
960             nodeName = node.nodeName.toUpperCase();
961         } catch(e) {
962             nodeName = node.nodeName;
963         }
964         valid = valid && !this.invalidHandleTypes[nodeName];
965         valid = valid && !this.invalidHandleIds[node.id];
966
967         for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
968             valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]);
969         }
970
971
972         return valid;
973
974     },
975
976     /**
977      * Create the array of horizontal tick marks if an interval was specified
978      * in setXConstraint().
979      * @method setXTicks
980      * @private
981      */
982     setXTicks: function(iStartX, iTickSize) {
983         this.xTicks = [];
984         this.xTickSize = iTickSize;
985
986         var tickMap = {};
987
988         for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
989             if (!tickMap[i]) {
990                 this.xTicks[this.xTicks.length] = i;
991                 tickMap[i] = true;
992             }
993         }
994
995         for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
996             if (!tickMap[i]) {
997                 this.xTicks[this.xTicks.length] = i;
998                 tickMap[i] = true;
999             }
1000         }
1001
1002         this.xTicks.sort(this.DDM.numericSort) ;
1003     },
1004
1005     /**
1006      * Create the array of vertical tick marks if an interval was specified in
1007      * setYConstraint().
1008      * @method setYTicks
1009      * @private
1010      */
1011     setYTicks: function(iStartY, iTickSize) {
1012         this.yTicks = [];
1013         this.yTickSize = iTickSize;
1014
1015         var tickMap = {};
1016
1017         for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1018             if (!tickMap[i]) {
1019                 this.yTicks[this.yTicks.length] = i;
1020                 tickMap[i] = true;
1021             }
1022         }
1023
1024         for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1025             if (!tickMap[i]) {
1026                 this.yTicks[this.yTicks.length] = i;
1027                 tickMap[i] = true;
1028             }
1029         }
1030
1031         this.yTicks.sort(this.DDM.numericSort) ;
1032     },
1033
1034     /**
1035      * By default, the element can be dragged any place on the screen.  Use
1036      * this method to limit the horizontal travel of the element.  Pass in
1037      * 0,0 for the parameters if you want to lock the drag to the y axis.
1038      * @method setXConstraint
1039      * @param {int} iLeft the number of pixels the element can move to the left
1040      * @param {int} iRight the number of pixels the element can move to the
1041      * right
1042      * @param {int} iTickSize optional parameter for specifying that the
1043      * element
1044      * should move iTickSize pixels at a time.
1045      */
1046     setXConstraint: function(iLeft, iRight, iTickSize) {
1047         this.leftConstraint = iLeft;
1048         this.rightConstraint = iRight;
1049
1050         this.minX = this.initPageX - iLeft;
1051         this.maxX = this.initPageX + iRight;
1052         if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1053
1054         this.constrainX = true;
1055     },
1056
1057     /**
1058      * Clears any constraints applied to this instance.  Also clears ticks
1059      * since they can't exist independent of a constraint at this time.
1060      * @method clearConstraints
1061      */
1062     clearConstraints: function() {
1063         this.constrainX = false;
1064         this.constrainY = false;
1065         this.clearTicks();
1066     },
1067
1068     /**
1069      * Clears any tick interval defined for this instance
1070      * @method clearTicks
1071      */
1072     clearTicks: function() {
1073         this.xTicks = null;
1074         this.yTicks = null;
1075         this.xTickSize = 0;
1076         this.yTickSize = 0;
1077     },
1078
1079     /**
1080      * By default, the element can be dragged any place on the screen.  Set
1081      * this to limit the vertical travel of the element.  Pass in 0,0 for the
1082      * parameters if you want to lock the drag to the x axis.
1083      * @method setYConstraint
1084      * @param {int} iUp the number of pixels the element can move up
1085      * @param {int} iDown the number of pixels the element can move down
1086      * @param {int} iTickSize optional parameter for specifying that the
1087      * element should move iTickSize pixels at a time.
1088      */
1089     setYConstraint: function(iUp, iDown, iTickSize) {
1090         this.topConstraint = iUp;
1091         this.bottomConstraint = iDown;
1092
1093         this.minY = this.initPageY - iUp;
1094         this.maxY = this.initPageY + iDown;
1095         if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1096
1097         this.constrainY = true;
1098
1099     },
1100
1101     /**
1102      * resetConstraints must be called if you manually reposition a dd element.
1103      * @method resetConstraints
1104      * @param {boolean} maintainOffset
1105      */
1106     resetConstraints: function() {
1107
1108
1109         // Maintain offsets if necessary
1110         if (this.initPageX || this.initPageX === 0) {
1111             // figure out how much this thing has moved
1112             var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
1113             var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
1114
1115             this.setInitPosition(dx, dy);
1116
1117         // This is the first time we have detected the element's position
1118         } else {
1119             this.setInitPosition();
1120         }
1121
1122         if (this.constrainX) {
1123             this.setXConstraint( this.leftConstraint,
1124                                  this.rightConstraint,
1125                                  this.xTickSize        );
1126         }
1127
1128         if (this.constrainY) {
1129             this.setYConstraint( this.topConstraint,
1130                                  this.bottomConstraint,
1131                                  this.yTickSize         );
1132         }
1133     },
1134
1135     /**
1136      * Normally the drag element is moved pixel by pixel, but we can specify
1137      * that it move a number of pixels at a time.  This method resolves the
1138      * location when we have it set up like this.
1139      * @method getTick
1140      * @param {int} val where we want to place the object
1141      * @param {int[]} tickArray sorted array of valid points
1142      * @return {int} the closest tick
1143      * @private
1144      */
1145     getTick: function(val, tickArray) {
1146
1147         if (!tickArray) {
1148             // If tick interval is not defined, it is effectively 1 pixel,
1149             // so we return the value passed to us.
1150             return val;
1151         } else if (tickArray[0] >= val) {
1152             // The value is lower than the first tick, so we return the first
1153             // tick.
1154             return tickArray[0];
1155         } else {
1156             for (var i=0, len=tickArray.length; i<len; ++i) {
1157                 var next = i + 1;
1158                 if (tickArray[next] && tickArray[next] >= val) {
1159                     var diff1 = val - tickArray[i];
1160                     var diff2 = tickArray[next] - val;
1161                     return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1162                 }
1163             }
1164
1165             // The value is larger than the last tick, so we return the last
1166             // tick.
1167             return tickArray[tickArray.length - 1];
1168         }
1169     },
1170
1171     /**
1172      * toString method
1173      * @method toString
1174      * @return {string} string representation of the dd obj
1175      */
1176     toString: function() {
1177         return ("DragDrop " + this.id);
1178     }
1179
1180 };
1181
1182 })();
1183 /**
1184  * The drag and drop utility provides a framework for building drag and drop
1185  * applications.  In addition to enabling drag and drop for specific elements,
1186  * the drag and drop elements are tracked by the manager class, and the
1187  * interactions between the various elements are tracked during the drag and
1188  * the implementing code is notified about these important moments.
1189  */
1190
1191 // Only load the library once.  Rewriting the manager class would orphan
1192 // existing drag and drop instances.
1193 if (!Ext.dd.DragDropMgr) {
1194
1195 /**
1196  * @class Ext.dd.DragDropMgr
1197  * DragDropMgr is a singleton that tracks the element interaction for
1198  * all DragDrop items in the window.  Generally, you will not call
1199  * this class directly, but it does have helper methods that could
1200  * be useful in your DragDrop implementations.
1201  * @singleton
1202  */
1203 Ext.dd.DragDropMgr = function() {
1204
1205     var Event = Ext.EventManager;
1206
1207     return {
1208
1209         /**
1210          * Two dimensional Array of registered DragDrop objects.  The first
1211          * dimension is the DragDrop item group, the second the DragDrop
1212          * object.
1213          * @property ids
1214          * @type {string: string}
1215          * @private
1216          * @static
1217          */
1218         ids: {},
1219
1220         /**
1221          * Array of element ids defined as drag handles.  Used to determine
1222          * if the element that generated the mousedown event is actually the
1223          * handle and not the html element itself.
1224          * @property handleIds
1225          * @type {string: string}
1226          * @private
1227          * @static
1228          */
1229         handleIds: {},
1230
1231         /**
1232          * the DragDrop object that is currently being dragged
1233          * @property dragCurrent
1234          * @type DragDrop
1235          * @private
1236          * @static
1237          **/
1238         dragCurrent: null,
1239
1240         /**
1241          * the DragDrop object(s) that are being hovered over
1242          * @property dragOvers
1243          * @type Array
1244          * @private
1245          * @static
1246          */
1247         dragOvers: {},
1248
1249         /**
1250          * the X distance between the cursor and the object being dragged
1251          * @property deltaX
1252          * @type int
1253          * @private
1254          * @static
1255          */
1256         deltaX: 0,
1257
1258         /**
1259          * the Y distance between the cursor and the object being dragged
1260          * @property deltaY
1261          * @type int
1262          * @private
1263          * @static
1264          */
1265         deltaY: 0,
1266
1267         /**
1268          * Flag to determine if we should prevent the default behavior of the
1269          * events we define. By default this is true, but this can be set to
1270          * false if you need the default behavior (not recommended)
1271          * @property preventDefault
1272          * @type boolean
1273          * @static
1274          */
1275         preventDefault: true,
1276
1277         /**
1278          * Flag to determine if we should stop the propagation of the events
1279          * we generate. This is true by default but you may want to set it to
1280          * false if the html element contains other features that require the
1281          * mouse click.
1282          * @property stopPropagation
1283          * @type boolean
1284          * @static
1285          */
1286         stopPropagation: true,
1287
1288         /**
1289          * Internal flag that is set to true when drag and drop has been
1290          * intialized
1291          * @property initialized
1292          * @private
1293          * @static
1294          */
1295         initialized: false,
1296
1297         /**
1298          * All drag and drop can be disabled.
1299          * @property locked
1300          * @private
1301          * @static
1302          */
1303         locked: false,
1304
1305         /**
1306          * Called the first time an element is registered.
1307          * @method init
1308          * @private
1309          * @static
1310          */
1311         init: function() {
1312             this.initialized = true;
1313         },
1314
1315         /**
1316          * In point mode, drag and drop interaction is defined by the
1317          * location of the cursor during the drag/drop
1318          * @property POINT
1319          * @type int
1320          * @static
1321          */
1322         POINT: 0,
1323
1324         /**
1325          * In intersect mode, drag and drop interaction is defined by the
1326          * overlap of two or more drag and drop objects.
1327          * @property INTERSECT
1328          * @type int
1329          * @static
1330          */
1331         INTERSECT: 1,
1332
1333         /**
1334          * The current drag and drop mode.  Default: POINT
1335          * @property mode
1336          * @type int
1337          * @static
1338          */
1339         mode: 0,
1340
1341         /**
1342          * Runs method on all drag and drop objects
1343          * @method _execOnAll
1344          * @private
1345          * @static
1346          */
1347         _execOnAll: function(sMethod, args) {
1348             for (var i in this.ids) {
1349                 for (var j in this.ids[i]) {
1350                     var oDD = this.ids[i][j];
1351                     if (! this.isTypeOfDD(oDD)) {
1352                         continue;
1353                     }
1354                     oDD[sMethod].apply(oDD, args);
1355                 }
1356             }
1357         },
1358
1359         /**
1360          * Drag and drop initialization.  Sets up the global event handlers
1361          * @method _onLoad
1362          * @private
1363          * @static
1364          */
1365         _onLoad: function() {
1366
1367             this.init();
1368
1369
1370             Event.on(document, "mouseup",   this.handleMouseUp, this, true);
1371             Event.on(document, "mousemove", this.handleMouseMove, this, true);
1372             Event.on(window,   "unload",    this._onUnload, this, true);
1373             Event.on(window,   "resize",    this._onResize, this, true);
1374             // Event.on(window,   "mouseout",    this._test);
1375
1376         },
1377
1378         /**
1379          * Reset constraints on all drag and drop objs
1380          * @method _onResize
1381          * @private
1382          * @static
1383          */
1384         _onResize: function(e) {
1385             this._execOnAll("resetConstraints", []);
1386         },
1387
1388         /**
1389          * Lock all drag and drop functionality
1390          * @method lock
1391          * @static
1392          */
1393         lock: function() { this.locked = true; },
1394
1395         /**
1396          * Unlock all drag and drop functionality
1397          * @method unlock
1398          * @static
1399          */
1400         unlock: function() { this.locked = false; },
1401
1402         /**
1403          * Is drag and drop locked?
1404          * @method isLocked
1405          * @return {boolean} True if drag and drop is locked, false otherwise.
1406          * @static
1407          */
1408         isLocked: function() { return this.locked; },
1409
1410         /**
1411          * Location cache that is set for all drag drop objects when a drag is
1412          * initiated, cleared when the drag is finished.
1413          * @property locationCache
1414          * @private
1415          * @static
1416          */
1417         locationCache: {},
1418
1419         /**
1420          * Set useCache to false if you want to force object the lookup of each
1421          * drag and drop linked element constantly during a drag.
1422          * @property useCache
1423          * @type boolean
1424          * @static
1425          */
1426         useCache: true,
1427
1428         /**
1429          * The number of pixels that the mouse needs to move after the
1430          * mousedown before the drag is initiated.  Default=3;
1431          * @property clickPixelThresh
1432          * @type int
1433          * @static
1434          */
1435         clickPixelThresh: 3,
1436
1437         /**
1438          * The number of milliseconds after the mousedown event to initiate the
1439          * drag if we don't get a mouseup event. Default=1000
1440          * @property clickTimeThresh
1441          * @type int
1442          * @static
1443          */
1444         clickTimeThresh: 350,
1445
1446         /**
1447          * Flag that indicates that either the drag pixel threshold or the
1448          * mousdown time threshold has been met
1449          * @property dragThreshMet
1450          * @type boolean
1451          * @private
1452          * @static
1453          */
1454         dragThreshMet: false,
1455
1456         /**
1457          * Timeout used for the click time threshold
1458          * @property clickTimeout
1459          * @type Object
1460          * @private
1461          * @static
1462          */
1463         clickTimeout: null,
1464
1465         /**
1466          * The X position of the mousedown event stored for later use when a
1467          * drag threshold is met.
1468          * @property startX
1469          * @type int
1470          * @private
1471          * @static
1472          */
1473         startX: 0,
1474
1475         /**
1476          * The Y position of the mousedown event stored for later use when a
1477          * drag threshold is met.
1478          * @property startY
1479          * @type int
1480          * @private
1481          * @static
1482          */
1483         startY: 0,
1484
1485         /**
1486          * Each DragDrop instance must be registered with the DragDropMgr.
1487          * This is executed in DragDrop.init()
1488          * @method regDragDrop
1489          * @param {DragDrop} oDD the DragDrop object to register
1490          * @param {String} sGroup the name of the group this element belongs to
1491          * @static
1492          */
1493         regDragDrop: function(oDD, sGroup) {
1494             if (!this.initialized) { this.init(); }
1495
1496             if (!this.ids[sGroup]) {
1497                 this.ids[sGroup] = {};
1498             }
1499             this.ids[sGroup][oDD.id] = oDD;
1500         },
1501
1502         /**
1503          * Removes the supplied dd instance from the supplied group. Executed
1504          * by DragDrop.removeFromGroup, so don't call this function directly.
1505          * @method removeDDFromGroup
1506          * @private
1507          * @static
1508          */
1509         removeDDFromGroup: function(oDD, sGroup) {
1510             if (!this.ids[sGroup]) {
1511                 this.ids[sGroup] = {};
1512             }
1513
1514             var obj = this.ids[sGroup];
1515             if (obj && obj[oDD.id]) {
1516                 delete obj[oDD.id];
1517             }
1518         },
1519
1520         /**
1521          * Unregisters a drag and drop item.  This is executed in
1522          * DragDrop.unreg, use that method instead of calling this directly.
1523          * @method _remove
1524          * @private
1525          * @static
1526          */
1527         _remove: function(oDD) {
1528             for (var g in oDD.groups) {
1529                 if (g && this.ids[g] && this.ids[g][oDD.id]) {
1530                     delete this.ids[g][oDD.id];
1531                 }
1532             }
1533             delete this.handleIds[oDD.id];
1534         },
1535
1536         /**
1537          * Each DragDrop handle element must be registered.  This is done
1538          * automatically when executing DragDrop.setHandleElId()
1539          * @method regHandle
1540          * @param {String} sDDId the DragDrop id this element is a handle for
1541          * @param {String} sHandleId the id of the element that is the drag
1542          * handle
1543          * @static
1544          */
1545         regHandle: function(sDDId, sHandleId) {
1546             if (!this.handleIds[sDDId]) {
1547                 this.handleIds[sDDId] = {};
1548             }
1549             this.handleIds[sDDId][sHandleId] = sHandleId;
1550         },
1551
1552         /**
1553          * Utility function to determine if a given element has been
1554          * registered as a drag drop item.
1555          * @method isDragDrop
1556          * @param {String} id the element id to check
1557          * @return {boolean} true if this element is a DragDrop item,
1558          * false otherwise
1559          * @static
1560          */
1561         isDragDrop: function(id) {
1562             return ( this.getDDById(id) ) ? true : false;
1563         },
1564
1565         /**
1566          * Returns the drag and drop instances that are in all groups the
1567          * passed in instance belongs to.
1568          * @method getRelated
1569          * @param {DragDrop} p_oDD the obj to get related data for
1570          * @param {boolean} bTargetsOnly if true, only return targetable objs
1571          * @return {DragDrop[]} the related instances
1572          * @static
1573          */
1574         getRelated: function(p_oDD, bTargetsOnly) {
1575             var oDDs = [];
1576             for (var i in p_oDD.groups) {
1577                 for (var j in this.ids[i]) {
1578                     var dd = this.ids[i][j];
1579                     if (! this.isTypeOfDD(dd)) {
1580                         continue;
1581                     }
1582                     if (!bTargetsOnly || dd.isTarget) {
1583                         oDDs[oDDs.length] = dd;
1584                     }
1585                 }
1586             }
1587
1588             return oDDs;
1589         },
1590
1591         /**
1592          * Returns true if the specified dd target is a legal target for
1593          * the specifice drag obj
1594          * @method isLegalTarget
1595          * @param {DragDrop} the drag obj
1596          * @param {DragDrop} the target
1597          * @return {boolean} true if the target is a legal target for the
1598          * dd obj
1599          * @static
1600          */
1601         isLegalTarget: function (oDD, oTargetDD) {
1602             var targets = this.getRelated(oDD, true);
1603             for (var i=0, len=targets.length;i<len;++i) {
1604                 if (targets[i].id == oTargetDD.id) {
1605                     return true;
1606                 }
1607             }
1608
1609             return false;
1610         },
1611
1612         /**
1613          * My goal is to be able to transparently determine if an object is
1614          * typeof DragDrop, and the exact subclass of DragDrop.  typeof
1615          * returns "object", oDD.constructor.toString() always returns
1616          * "DragDrop" and not the name of the subclass.  So for now it just
1617          * evaluates a well-known variable in DragDrop.
1618          * @method isTypeOfDD
1619          * @param {Object} the object to evaluate
1620          * @return {boolean} true if typeof oDD = DragDrop
1621          * @static
1622          */
1623         isTypeOfDD: function (oDD) {
1624             return (oDD && oDD.__ygDragDrop);
1625         },
1626
1627         /**
1628          * Utility function to determine if a given element has been
1629          * registered as a drag drop handle for the given Drag Drop object.
1630          * @method isHandle
1631          * @param {String} id the element id to check
1632          * @return {boolean} true if this element is a DragDrop handle, false
1633          * otherwise
1634          * @static
1635          */
1636         isHandle: function(sDDId, sHandleId) {
1637             return ( this.handleIds[sDDId] &&
1638                             this.handleIds[sDDId][sHandleId] );
1639         },
1640
1641         /**
1642          * Returns the DragDrop instance for a given id
1643          * @method getDDById
1644          * @param {String} id the id of the DragDrop object
1645          * @return {DragDrop} the drag drop object, null if it is not found
1646          * @static
1647          */
1648         getDDById: function(id) {
1649             for (var i in this.ids) {
1650                 if (this.ids[i][id]) {
1651                     return this.ids[i][id];
1652                 }
1653             }
1654             return null;
1655         },
1656
1657         /**
1658          * Fired after a registered DragDrop object gets the mousedown event.
1659          * Sets up the events required to track the object being dragged
1660          * @method handleMouseDown
1661          * @param {Event} e the event
1662          * @param oDD the DragDrop object being dragged
1663          * @private
1664          * @static
1665          */
1666         handleMouseDown: function(e, oDD) {
1667             if(Ext.QuickTips){
1668                 Ext.QuickTips.disable();
1669             }
1670             if(this.dragCurrent){
1671                 // the original browser mouseup wasn't handled (e.g. outside FF browser window)
1672                 // so clean up first to avoid breaking the next drag
1673                 this.handleMouseUp(e);
1674             }
1675             
1676             this.currentTarget = e.getTarget();
1677             this.dragCurrent = oDD;
1678
1679             var el = oDD.getEl();
1680
1681             // track start position
1682             this.startX = e.getPageX();
1683             this.startY = e.getPageY();
1684
1685             this.deltaX = this.startX - el.offsetLeft;
1686             this.deltaY = this.startY - el.offsetTop;
1687
1688             this.dragThreshMet = false;
1689
1690             this.clickTimeout = setTimeout(
1691                     function() {
1692                         var DDM = Ext.dd.DDM;
1693                         DDM.startDrag(DDM.startX, DDM.startY);
1694                     },
1695                     this.clickTimeThresh );
1696         },
1697
1698         /**
1699          * Fired when either the drag pixel threshol or the mousedown hold
1700          * time threshold has been met.
1701          * @method startDrag
1702          * @param x {int} the X position of the original mousedown
1703          * @param y {int} the Y position of the original mousedown
1704          * @static
1705          */
1706         startDrag: function(x, y) {
1707             clearTimeout(this.clickTimeout);
1708             if (this.dragCurrent) {
1709                 this.dragCurrent.b4StartDrag(x, y);
1710                 this.dragCurrent.startDrag(x, y);
1711             }
1712             this.dragThreshMet = true;
1713         },
1714
1715         /**
1716          * Internal function to handle the mouseup event.  Will be invoked
1717          * from the context of the document.
1718          * @method handleMouseUp
1719          * @param {Event} e the event
1720          * @private
1721          * @static
1722          */
1723         handleMouseUp: function(e) {
1724
1725             if(Ext.QuickTips){
1726                 Ext.QuickTips.enable();
1727             }
1728             if (! this.dragCurrent) {
1729                 return;
1730             }
1731
1732             clearTimeout(this.clickTimeout);
1733
1734             if (this.dragThreshMet) {
1735                 this.fireEvents(e, true);
1736             } else {
1737             }
1738
1739             this.stopDrag(e);
1740
1741             this.stopEvent(e);
1742         },
1743
1744         /**
1745          * Utility to stop event propagation and event default, if these
1746          * features are turned on.
1747          * @method stopEvent
1748          * @param {Event} e the event as returned by this.getEvent()
1749          * @static
1750          */
1751         stopEvent: function(e){
1752             if(this.stopPropagation) {
1753                 e.stopPropagation();
1754             }
1755
1756             if (this.preventDefault) {
1757                 e.preventDefault();
1758             }
1759         },
1760
1761         /**
1762          * Internal function to clean up event handlers after the drag
1763          * operation is complete
1764          * @method stopDrag
1765          * @param {Event} e the event
1766          * @private
1767          * @static
1768          */
1769         stopDrag: function(e) {
1770             // Fire the drag end event for the item that was dragged
1771             if (this.dragCurrent) {
1772                 if (this.dragThreshMet) {
1773                     this.dragCurrent.b4EndDrag(e);
1774                     this.dragCurrent.endDrag(e);
1775                 }
1776
1777                 this.dragCurrent.onMouseUp(e);
1778             }
1779
1780             this.dragCurrent = null;
1781             this.dragOvers = {};
1782         },
1783
1784         /**
1785          * Internal function to handle the mousemove event.  Will be invoked
1786          * from the context of the html element.
1787          *
1788          * @TODO figure out what we can do about mouse events lost when the
1789          * user drags objects beyond the window boundary.  Currently we can
1790          * detect this in internet explorer by verifying that the mouse is
1791          * down during the mousemove event.  Firefox doesn't give us the
1792          * button state on the mousemove event.
1793          * @method handleMouseMove
1794          * @param {Event} e the event
1795          * @private
1796          * @static
1797          */
1798         handleMouseMove: function(e) {
1799             if (! this.dragCurrent) {
1800                 return true;
1801             }
1802             // var button = e.which || e.button;
1803
1804             // check for IE mouseup outside of page boundary
1805             if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1806                 this.stopEvent(e);
1807                 return this.handleMouseUp(e);
1808             }
1809
1810             if (!this.dragThreshMet) {
1811                 var diffX = Math.abs(this.startX - e.getPageX());
1812                 var diffY = Math.abs(this.startY - e.getPageY());
1813                 if (diffX > this.clickPixelThresh ||
1814                             diffY > this.clickPixelThresh) {
1815                     this.startDrag(this.startX, this.startY);
1816                 }
1817             }
1818
1819             if (this.dragThreshMet) {
1820                 this.dragCurrent.b4Drag(e);
1821                 this.dragCurrent.onDrag(e);
1822                 if(!this.dragCurrent.moveOnly){
1823                     this.fireEvents(e, false);
1824                 }
1825             }
1826
1827             this.stopEvent(e);
1828
1829             return true;
1830         },
1831
1832         /**
1833          * Iterates over all of the DragDrop elements to find ones we are
1834          * hovering over or dropping on
1835          * @method fireEvents
1836          * @param {Event} e the event
1837          * @param {boolean} isDrop is this a drop op or a mouseover op?
1838          * @private
1839          * @static
1840          */
1841         fireEvents: function(e, isDrop) {
1842             var dc = this.dragCurrent;
1843
1844             // If the user did the mouse up outside of the window, we could
1845             // get here even though we have ended the drag.
1846             if (!dc || dc.isLocked()) {
1847                 return;
1848             }
1849
1850             var pt = e.getPoint();
1851
1852             // cache the previous dragOver array
1853             var oldOvers = [];
1854
1855             var outEvts   = [];
1856             var overEvts  = [];
1857             var dropEvts  = [];
1858             var enterEvts = [];
1859
1860             // Check to see if the object(s) we were hovering over is no longer
1861             // being hovered over so we can fire the onDragOut event
1862             for (var i in this.dragOvers) {
1863
1864                 var ddo = this.dragOvers[i];
1865
1866                 if (! this.isTypeOfDD(ddo)) {
1867                     continue;
1868                 }
1869
1870                 if (! this.isOverTarget(pt, ddo, this.mode)) {
1871                     outEvts.push( ddo );
1872                 }
1873
1874                 oldOvers[i] = true;
1875                 delete this.dragOvers[i];
1876             }
1877
1878             for (var sGroup in dc.groups) {
1879
1880                 if ("string" != typeof sGroup) {
1881                     continue;
1882                 }
1883
1884                 for (i in this.ids[sGroup]) {
1885                     var oDD = this.ids[sGroup][i];
1886                     if (! this.isTypeOfDD(oDD)) {
1887                         continue;
1888                     }
1889
1890                     if (oDD.isTarget && !oDD.isLocked() && ((oDD != dc) || (dc.ignoreSelf === false))) {
1891                         if (this.isOverTarget(pt, oDD, this.mode)) {
1892                             // look for drop interactions
1893                             if (isDrop) {
1894                                 dropEvts.push( oDD );
1895                             // look for drag enter and drag over interactions
1896                             } else {
1897
1898                                 // initial drag over: dragEnter fires
1899                                 if (!oldOvers[oDD.id]) {
1900                                     enterEvts.push( oDD );
1901                                 // subsequent drag overs: dragOver fires
1902                                 } else {
1903                                     overEvts.push( oDD );
1904                                 }
1905
1906                                 this.dragOvers[oDD.id] = oDD;
1907                             }
1908                         }
1909                     }
1910                 }
1911             }
1912
1913             if (this.mode) {
1914                 if (outEvts.length) {
1915                     dc.b4DragOut(e, outEvts);
1916                     dc.onDragOut(e, outEvts);
1917                 }
1918
1919                 if (enterEvts.length) {
1920                     dc.onDragEnter(e, enterEvts);
1921                 }
1922
1923                 if (overEvts.length) {
1924                     dc.b4DragOver(e, overEvts);
1925                     dc.onDragOver(e, overEvts);
1926                 }
1927
1928                 if (dropEvts.length) {
1929                     dc.b4DragDrop(e, dropEvts);
1930                     dc.onDragDrop(e, dropEvts);
1931                 }
1932
1933             } else {
1934                 // fire dragout events
1935                 var len = 0;
1936                 for (i=0, len=outEvts.length; i<len; ++i) {
1937                     dc.b4DragOut(e, outEvts[i].id);
1938                     dc.onDragOut(e, outEvts[i].id);
1939                 }
1940
1941                 // fire enter events
1942                 for (i=0,len=enterEvts.length; i<len; ++i) {
1943                     // dc.b4DragEnter(e, oDD.id);
1944                     dc.onDragEnter(e, enterEvts[i].id);
1945                 }
1946
1947                 // fire over events
1948                 for (i=0,len=overEvts.length; i<len; ++i) {
1949                     dc.b4DragOver(e, overEvts[i].id);
1950                     dc.onDragOver(e, overEvts[i].id);
1951                 }
1952
1953                 // fire drop events
1954                 for (i=0, len=dropEvts.length; i<len; ++i) {
1955                     dc.b4DragDrop(e, dropEvts[i].id);
1956                     dc.onDragDrop(e, dropEvts[i].id);
1957                 }
1958
1959             }
1960
1961             // notify about a drop that did not find a target
1962             if (isDrop && !dropEvts.length) {
1963                 dc.onInvalidDrop(e);
1964             }
1965
1966         },
1967
1968         /**
1969          * Helper function for getting the best match from the list of drag
1970          * and drop objects returned by the drag and drop events when we are
1971          * in INTERSECT mode.  It returns either the first object that the
1972          * cursor is over, or the object that has the greatest overlap with
1973          * the dragged element.
1974          * @method getBestMatch
1975          * @param  {DragDrop[]} dds The array of drag and drop objects
1976          * targeted
1977          * @return {DragDrop}       The best single match
1978          * @static
1979          */
1980         getBestMatch: function(dds) {
1981             var winner = null;
1982             // Return null if the input is not what we expect
1983             //if (!dds || !dds.length || dds.length == 0) {
1984                // winner = null;
1985             // If there is only one item, it wins
1986             //} else if (dds.length == 1) {
1987
1988             var len = dds.length;
1989
1990             if (len == 1) {
1991                 winner = dds[0];
1992             } else {
1993                 // Loop through the targeted items
1994                 for (var i=0; i<len; ++i) {
1995                     var dd = dds[i];
1996                     // If the cursor is over the object, it wins.  If the
1997                     // cursor is over multiple matches, the first one we come
1998                     // to wins.
1999                     if (dd.cursorIsOver) {
2000                         winner = dd;
2001                         break;
2002                     // Otherwise the object with the most overlap wins
2003                     } else {
2004                         if (!winner ||
2005                             winner.overlap.getArea() < dd.overlap.getArea()) {
2006                             winner = dd;
2007                         }
2008                     }
2009                 }
2010             }
2011
2012             return winner;
2013         },
2014
2015         /**
2016          * Refreshes the cache of the top-left and bottom-right points of the
2017          * drag and drop objects in the specified group(s).  This is in the
2018          * format that is stored in the drag and drop instance, so typical
2019          * usage is:
2020          * <code>
2021          * Ext.dd.DragDropMgr.refreshCache(ddinstance.groups);
2022          * </code>
2023          * Alternatively:
2024          * <code>
2025          * Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2026          * </code>
2027          * @TODO this really should be an indexed array.  Alternatively this
2028          * method could accept both.
2029          * @method refreshCache
2030          * @param {Object} groups an associative array of groups to refresh
2031          * @static
2032          */
2033         refreshCache: function(groups) {
2034             for (var sGroup in groups) {
2035                 if ("string" != typeof sGroup) {
2036                     continue;
2037                 }
2038                 for (var i in this.ids[sGroup]) {
2039                     var oDD = this.ids[sGroup][i];
2040
2041                     if (this.isTypeOfDD(oDD)) {
2042                     // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2043                         var loc = this.getLocation(oDD);
2044                         if (loc) {
2045                             this.locationCache[oDD.id] = loc;
2046                         } else {
2047                             delete this.locationCache[oDD.id];
2048                             // this will unregister the drag and drop object if
2049                             // the element is not in a usable state
2050                             // oDD.unreg();
2051                         }
2052                     }
2053                 }
2054             }
2055         },
2056
2057         /**
2058          * This checks to make sure an element exists and is in the DOM.  The
2059          * main purpose is to handle cases where innerHTML is used to remove
2060          * drag and drop objects from the DOM.  IE provides an 'unspecified
2061          * error' when trying to access the offsetParent of such an element
2062          * @method verifyEl
2063          * @param {HTMLElement} el the element to check
2064          * @return {boolean} true if the element looks usable
2065          * @static
2066          */
2067         verifyEl: function(el) {
2068             if (el) {
2069                 var parent;
2070                 if(Ext.isIE){
2071                     try{
2072                         parent = el.offsetParent;
2073                     }catch(e){}
2074                 }else{
2075                     parent = el.offsetParent;
2076                 }
2077                 if (parent) {
2078                     return true;
2079                 }
2080             }
2081
2082             return false;
2083         },
2084
2085         /**
2086          * Returns a Region object containing the drag and drop element's position
2087          * and size, including the padding configured for it
2088          * @method getLocation
2089          * @param {DragDrop} oDD the drag and drop object to get the
2090          *                       location for
2091          * @return {Ext.lib.Region} a Region object representing the total area
2092          *                             the element occupies, including any padding
2093          *                             the instance is configured for.
2094          * @static
2095          */
2096         getLocation: function(oDD) {
2097             if (! this.isTypeOfDD(oDD)) {
2098                 return null;
2099             }
2100
2101             var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2102
2103             try {
2104                 pos= Ext.lib.Dom.getXY(el);
2105             } catch (e) { }
2106
2107             if (!pos) {
2108                 return null;
2109             }
2110
2111             x1 = pos[0];
2112             x2 = x1 + el.offsetWidth;
2113             y1 = pos[1];
2114             y2 = y1 + el.offsetHeight;
2115
2116             t = y1 - oDD.padding[0];
2117             r = x2 + oDD.padding[1];
2118             b = y2 + oDD.padding[2];
2119             l = x1 - oDD.padding[3];
2120
2121             return new Ext.lib.Region( t, r, b, l );
2122         },
2123
2124         /**
2125          * Checks the cursor location to see if it over the target
2126          * @method isOverTarget
2127          * @param {Ext.lib.Point} pt The point to evaluate
2128          * @param {DragDrop} oTarget the DragDrop object we are inspecting
2129          * @return {boolean} true if the mouse is over the target
2130          * @private
2131          * @static
2132          */
2133         isOverTarget: function(pt, oTarget, intersect) {
2134             // use cache if available
2135             var loc = this.locationCache[oTarget.id];
2136             if (!loc || !this.useCache) {
2137                 loc = this.getLocation(oTarget);
2138                 this.locationCache[oTarget.id] = loc;
2139
2140             }
2141
2142             if (!loc) {
2143                 return false;
2144             }
2145
2146             oTarget.cursorIsOver = loc.contains( pt );
2147
2148             // DragDrop is using this as a sanity check for the initial mousedown
2149             // in this case we are done.  In POINT mode, if the drag obj has no
2150             // contraints, we are also done. Otherwise we need to evaluate the
2151             // location of the target as related to the actual location of the
2152             // dragged element.
2153             var dc = this.dragCurrent;
2154             if (!dc || !dc.getTargetCoord ||
2155                     (!intersect && !dc.constrainX && !dc.constrainY)) {
2156                 return oTarget.cursorIsOver;
2157             }
2158
2159             oTarget.overlap = null;
2160
2161             // Get the current location of the drag element, this is the
2162             // location of the mouse event less the delta that represents
2163             // where the original mousedown happened on the element.  We
2164             // need to consider constraints and ticks as well.
2165             var pos = dc.getTargetCoord(pt.x, pt.y);
2166
2167             var el = dc.getDragEl();
2168             var curRegion = new Ext.lib.Region( pos.y,
2169                                                    pos.x + el.offsetWidth,
2170                                                    pos.y + el.offsetHeight,
2171                                                    pos.x );
2172
2173             var overlap = curRegion.intersect(loc);
2174
2175             if (overlap) {
2176                 oTarget.overlap = overlap;
2177                 return (intersect) ? true : oTarget.cursorIsOver;
2178             } else {
2179                 return false;
2180             }
2181         },
2182
2183         /**
2184          * unload event handler
2185          * @method _onUnload
2186          * @private
2187          * @static
2188          */
2189         _onUnload: function(e, me) {
2190             Ext.dd.DragDropMgr.unregAll();
2191         },
2192
2193         /**
2194          * Cleans up the drag and drop events and objects.
2195          * @method unregAll
2196          * @private
2197          * @static
2198          */
2199         unregAll: function() {
2200
2201             if (this.dragCurrent) {
2202                 this.stopDrag();
2203                 this.dragCurrent = null;
2204             }
2205
2206             this._execOnAll("unreg", []);
2207
2208             for (var i in this.elementCache) {
2209                 delete this.elementCache[i];
2210             }
2211
2212             this.elementCache = {};
2213             this.ids = {};
2214         },
2215
2216         /**
2217          * A cache of DOM elements
2218          * @property elementCache
2219          * @private
2220          * @static
2221          */
2222         elementCache: {},
2223
2224         /**
2225          * Get the wrapper for the DOM element specified
2226          * @method getElWrapper
2227          * @param {String} id the id of the element to get
2228          * @return {Ext.dd.DDM.ElementWrapper} the wrapped element
2229          * @private
2230          * @deprecated This wrapper isn't that useful
2231          * @static
2232          */
2233         getElWrapper: function(id) {
2234             var oWrapper = this.elementCache[id];
2235             if (!oWrapper || !oWrapper.el) {
2236                 oWrapper = this.elementCache[id] =
2237                     new this.ElementWrapper(Ext.getDom(id));
2238             }
2239             return oWrapper;
2240         },
2241
2242         /**
2243          * Returns the actual DOM element
2244          * @method getElement
2245          * @param {String} id the id of the elment to get
2246          * @return {Object} The element
2247          * @deprecated use Ext.lib.Ext.getDom instead
2248          * @static
2249          */
2250         getElement: function(id) {
2251             return Ext.getDom(id);
2252         },
2253
2254         /**
2255          * Returns the style property for the DOM element (i.e.,
2256          * document.getElById(id).style)
2257          * @method getCss
2258          * @param {String} id the id of the elment to get
2259          * @return {Object} The style property of the element
2260          * @deprecated use Ext.lib.Dom instead
2261          * @static
2262          */
2263         getCss: function(id) {
2264             var el = Ext.getDom(id);
2265             return (el) ? el.style : null;
2266         },
2267
2268         /**
2269          * Inner class for cached elements
2270          * @class DragDropMgr.ElementWrapper
2271          * @for DragDropMgr
2272          * @private
2273          * @deprecated
2274          */
2275         ElementWrapper: function(el) {
2276                 /**
2277                  * The element
2278                  * @property el
2279                  */
2280                 this.el = el || null;
2281                 /**
2282                  * The element id
2283                  * @property id
2284                  */
2285                 this.id = this.el && el.id;
2286                 /**
2287                  * A reference to the style property
2288                  * @property css
2289                  */
2290                 this.css = this.el && el.style;
2291             },
2292
2293         /**
2294          * Returns the X position of an html element
2295          * @method getPosX
2296          * @param el the element for which to get the position
2297          * @return {int} the X coordinate
2298          * @for DragDropMgr
2299          * @deprecated use Ext.lib.Dom.getX instead
2300          * @static
2301          */
2302         getPosX: function(el) {
2303             return Ext.lib.Dom.getX(el);
2304         },
2305
2306         /**
2307          * Returns the Y position of an html element
2308          * @method getPosY
2309          * @param el the element for which to get the position
2310          * @return {int} the Y coordinate
2311          * @deprecated use Ext.lib.Dom.getY instead
2312          * @static
2313          */
2314         getPosY: function(el) {
2315             return Ext.lib.Dom.getY(el);
2316         },
2317
2318         /**
2319          * Swap two nodes.  In IE, we use the native method, for others we
2320          * emulate the IE behavior
2321          * @method swapNode
2322          * @param n1 the first node to swap
2323          * @param n2 the other node to swap
2324          * @static
2325          */
2326         swapNode: function(n1, n2) {
2327             if (n1.swapNode) {
2328                 n1.swapNode(n2);
2329             } else {
2330                 var p = n2.parentNode;
2331                 var s = n2.nextSibling;
2332
2333                 if (s == n1) {
2334                     p.insertBefore(n1, n2);
2335                 } else if (n2 == n1.nextSibling) {
2336                     p.insertBefore(n2, n1);
2337                 } else {
2338                     n1.parentNode.replaceChild(n2, n1);
2339                     p.insertBefore(n1, s);
2340                 }
2341             }
2342         },
2343
2344         /**
2345          * Returns the current scroll position
2346          * @method getScroll
2347          * @private
2348          * @static
2349          */
2350         getScroll: function () {
2351             var t, l, dde=document.documentElement, db=document.body;
2352             if (dde && (dde.scrollTop || dde.scrollLeft)) {
2353                 t = dde.scrollTop;
2354                 l = dde.scrollLeft;
2355             } else if (db) {
2356                 t = db.scrollTop;
2357                 l = db.scrollLeft;
2358             } else {
2359
2360             }
2361             return { top: t, left: l };
2362         },
2363
2364         /**
2365          * Returns the specified element style property
2366          * @method getStyle
2367          * @param {HTMLElement} el          the element
2368          * @param {string}      styleProp   the style property
2369          * @return {string} The value of the style property
2370          * @deprecated use Ext.lib.Dom.getStyle
2371          * @static
2372          */
2373         getStyle: function(el, styleProp) {
2374             return Ext.fly(el).getStyle(styleProp);
2375         },
2376
2377         /**
2378          * Gets the scrollTop
2379          * @method getScrollTop
2380          * @return {int} the document's scrollTop
2381          * @static
2382          */
2383         getScrollTop: function () { return this.getScroll().top; },
2384
2385         /**
2386          * Gets the scrollLeft
2387          * @method getScrollLeft
2388          * @return {int} the document's scrollTop
2389          * @static
2390          */
2391         getScrollLeft: function () { return this.getScroll().left; },
2392
2393         /**
2394          * Sets the x/y position of an element to the location of the
2395          * target element.
2396          * @method moveToEl
2397          * @param {HTMLElement} moveEl      The element to move
2398          * @param {HTMLElement} targetEl    The position reference element
2399          * @static
2400          */
2401         moveToEl: function (moveEl, targetEl) {
2402             var aCoord = Ext.lib.Dom.getXY(targetEl);
2403             Ext.lib.Dom.setXY(moveEl, aCoord);
2404         },
2405
2406         /**
2407          * Numeric array sort function
2408          * @method numericSort
2409          * @static
2410          */
2411         numericSort: function(a, b) { return (a - b); },
2412
2413         /**
2414          * Internal counter
2415          * @property _timeoutCount
2416          * @private
2417          * @static
2418          */
2419         _timeoutCount: 0,
2420
2421         /**
2422          * Trying to make the load order less important.  Without this we get
2423          * an error if this file is loaded before the Event Utility.
2424          * @method _addListeners
2425          * @private
2426          * @static
2427          */
2428         _addListeners: function() {
2429             var DDM = Ext.dd.DDM;
2430             if ( Ext.lib.Event && document ) {
2431                 DDM._onLoad();
2432             } else {
2433                 if (DDM._timeoutCount > 2000) {
2434                 } else {
2435                     setTimeout(DDM._addListeners, 10);
2436                     if (document && document.body) {
2437                         DDM._timeoutCount += 1;
2438                     }
2439                 }
2440             }
2441         },
2442
2443         /**
2444          * Recursively searches the immediate parent and all child nodes for
2445          * the handle element in order to determine wheter or not it was
2446          * clicked.
2447          * @method handleWasClicked
2448          * @param node the html element to inspect
2449          * @static
2450          */
2451         handleWasClicked: function(node, id) {
2452             if (this.isHandle(id, node.id)) {
2453                 return true;
2454             } else {
2455                 // check to see if this is a text node child of the one we want
2456                 var p = node.parentNode;
2457
2458                 while (p) {
2459                     if (this.isHandle(id, p.id)) {
2460                         return true;
2461                     } else {
2462                         p = p.parentNode;
2463                     }
2464                 }
2465             }
2466
2467             return false;
2468         }
2469
2470     };
2471
2472 }();
2473
2474 // shorter alias, save a few bytes
2475 Ext.dd.DDM = Ext.dd.DragDropMgr;
2476 Ext.dd.DDM._addListeners();
2477
2478 }
2479
2480 /**
2481  * @class Ext.dd.DD
2482  * A DragDrop implementation where the linked element follows the
2483  * mouse cursor during a drag.
2484  * @extends Ext.dd.DragDrop
2485  * @constructor
2486  * @param {String} id the id of the linked element
2487  * @param {String} sGroup the group of related DragDrop items
2488  * @param {object} config an object containing configurable attributes
2489  *                Valid properties for DD:
2490  *                    scroll
2491  */
2492 Ext.dd.DD = function(id, sGroup, config) {
2493     if (id) {
2494         this.init(id, sGroup, config);
2495     }
2496 };
2497
2498 Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, {
2499
2500     /**
2501      * When set to true, the utility automatically tries to scroll the browser
2502      * window when a drag and drop element is dragged near the viewport boundary.
2503      * Defaults to true.
2504      * @property scroll
2505      * @type boolean
2506      */
2507     scroll: true,
2508
2509     /**
2510      * Sets the pointer offset to the distance between the linked element's top
2511      * left corner and the location the element was clicked
2512      * @method autoOffset
2513      * @param {int} iPageX the X coordinate of the click
2514      * @param {int} iPageY the Y coordinate of the click
2515      */
2516     autoOffset: function(iPageX, iPageY) {
2517         var x = iPageX - this.startPageX;
2518         var y = iPageY - this.startPageY;
2519         this.setDelta(x, y);
2520     },
2521
2522     /**
2523      * Sets the pointer offset.  You can call this directly to force the
2524      * offset to be in a particular location (e.g., pass in 0,0 to set it
2525      * to the center of the object)
2526      * @method setDelta
2527      * @param {int} iDeltaX the distance from the left
2528      * @param {int} iDeltaY the distance from the top
2529      */
2530     setDelta: function(iDeltaX, iDeltaY) {
2531         this.deltaX = iDeltaX;
2532         this.deltaY = iDeltaY;
2533     },
2534
2535     /**
2536      * Sets the drag element to the location of the mousedown or click event,
2537      * maintaining the cursor location relative to the location on the element
2538      * that was clicked.  Override this if you want to place the element in a
2539      * location other than where the cursor is.
2540      * @method setDragElPos
2541      * @param {int} iPageX the X coordinate of the mousedown or drag event
2542      * @param {int} iPageY the Y coordinate of the mousedown or drag event
2543      */
2544     setDragElPos: function(iPageX, iPageY) {
2545         // the first time we do this, we are going to check to make sure
2546         // the element has css positioning
2547
2548         var el = this.getDragEl();
2549         this.alignElWithMouse(el, iPageX, iPageY);
2550     },
2551
2552     /**
2553      * Sets the element to the location of the mousedown or click event,
2554      * maintaining the cursor location relative to the location on the element
2555      * that was clicked.  Override this if you want to place the element in a
2556      * location other than where the cursor is.
2557      * @method alignElWithMouse
2558      * @param {HTMLElement} el the element to move
2559      * @param {int} iPageX the X coordinate of the mousedown or drag event
2560      * @param {int} iPageY the Y coordinate of the mousedown or drag event
2561      */
2562     alignElWithMouse: function(el, iPageX, iPageY) {
2563         var oCoord = this.getTargetCoord(iPageX, iPageY);
2564         var fly = el.dom ? el : Ext.fly(el, '_dd');
2565         if (!this.deltaSetXY) {
2566             var aCoord = [oCoord.x, oCoord.y];
2567             fly.setXY(aCoord);
2568             var newLeft = fly.getLeft(true);
2569             var newTop  = fly.getTop(true);
2570             this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2571         } else {
2572             fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2573         }
2574
2575         this.cachePosition(oCoord.x, oCoord.y);
2576         this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2577         return oCoord;
2578     },
2579
2580     /**
2581      * Saves the most recent position so that we can reset the constraints and
2582      * tick marks on-demand.  We need to know this so that we can calculate the
2583      * number of pixels the element is offset from its original position.
2584      * @method cachePosition
2585      * @param iPageX the current x position (optional, this just makes it so we
2586      * don't have to look it up again)
2587      * @param iPageY the current y position (optional, this just makes it so we
2588      * don't have to look it up again)
2589      */
2590     cachePosition: function(iPageX, iPageY) {
2591         if (iPageX) {
2592             this.lastPageX = iPageX;
2593             this.lastPageY = iPageY;
2594         } else {
2595             var aCoord = Ext.lib.Dom.getXY(this.getEl());
2596             this.lastPageX = aCoord[0];
2597             this.lastPageY = aCoord[1];
2598         }
2599     },
2600
2601     /**
2602      * Auto-scroll the window if the dragged object has been moved beyond the
2603      * visible window boundary.
2604      * @method autoScroll
2605      * @param {int} x the drag element's x position
2606      * @param {int} y the drag element's y position
2607      * @param {int} h the height of the drag element
2608      * @param {int} w the width of the drag element
2609      * @private
2610      */
2611     autoScroll: function(x, y, h, w) {
2612
2613         if (this.scroll) {
2614             // The client height
2615             var clientH = Ext.lib.Dom.getViewHeight();
2616
2617             // The client width
2618             var clientW = Ext.lib.Dom.getViewWidth();
2619
2620             // The amt scrolled down
2621             var st = this.DDM.getScrollTop();
2622
2623             // The amt scrolled right
2624             var sl = this.DDM.getScrollLeft();
2625
2626             // Location of the bottom of the element
2627             var bot = h + y;
2628
2629             // Location of the right of the element
2630             var right = w + x;
2631
2632             // The distance from the cursor to the bottom of the visible area,
2633             // adjusted so that we don't scroll if the cursor is beyond the
2634             // element drag constraints
2635             var toBot = (clientH + st - y - this.deltaY);
2636
2637             // The distance from the cursor to the right of the visible area
2638             var toRight = (clientW + sl - x - this.deltaX);
2639
2640
2641             // How close to the edge the cursor must be before we scroll
2642             // var thresh = (document.all) ? 100 : 40;
2643             var thresh = 40;
2644
2645             // How many pixels to scroll per autoscroll op.  This helps to reduce
2646             // clunky scrolling. IE is more sensitive about this ... it needs this
2647             // value to be higher.
2648             var scrAmt = (document.all) ? 80 : 30;
2649
2650             // Scroll down if we are near the bottom of the visible page and the
2651             // obj extends below the crease
2652             if ( bot > clientH && toBot < thresh ) {
2653                 window.scrollTo(sl, st + scrAmt);
2654             }
2655
2656             // Scroll up if the window is scrolled down and the top of the object
2657             // goes above the top border
2658             if ( y < st && st > 0 && y - st < thresh ) {
2659                 window.scrollTo(sl, st - scrAmt);
2660             }
2661
2662             // Scroll right if the obj is beyond the right border and the cursor is
2663             // near the border.
2664             if ( right > clientW && toRight < thresh ) {
2665                 window.scrollTo(sl + scrAmt, st);
2666             }
2667
2668             // Scroll left if the window has been scrolled to the right and the obj
2669             // extends past the left border
2670             if ( x < sl && sl > 0 && x - sl < thresh ) {
2671                 window.scrollTo(sl - scrAmt, st);
2672             }
2673         }
2674     },
2675
2676     /**
2677      * Finds the location the element should be placed if we want to move
2678      * it to where the mouse location less the click offset would place us.
2679      * @method getTargetCoord
2680      * @param {int} iPageX the X coordinate of the click
2681      * @param {int} iPageY the Y coordinate of the click
2682      * @return an object that contains the coordinates (Object.x and Object.y)
2683      * @private
2684      */
2685     getTargetCoord: function(iPageX, iPageY) {
2686
2687
2688         var x = iPageX - this.deltaX;
2689         var y = iPageY - this.deltaY;
2690
2691         if (this.constrainX) {
2692             if (x < this.minX) { x = this.minX; }
2693             if (x > this.maxX) { x = this.maxX; }
2694         }
2695
2696         if (this.constrainY) {
2697             if (y < this.minY) { y = this.minY; }
2698             if (y > this.maxY) { y = this.maxY; }
2699         }
2700
2701         x = this.getTick(x, this.xTicks);
2702         y = this.getTick(y, this.yTicks);
2703
2704
2705         return {x:x, y:y};
2706     },
2707
2708     /**
2709      * Sets up config options specific to this class. Overrides
2710      * Ext.dd.DragDrop, but all versions of this method through the
2711      * inheritance chain are called
2712      */
2713     applyConfig: function() {
2714         Ext.dd.DD.superclass.applyConfig.call(this);
2715         this.scroll = (this.config.scroll !== false);
2716     },
2717
2718     /**
2719      * Event that fires prior to the onMouseDown event.  Overrides
2720      * Ext.dd.DragDrop.
2721      */
2722     b4MouseDown: function(e) {
2723         // this.resetConstraints();
2724         this.autoOffset(e.getPageX(),
2725                             e.getPageY());
2726     },
2727
2728     /**
2729      * Event that fires prior to the onDrag event.  Overrides
2730      * Ext.dd.DragDrop.
2731      */
2732     b4Drag: function(e) {
2733         this.setDragElPos(e.getPageX(),
2734                             e.getPageY());
2735     },
2736
2737     toString: function() {
2738         return ("DD " + this.id);
2739     }
2740
2741     //////////////////////////////////////////////////////////////////////////
2742     // Debugging ygDragDrop events that can be overridden
2743     //////////////////////////////////////////////////////////////////////////
2744     /*
2745     startDrag: function(x, y) {
2746     },
2747
2748     onDrag: function(e) {
2749     },
2750
2751     onDragEnter: function(e, id) {
2752     },
2753
2754     onDragOver: function(e, id) {
2755     },
2756
2757     onDragOut: function(e, id) {
2758     },
2759
2760     onDragDrop: function(e, id) {
2761     },
2762
2763     endDrag: function(e) {
2764     }
2765
2766     */
2767
2768 });
2769 /**
2770  * @class Ext.dd.DDProxy
2771  * A DragDrop implementation that inserts an empty, bordered div into
2772  * the document that follows the cursor during drag operations.  At the time of
2773  * the click, the frame div is resized to the dimensions of the linked html
2774  * element, and moved to the exact location of the linked element.
2775  *
2776  * References to the "frame" element refer to the single proxy element that
2777  * was created to be dragged in place of all DDProxy elements on the
2778  * page.
2779  *
2780  * @extends Ext.dd.DD
2781  * @constructor
2782  * @param {String} id the id of the linked html element
2783  * @param {String} sGroup the group of related DragDrop objects
2784  * @param {object} config an object containing configurable attributes
2785  *                Valid properties for DDProxy in addition to those in DragDrop:
2786  *                   resizeFrame, centerFrame, dragElId
2787  */
2788 Ext.dd.DDProxy = function(id, sGroup, config) {
2789     if (id) {
2790         this.init(id, sGroup, config);
2791         this.initFrame();
2792     }
2793 };
2794
2795 /**
2796  * The default drag frame div id
2797  * @property Ext.dd.DDProxy.dragElId
2798  * @type String
2799  * @static
2800  */
2801 Ext.dd.DDProxy.dragElId = "ygddfdiv";
2802
2803 Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, {
2804
2805     /**
2806      * By default we resize the drag frame to be the same size as the element
2807      * we want to drag (this is to get the frame effect).  We can turn it off
2808      * if we want a different behavior.
2809      * @property resizeFrame
2810      * @type boolean
2811      */
2812     resizeFrame: true,
2813
2814     /**
2815      * By default the frame is positioned exactly where the drag element is, so
2816      * we use the cursor offset provided by Ext.dd.DD.  Another option that works only if
2817      * you do not have constraints on the obj is to have the drag frame centered
2818      * around the cursor.  Set centerFrame to true for this effect.
2819      * @property centerFrame
2820      * @type boolean
2821      */
2822     centerFrame: false,
2823
2824     /**
2825      * Creates the proxy element if it does not yet exist
2826      * @method createFrame
2827      */
2828     createFrame: function() {
2829         var self = this;
2830         var body = document.body;
2831
2832         if (!body || !body.firstChild) {
2833             setTimeout( function() { self.createFrame(); }, 50 );
2834             return;
2835         }
2836
2837         var div = this.getDragEl();
2838
2839         if (!div) {
2840             div    = document.createElement("div");
2841             div.id = this.dragElId;
2842             var s  = div.style;
2843
2844             s.position   = "absolute";
2845             s.visibility = "hidden";
2846             s.cursor     = "move";
2847             s.border     = "2px solid #aaa";
2848             s.zIndex     = 999;
2849
2850             // appendChild can blow up IE if invoked prior to the window load event
2851             // while rendering a table.  It is possible there are other scenarios
2852             // that would cause this to happen as well.
2853             body.insertBefore(div, body.firstChild);
2854         }
2855     },
2856
2857     /**
2858      * Initialization for the drag frame element.  Must be called in the
2859      * constructor of all subclasses
2860      * @method initFrame
2861      */
2862     initFrame: function() {
2863         this.createFrame();
2864     },
2865
2866     applyConfig: function() {
2867         Ext.dd.DDProxy.superclass.applyConfig.call(this);
2868
2869         this.resizeFrame = (this.config.resizeFrame !== false);
2870         this.centerFrame = (this.config.centerFrame);
2871         this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
2872     },
2873
2874     /**
2875      * Resizes the drag frame to the dimensions of the clicked object, positions
2876      * it over the object, and finally displays it
2877      * @method showFrame
2878      * @param {int} iPageX X click position
2879      * @param {int} iPageY Y click position
2880      * @private
2881      */
2882     showFrame: function(iPageX, iPageY) {
2883         var el = this.getEl();
2884         var dragEl = this.getDragEl();
2885         var s = dragEl.style;
2886
2887         this._resizeProxy();
2888
2889         if (this.centerFrame) {
2890             this.setDelta( Math.round(parseInt(s.width,  10)/2),
2891                            Math.round(parseInt(s.height, 10)/2) );
2892         }
2893
2894         this.setDragElPos(iPageX, iPageY);
2895
2896         Ext.fly(dragEl).show();
2897     },
2898
2899     /**
2900      * The proxy is automatically resized to the dimensions of the linked
2901      * element when a drag is initiated, unless resizeFrame is set to false
2902      * @method _resizeProxy
2903      * @private
2904      */
2905     _resizeProxy: function() {
2906         if (this.resizeFrame) {
2907             var el = this.getEl();
2908             Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2909         }
2910     },
2911
2912     // overrides Ext.dd.DragDrop
2913     b4MouseDown: function(e) {
2914         var x = e.getPageX();
2915         var y = e.getPageY();
2916         this.autoOffset(x, y);
2917         this.setDragElPos(x, y);
2918     },
2919
2920     // overrides Ext.dd.DragDrop
2921     b4StartDrag: function(x, y) {
2922         // show the drag frame
2923         this.showFrame(x, y);
2924     },
2925
2926     // overrides Ext.dd.DragDrop
2927     b4EndDrag: function(e) {
2928         Ext.fly(this.getDragEl()).hide();
2929     },
2930
2931     // overrides Ext.dd.DragDrop
2932     // By default we try to move the element to the last location of the frame.
2933     // This is so that the default behavior mirrors that of Ext.dd.DD.
2934     endDrag: function(e) {
2935
2936         var lel = this.getEl();
2937         var del = this.getDragEl();
2938
2939         // Show the drag frame briefly so we can get its position
2940         del.style.visibility = "";
2941
2942         this.beforeMove();
2943         // Hide the linked element before the move to get around a Safari
2944         // rendering bug.
2945         lel.style.visibility = "hidden";
2946         Ext.dd.DDM.moveToEl(lel, del);
2947         del.style.visibility = "hidden";
2948         lel.style.visibility = "";
2949
2950         this.afterDrag();
2951     },
2952
2953     beforeMove : function(){
2954
2955     },
2956
2957     afterDrag : function(){
2958
2959     },
2960
2961     toString: function() {
2962         return ("DDProxy " + this.id);
2963     }
2964
2965 });
2966 /**
2967  * @class Ext.dd.DDTarget
2968  * A DragDrop implementation that does not move, but can be a drop
2969  * target.  You would get the same result by simply omitting implementation
2970  * for the event callbacks, but this way we reduce the processing cost of the
2971  * event listener and the callbacks.
2972  * @extends Ext.dd.DragDrop
2973  * @constructor
2974  * @param {String} id the id of the element that is a drop target
2975  * @param {String} sGroup the group of related DragDrop objects
2976  * @param {object} config an object containing configurable attributes
2977  *                 Valid properties for DDTarget in addition to those in
2978  *                 DragDrop:
2979  *                    none
2980  */
2981 Ext.dd.DDTarget = function(id, sGroup, config) {
2982     if (id) {
2983         this.initTarget(id, sGroup, config);
2984     }
2985 };
2986
2987 // Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop();
2988 Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, {
2989     toString: function() {
2990         return ("DDTarget " + this.id);
2991     }
2992 });
2993 /**\r
2994  * @class Ext.dd.DragTracker\r
2995  * @extends Ext.util.Observable\r
2996  */\r
2997 Ext.dd.DragTracker = function(config){\r
2998     Ext.apply(this, config);\r
2999     this.addEvents(\r
3000         /**\r
3001          * @event mousedown\r
3002          * @param {Object} this\r
3003          * @param {Object} e event object\r
3004          */\r
3005         'mousedown',\r
3006         /**\r
3007          * @event mouseup\r
3008          * @param {Object} this\r
3009          * @param {Object} e event object\r
3010          */\r
3011         'mouseup',\r
3012         /**\r
3013          * @event mousemove\r
3014          * @param {Object} this\r
3015          * @param {Object} e event object\r
3016          */\r
3017         'mousemove',\r
3018         /**\r
3019          * @event dragstart\r
3020          * @param {Object} this\r
3021          * @param {Object} startXY the page coordinates of the event\r
3022          */\r
3023         'dragstart',\r
3024         /**\r
3025          * @event dragend\r
3026          * @param {Object} this\r
3027          * @param {Object} e event object\r
3028          */\r
3029         'dragend',\r
3030         /**\r
3031          * @event drag\r
3032          * @param {Object} this\r
3033          * @param {Object} e event object\r
3034          */\r
3035         'drag'\r
3036     );\r
3037 \r
3038     this.dragRegion = new Ext.lib.Region(0,0,0,0);\r
3039 \r
3040     if(this.el){\r
3041         this.initEl(this.el);\r
3042     }\r
3043 }\r
3044 \r
3045 Ext.extend(Ext.dd.DragTracker, Ext.util.Observable,  {\r
3046     /**\r
3047      * @cfg {Boolean} active\r
3048          * Defaults to <tt>false</tt>.\r
3049          */     \r
3050     active: false,\r
3051     /**\r
3052      * @cfg {Number} tolerance\r
3053          * Defaults to <tt>5</tt>.\r
3054          */     \r
3055     tolerance: 5,\r
3056     /**\r
3057      * @cfg {Boolean/Number} autoStart\r
3058          * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.\r
3059          * Specify a Number for the number of milliseconds to defer trigger start.\r
3060          */     \r
3061     autoStart: false,\r
3062 \r
3063     initEl: function(el){\r
3064         this.el = Ext.get(el);\r
3065         el.on('mousedown', this.onMouseDown, this,\r
3066                 this.delegate ? {delegate: this.delegate} : undefined);\r
3067     },\r
3068 \r
3069     destroy : function(){\r
3070         this.el.un('mousedown', this.onMouseDown, this);\r
3071     },\r
3072 \r
3073     onMouseDown: function(e, target){\r
3074         if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){\r
3075             this.startXY = this.lastXY = e.getXY();\r
3076             this.dragTarget = this.delegate ? target : this.el.dom;\r
3077             if(this.preventDefault !== false){\r
3078                 e.preventDefault();\r
3079             }\r
3080             var doc = Ext.getDoc();\r
3081             doc.on('mouseup', this.onMouseUp, this);\r
3082             doc.on('mousemove', this.onMouseMove, this);\r
3083             doc.on('selectstart', this.stopSelect, this);\r
3084             if(this.autoStart){\r
3085                 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);\r
3086             }\r
3087         }\r
3088     },\r
3089 \r
3090     onMouseMove: function(e, target){\r
3091         // HACK: IE hack to see if button was released outside of window. */\r
3092         if(this.active && Ext.isIE && !e.browserEvent.button){\r
3093             e.preventDefault();\r
3094             this.onMouseUp(e);\r
3095             return;\r
3096         }\r
3097 \r
3098         e.preventDefault();\r
3099         var xy = e.getXY(), s = this.startXY;\r
3100         this.lastXY = xy;\r
3101         if(!this.active){\r
3102             if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){\r
3103                 this.triggerStart();\r
3104             }else{\r
3105                 return;\r
3106             }\r
3107         }\r
3108         this.fireEvent('mousemove', this, e);\r
3109         this.onDrag(e);\r
3110         this.fireEvent('drag', this, e);\r
3111     },\r
3112 \r
3113     onMouseUp: function(e){\r
3114         var doc = Ext.getDoc();\r
3115         doc.un('mousemove', this.onMouseMove, this);\r
3116         doc.un('mouseup', this.onMouseUp, this);\r
3117         doc.un('selectstart', this.stopSelect, this);\r
3118         e.preventDefault();\r
3119         this.clearStart();\r
3120         var wasActive = this.active;\r
3121         this.active = false;\r
3122         delete this.elRegion;\r
3123         this.fireEvent('mouseup', this, e);\r
3124         if(wasActive){\r
3125             this.onEnd(e);\r
3126             this.fireEvent('dragend', this, e);\r
3127         }\r
3128     },\r
3129 \r
3130     triggerStart: function(isTimer){\r
3131         this.clearStart();\r
3132         this.active = true;\r
3133         this.onStart(this.startXY);\r
3134         this.fireEvent('dragstart', this, this.startXY);\r
3135     },\r
3136 \r
3137     clearStart : function(){\r
3138         if(this.timer){\r
3139             clearTimeout(this.timer);\r
3140             delete this.timer;\r
3141         }\r
3142     },\r
3143 \r
3144     stopSelect : function(e){\r
3145         e.stopEvent();\r
3146         return false;\r
3147     },\r
3148 \r
3149     onBeforeStart : function(e){\r
3150 \r
3151     },\r
3152 \r
3153     onStart : function(xy){\r
3154 \r
3155     },\r
3156 \r
3157     onDrag : function(e){\r
3158 \r
3159     },\r
3160 \r
3161     onEnd : function(e){\r
3162 \r
3163     },\r
3164 \r
3165     getDragTarget : function(){\r
3166         return this.dragTarget;\r
3167     },\r
3168 \r
3169     getDragCt : function(){\r
3170         return this.el;\r
3171     },\r
3172 \r
3173     getXY : function(constrain){\r
3174         return constrain ?\r
3175                this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;\r
3176     },\r
3177 \r
3178     getOffset : function(constrain){\r
3179         var xy = this.getXY(constrain);\r
3180         var s = this.startXY;\r
3181         return [s[0]-xy[0], s[1]-xy[1]];\r
3182     },\r
3183 \r
3184     constrainModes: {\r
3185         'point' : function(xy){\r
3186 \r
3187             if(!this.elRegion){\r
3188                 this.elRegion = this.getDragCt().getRegion();\r
3189             }\r
3190 \r
3191             var dr = this.dragRegion;\r
3192 \r
3193             dr.left = xy[0];\r
3194             dr.top = xy[1];\r
3195             dr.right = xy[0];\r
3196             dr.bottom = xy[1];\r
3197 \r
3198             dr.constrainTo(this.elRegion);\r
3199 \r
3200             return [dr.left, dr.top];\r
3201         }\r
3202     }\r
3203 });/**\r
3204  * @class Ext.dd.ScrollManager\r
3205  * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>\r
3206  * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,\r
3207  * but you can also override most of the configs per scroll container by adding a \r
3208  * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},\r
3209  * {@link #vthresh}, {@link #increment} and {@link #frequency}.  Example usage:\r
3210  * <pre><code>\r
3211 var el = Ext.get('scroll-ct');\r
3212 el.ddScrollConfig = {\r
3213     vthresh: 50,\r
3214     hthresh: -1,\r
3215     frequency: 100,\r
3216     increment: 200\r
3217 };\r
3218 Ext.dd.ScrollManager.register(el);\r
3219 </code></pre>\r
3220  * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>\r
3221  * @singleton\r
3222  */\r
3223 Ext.dd.ScrollManager = function(){\r
3224     var ddm = Ext.dd.DragDropMgr;\r
3225     var els = {};\r
3226     var dragEl = null;\r
3227     var proc = {};\r
3228     \r
3229     var onStop = function(e){\r
3230         dragEl = null;\r
3231         clearProc();\r
3232     };\r
3233     \r
3234     var triggerRefresh = function(){\r
3235         if(ddm.dragCurrent){\r
3236              ddm.refreshCache(ddm.dragCurrent.groups);\r
3237         }\r
3238     };\r
3239     \r
3240     var doScroll = function(){\r
3241         if(ddm.dragCurrent){\r
3242             var dds = Ext.dd.ScrollManager;\r
3243             var inc = proc.el.ddScrollConfig ?\r
3244                       proc.el.ddScrollConfig.increment : dds.increment;\r
3245             if(!dds.animate){\r
3246                 if(proc.el.scroll(proc.dir, inc)){\r
3247                     triggerRefresh();\r
3248                 }\r
3249             }else{\r
3250                 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);\r
3251             }\r
3252         }\r
3253     };\r
3254     \r
3255     var clearProc = function(){\r
3256         if(proc.id){\r
3257             clearInterval(proc.id);\r
3258         }\r
3259         proc.id = 0;\r
3260         proc.el = null;\r
3261         proc.dir = "";\r
3262     };\r
3263     \r
3264     var startProc = function(el, dir){\r
3265         clearProc();\r
3266         proc.el = el;\r
3267         proc.dir = dir;\r
3268         var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ? \r
3269                 el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;\r
3270         proc.id = setInterval(doScroll, freq);\r
3271     };\r
3272     \r
3273     var onFire = function(e, isDrop){\r
3274         if(isDrop || !ddm.dragCurrent){ return; }\r
3275         var dds = Ext.dd.ScrollManager;\r
3276         if(!dragEl || dragEl != ddm.dragCurrent){\r
3277             dragEl = ddm.dragCurrent;\r
3278             // refresh regions on drag start\r
3279             dds.refreshCache();\r
3280         }\r
3281         \r
3282         var xy = Ext.lib.Event.getXY(e);\r
3283         var pt = new Ext.lib.Point(xy[0], xy[1]);\r
3284         for(var id in els){\r
3285             var el = els[id], r = el._region;\r
3286             var c = el.ddScrollConfig ? el.ddScrollConfig : dds;\r
3287             if(r && r.contains(pt) && el.isScrollable()){\r
3288                 if(r.bottom - pt.y <= c.vthresh){\r
3289                     if(proc.el != el){\r
3290                         startProc(el, "down");\r
3291                     }\r
3292                     return;\r
3293                 }else if(r.right - pt.x <= c.hthresh){\r
3294                     if(proc.el != el){\r
3295                         startProc(el, "left");\r
3296                     }\r
3297                     return;\r
3298                 }else if(pt.y - r.top <= c.vthresh){\r
3299                     if(proc.el != el){\r
3300                         startProc(el, "up");\r
3301                     }\r
3302                     return;\r
3303                 }else if(pt.x - r.left <= c.hthresh){\r
3304                     if(proc.el != el){\r
3305                         startProc(el, "right");\r
3306                     }\r
3307                     return;\r
3308                 }\r
3309             }\r
3310         }\r
3311         clearProc();\r
3312     };\r
3313     \r
3314     ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);\r
3315     ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);\r
3316     \r
3317     return {\r
3318         /**\r
3319          * Registers new overflow element(s) to auto scroll\r
3320          * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either\r
3321          */\r
3322         register : function(el){\r
3323             if(Ext.isArray(el)){\r
3324                 for(var i = 0, len = el.length; i < len; i++) {\r
3325                         this.register(el[i]);\r
3326                 }\r
3327             }else{\r
3328                 el = Ext.get(el);\r
3329                 els[el.id] = el;\r
3330             }\r
3331         },\r
3332         \r
3333         /**\r
3334          * Unregisters overflow element(s) so they are no longer scrolled\r
3335          * @param {Mixed/Array} el The id of or the element to be removed or an array of either\r
3336          */\r
3337         unregister : function(el){\r
3338             if(Ext.isArray(el)){\r
3339                 for(var i = 0, len = el.length; i < len; i++) {\r
3340                         this.unregister(el[i]);\r
3341                 }\r
3342             }else{\r
3343                 el = Ext.get(el);\r
3344                 delete els[el.id];\r
3345             }\r
3346         },\r
3347         \r
3348         /**\r
3349          * The number of pixels from the top or bottom edge of a container the pointer needs to be to\r
3350          * trigger scrolling (defaults to 25)\r
3351          * @type Number\r
3352          */\r
3353         vthresh : 25,\r
3354         /**\r
3355          * The number of pixels from the right or left edge of a container the pointer needs to be to\r
3356          * trigger scrolling (defaults to 25)\r
3357          * @type Number\r
3358          */\r
3359         hthresh : 25,\r
3360 \r
3361         /**\r
3362          * The number of pixels to scroll in each scroll increment (defaults to 50)\r
3363          * @type Number\r
3364          */\r
3365         increment : 100,\r
3366         \r
3367         /**\r
3368          * The frequency of scrolls in milliseconds (defaults to 500)\r
3369          * @type Number\r
3370          */\r
3371         frequency : 500,\r
3372         \r
3373         /**\r
3374          * True to animate the scroll (defaults to true)\r
3375          * @type Boolean\r
3376          */\r
3377         animate: true,\r
3378         \r
3379         /**\r
3380          * The animation duration in seconds - \r
3381          * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)\r
3382          * @type Number\r
3383          */\r
3384         animDuration: .4,\r
3385         \r
3386         /**\r
3387          * Manually trigger a cache refresh.\r
3388          */\r
3389         refreshCache : function(){\r
3390             for(var id in els){\r
3391                 if(typeof els[id] == 'object'){ // for people extending the object prototype\r
3392                     els[id]._region = els[id].getRegion();\r
3393                 }\r
3394             }\r
3395         }\r
3396     };\r
3397 }();/**\r
3398  * @class Ext.dd.Registry\r
3399  * Provides easy access to all drag drop components that are registered on a page.  Items can be retrieved either\r
3400  * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.\r
3401  * @singleton\r
3402  */\r
3403 Ext.dd.Registry = function(){\r
3404     var elements = {}; \r
3405     var handles = {}; \r
3406     var autoIdSeed = 0;\r
3407 \r
3408     var getId = function(el, autogen){\r
3409         if(typeof el == "string"){\r
3410             return el;\r
3411         }\r
3412         var id = el.id;\r
3413         if(!id && autogen !== false){\r
3414             id = "extdd-" + (++autoIdSeed);\r
3415             el.id = id;\r
3416         }\r
3417         return id;\r
3418     };\r
3419     \r
3420     return {\r
3421     /**\r
3422      * Resgister a drag drop element\r
3423      * @param {String/HTMLElement) element The id or DOM node to register\r
3424      * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved\r
3425      * in drag drop operations.  You can populate this object with any arbitrary properties that your own code\r
3426      * knows how to interpret, plus there are some specific properties known to the Registry that should be\r
3427      * populated in the data object (if applicable):\r
3428      * <pre>\r
3429 Value      Description<br />\r
3430 ---------  ------------------------------------------<br />\r
3431 handles    Array of DOM nodes that trigger dragging<br />\r
3432            for the element being registered<br />\r
3433 isHandle   True if the element passed in triggers<br />\r
3434            dragging itself, else false\r
3435 </pre>\r
3436      */\r
3437         register : function(el, data){\r
3438             data = data || {};\r
3439             if(typeof el == "string"){\r
3440                 el = document.getElementById(el);\r
3441             }\r
3442             data.ddel = el;\r
3443             elements[getId(el)] = data;\r
3444             if(data.isHandle !== false){\r
3445                 handles[data.ddel.id] = data;\r
3446             }\r
3447             if(data.handles){\r
3448                 var hs = data.handles;\r
3449                 for(var i = 0, len = hs.length; i < len; i++){\r
3450                         handles[getId(hs[i])] = data;\r
3451                 }\r
3452             }\r
3453         },\r
3454 \r
3455     /**\r
3456      * Unregister a drag drop element\r
3457      * @param {String/HTMLElement) element The id or DOM node to unregister\r
3458      */\r
3459         unregister : function(el){\r
3460             var id = getId(el, false);\r
3461             var data = elements[id];\r
3462             if(data){\r
3463                 delete elements[id];\r
3464                 if(data.handles){\r
3465                     var hs = data.handles;\r
3466                     for(var i = 0, len = hs.length; i < len; i++){\r
3467                         delete handles[getId(hs[i], false)];\r
3468                     }\r
3469                 }\r
3470             }\r
3471         },\r
3472 \r
3473     /**\r
3474      * Returns the handle registered for a DOM Node by id\r
3475      * @param {String/HTMLElement} id The DOM node or id to look up\r
3476      * @return {Object} handle The custom handle data\r
3477      */\r
3478         getHandle : function(id){\r
3479             if(typeof id != "string"){ // must be element?\r
3480                 id = id.id;\r
3481             }\r
3482             return handles[id];\r
3483         },\r
3484 \r
3485     /**\r
3486      * Returns the handle that is registered for the DOM node that is the target of the event\r
3487      * @param {Event} e The event\r
3488      * @return {Object} handle The custom handle data\r
3489      */\r
3490         getHandleFromEvent : function(e){\r
3491             var t = Ext.lib.Event.getTarget(e);\r
3492             return t ? handles[t.id] : null;\r
3493         },\r
3494 \r
3495     /**\r
3496      * Returns a custom data object that is registered for a DOM node by id\r
3497      * @param {String/HTMLElement} id The DOM node or id to look up\r
3498      * @return {Object} data The custom data\r
3499      */\r
3500         getTarget : function(id){\r
3501             if(typeof id != "string"){ // must be element?\r
3502                 id = id.id;\r
3503             }\r
3504             return elements[id];\r
3505         },\r
3506 \r
3507     /**\r
3508      * Returns a custom data object that is registered for the DOM node that is the target of the event\r
3509      * @param {Event} e The event\r
3510      * @return {Object} data The custom data\r
3511      */\r
3512         getTargetFromEvent : function(e){\r
3513             var t = Ext.lib.Event.getTarget(e);\r
3514             return t ? elements[t.id] || handles[t.id] : null;\r
3515         }\r
3516     };\r
3517 }();/**\r
3518  * @class Ext.dd.StatusProxy\r
3519  * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair.  This is the\r
3520  * default drag proxy used by all Ext.dd components.\r
3521  * @constructor\r
3522  * @param {Object} config\r
3523  */\r
3524 Ext.dd.StatusProxy = function(config){\r
3525     Ext.apply(this, config);\r
3526     this.id = this.id || Ext.id();\r
3527     this.el = new Ext.Layer({\r
3528         dh: {\r
3529             id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [\r
3530                 {tag: "div", cls: "x-dd-drop-icon"},\r
3531                 {tag: "div", cls: "x-dd-drag-ghost"}\r
3532             ]\r
3533         }, \r
3534         shadow: !config || config.shadow !== false\r
3535     });\r
3536     this.ghost = Ext.get(this.el.dom.childNodes[1]);\r
3537     this.dropStatus = this.dropNotAllowed;\r
3538 };\r
3539 \r
3540 Ext.dd.StatusProxy.prototype = {\r
3541     /**\r
3542      * @cfg {String} dropAllowed\r
3543      * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").\r
3544      */\r
3545     dropAllowed : "x-dd-drop-ok",\r
3546     /**\r
3547      * @cfg {String} dropNotAllowed\r
3548      * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").\r
3549      */\r
3550     dropNotAllowed : "x-dd-drop-nodrop",\r
3551 \r
3552     /**\r
3553      * Updates the proxy's visual element to indicate the status of whether or not drop is allowed\r
3554      * over the current target element.\r
3555      * @param {String} cssClass The css class for the new drop status indicator image\r
3556      */\r
3557     setStatus : function(cssClass){\r
3558         cssClass = cssClass || this.dropNotAllowed;\r
3559         if(this.dropStatus != cssClass){\r
3560             this.el.replaceClass(this.dropStatus, cssClass);\r
3561             this.dropStatus = cssClass;\r
3562         }\r
3563     },\r
3564 \r
3565     /**\r
3566      * Resets the status indicator to the default dropNotAllowed value\r
3567      * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it\r
3568      */\r
3569     reset : function(clearGhost){\r
3570         this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;\r
3571         this.dropStatus = this.dropNotAllowed;\r
3572         if(clearGhost){\r
3573             this.ghost.update("");\r
3574         }\r
3575     },\r
3576 \r
3577     /**\r
3578      * Updates the contents of the ghost element\r
3579      * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a\r
3580      * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).\r
3581      */\r
3582     update : function(html){\r
3583         if(typeof html == "string"){\r
3584             this.ghost.update(html);\r
3585         }else{\r
3586             this.ghost.update("");\r
3587             html.style.margin = "0";\r
3588             this.ghost.dom.appendChild(html);\r
3589         }\r
3590         var el = this.ghost.dom.firstChild; \r
3591         if(el){\r
3592             Ext.fly(el).setStyle('float', 'none');\r
3593         }\r
3594     },\r
3595 \r
3596     /**\r
3597      * Returns the underlying proxy {@link Ext.Layer}\r
3598      * @return {Ext.Layer} el\r
3599     */\r
3600     getEl : function(){\r
3601         return this.el;\r
3602     },\r
3603 \r
3604     /**\r
3605      * Returns the ghost element\r
3606      * @return {Ext.Element} el\r
3607      */\r
3608     getGhost : function(){\r
3609         return this.ghost;\r
3610     },\r
3611 \r
3612     /**\r
3613      * Hides the proxy\r
3614      * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them\r
3615      */\r
3616     hide : function(clear){\r
3617         this.el.hide();\r
3618         if(clear){\r
3619             this.reset(true);\r
3620         }\r
3621     },\r
3622 \r
3623     /**\r
3624      * Stops the repair animation if it's currently running\r
3625      */\r
3626     stop : function(){\r
3627         if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){\r
3628             this.anim.stop();\r
3629         }\r
3630     },\r
3631 \r
3632     /**\r
3633      * Displays this proxy\r
3634      */\r
3635     show : function(){\r
3636         this.el.show();\r
3637     },\r
3638 \r
3639     /**\r
3640      * Force the Layer to sync its shadow and shim positions to the element\r
3641      */\r
3642     sync : function(){\r
3643         this.el.sync();\r
3644     },\r
3645 \r
3646     /**\r
3647      * Causes the proxy to return to its position of origin via an animation.  Should be called after an\r
3648      * invalid drop operation by the item being dragged.\r
3649      * @param {Array} xy The XY position of the element ([x, y])\r
3650      * @param {Function} callback The function to call after the repair is complete\r
3651      * @param {Object} scope The scope in which to execute the callback\r
3652      */\r
3653     repair : function(xy, callback, scope){\r
3654         this.callback = callback;\r
3655         this.scope = scope;\r
3656         if(xy && this.animRepair !== false){\r
3657             this.el.addClass("x-dd-drag-repair");\r
3658             this.el.hideUnders(true);\r
3659             this.anim = this.el.shift({\r
3660                 duration: this.repairDuration || .5,\r
3661                 easing: 'easeOut',\r
3662                 xy: xy,\r
3663                 stopFx: true,\r
3664                 callback: this.afterRepair,\r
3665                 scope: this\r
3666             });\r
3667         }else{\r
3668             this.afterRepair();\r
3669         }\r
3670     },\r
3671 \r
3672     // private\r
3673     afterRepair : function(){\r
3674         this.hide(true);\r
3675         if(typeof this.callback == "function"){\r
3676             this.callback.call(this.scope || this);\r
3677         }\r
3678         this.callback = null;\r
3679         this.scope = null;\r
3680     }\r
3681 };/**\r
3682  * @class Ext.dd.DragSource\r
3683  * @extends Ext.dd.DDProxy\r
3684  * A simple class that provides the basic implementation needed to make any element draggable.\r
3685  * @constructor\r
3686  * @param {Mixed} el The container element\r
3687  * @param {Object} config\r
3688  */\r
3689 Ext.dd.DragSource = function(el, config){\r
3690     this.el = Ext.get(el);\r
3691     if(!this.dragData){\r
3692         this.dragData = {};\r
3693     }\r
3694     \r
3695     Ext.apply(this, config);\r
3696     \r
3697     if(!this.proxy){\r
3698         this.proxy = new Ext.dd.StatusProxy();\r
3699     }\r
3700     Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, \r
3701           {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});\r
3702     \r
3703     this.dragging = false;\r
3704 };\r
3705 \r
3706 Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {\r
3707     /**\r
3708      * @cfg {String} ddGroup\r
3709      * A named drag drop group to which this object belongs.  If a group is specified, then this object will only\r
3710      * interact with other drag drop objects in the same group (defaults to undefined).\r
3711      */\r
3712     /**\r
3713      * @cfg {String} dropAllowed\r
3714      * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").\r
3715      */\r
3716     dropAllowed : "x-dd-drop-ok",\r
3717     /**\r
3718      * @cfg {String} dropNotAllowed\r
3719      * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").\r
3720      */\r
3721     dropNotAllowed : "x-dd-drop-nodrop",\r
3722 \r
3723     /**\r
3724      * Returns the data object associated with this drag source\r
3725      * @return {Object} data An object containing arbitrary data\r
3726      */\r
3727     getDragData : function(e){\r
3728         return this.dragData;\r
3729     },\r
3730 \r
3731     // private\r
3732     onDragEnter : function(e, id){\r
3733         var target = Ext.dd.DragDropMgr.getDDById(id);\r
3734         this.cachedTarget = target;\r
3735         if(this.beforeDragEnter(target, e, id) !== false){\r
3736             if(target.isNotifyTarget){\r
3737                 var status = target.notifyEnter(this, e, this.dragData);\r
3738                 this.proxy.setStatus(status);\r
3739             }else{\r
3740                 this.proxy.setStatus(this.dropAllowed);\r
3741             }\r
3742             \r
3743             if(this.afterDragEnter){\r
3744                 /**\r
3745                  * An empty function by default, but provided so that you can perform a custom action\r
3746                  * when the dragged item enters the drop target by providing an implementation.\r
3747                  * @param {Ext.dd.DragDrop} target The drop target\r
3748                  * @param {Event} e The event object\r
3749                  * @param {String} id The id of the dragged element\r
3750                  * @method afterDragEnter\r
3751                  */\r
3752                 this.afterDragEnter(target, e, id);\r
3753             }\r
3754         }\r
3755     },\r
3756 \r
3757     /**\r
3758      * An empty function by default, but provided so that you can perform a custom action\r
3759      * before the dragged item enters the drop target and optionally cancel the onDragEnter.\r
3760      * @param {Ext.dd.DragDrop} target The drop target\r
3761      * @param {Event} e The event object\r
3762      * @param {String} id The id of the dragged element\r
3763      * @return {Boolean} isValid True if the drag event is valid, else false to cancel\r
3764      */\r
3765     beforeDragEnter : function(target, e, id){\r
3766         return true;\r
3767     },\r
3768 \r
3769     // private\r
3770     alignElWithMouse: function() {\r
3771         Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);\r
3772         this.proxy.sync();\r
3773     },\r
3774 \r
3775     // private\r
3776     onDragOver : function(e, id){\r
3777         var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);\r
3778         if(this.beforeDragOver(target, e, id) !== false){\r
3779             if(target.isNotifyTarget){\r
3780                 var status = target.notifyOver(this, e, this.dragData);\r
3781                 this.proxy.setStatus(status);\r
3782             }\r
3783 \r
3784             if(this.afterDragOver){\r
3785                 /**\r
3786                  * An empty function by default, but provided so that you can perform a custom action\r
3787                  * while the dragged item is over the drop target by providing an implementation.\r
3788                  * @param {Ext.dd.DragDrop} target The drop target\r
3789                  * @param {Event} e The event object\r
3790                  * @param {String} id The id of the dragged element\r
3791                  * @method afterDragOver\r
3792                  */\r
3793                 this.afterDragOver(target, e, id);\r
3794             }\r
3795         }\r
3796     },\r
3797 \r
3798     /**\r
3799      * An empty function by default, but provided so that you can perform a custom action\r
3800      * while the dragged item is over the drop target and optionally cancel the onDragOver.\r
3801      * @param {Ext.dd.DragDrop} target The drop target\r
3802      * @param {Event} e The event object\r
3803      * @param {String} id The id of the dragged element\r
3804      * @return {Boolean} isValid True if the drag event is valid, else false to cancel\r
3805      */\r
3806     beforeDragOver : function(target, e, id){\r
3807         return true;\r
3808     },\r
3809 \r
3810     // private\r
3811     onDragOut : function(e, id){\r
3812         var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);\r
3813         if(this.beforeDragOut(target, e, id) !== false){\r
3814             if(target.isNotifyTarget){\r
3815                 target.notifyOut(this, e, this.dragData);\r
3816             }\r
3817             this.proxy.reset();\r
3818             if(this.afterDragOut){\r
3819                 /**\r
3820                  * An empty function by default, but provided so that you can perform a custom action\r
3821                  * after the dragged item is dragged out of the target without dropping.\r
3822                  * @param {Ext.dd.DragDrop} target The drop target\r
3823                  * @param {Event} e The event object\r
3824                  * @param {String} id The id of the dragged element\r
3825                  * @method afterDragOut\r
3826                  */\r
3827                 this.afterDragOut(target, e, id);\r
3828             }\r
3829         }\r
3830         this.cachedTarget = null;\r
3831     },\r
3832 \r
3833     /**\r
3834      * An empty function by default, but provided so that you can perform a custom action before the dragged\r
3835      * item is dragged out of the target without dropping, and optionally cancel the onDragOut.\r
3836      * @param {Ext.dd.DragDrop} target The drop target\r
3837      * @param {Event} e The event object\r
3838      * @param {String} id The id of the dragged element\r
3839      * @return {Boolean} isValid True if the drag event is valid, else false to cancel\r
3840      */\r
3841     beforeDragOut : function(target, e, id){\r
3842         return true;\r
3843     },\r
3844     \r
3845     // private\r
3846     onDragDrop : function(e, id){\r
3847         var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);\r
3848         if(this.beforeDragDrop(target, e, id) !== false){\r
3849             if(target.isNotifyTarget){\r
3850                 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?\r
3851                     this.onValidDrop(target, e, id);\r
3852                 }else{\r
3853                     this.onInvalidDrop(target, e, id);\r
3854                 }\r
3855             }else{\r
3856                 this.onValidDrop(target, e, id);\r
3857             }\r
3858             \r
3859             if(this.afterDragDrop){\r
3860                 /**\r
3861                  * An empty function by default, but provided so that you can perform a custom action\r
3862                  * after a valid drag drop has occurred by providing an implementation.\r
3863                  * @param {Ext.dd.DragDrop} target The drop target\r
3864                  * @param {Event} e The event object\r
3865                  * @param {String} id The id of the dropped element\r
3866                  * @method afterDragDrop\r
3867                  */\r
3868                 this.afterDragDrop(target, e, id);\r
3869             }\r
3870         }\r
3871         delete this.cachedTarget;\r
3872     },\r
3873 \r
3874     /**\r
3875      * An empty function by default, but provided so that you can perform a custom action before the dragged\r
3876      * item is dropped onto the target and optionally cancel the onDragDrop.\r
3877      * @param {Ext.dd.DragDrop} target The drop target\r
3878      * @param {Event} e The event object\r
3879      * @param {String} id The id of the dragged element\r
3880      * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel\r
3881      */\r
3882     beforeDragDrop : function(target, e, id){\r
3883         return true;\r
3884     },\r
3885 \r
3886     // private\r
3887     onValidDrop : function(target, e, id){\r
3888         this.hideProxy();\r
3889         if(this.afterValidDrop){\r
3890             /**\r
3891              * An empty function by default, but provided so that you can perform a custom action\r
3892              * after a valid drop has occurred by providing an implementation.\r
3893              * @param {Object} target The target DD \r
3894              * @param {Event} e The event object\r
3895              * @param {String} id The id of the dropped element\r
3896              * @method afterInvalidDrop\r
3897              */\r
3898             this.afterValidDrop(target, e, id);\r
3899         }\r
3900     },\r
3901 \r
3902     // private\r
3903     getRepairXY : function(e, data){\r
3904         return this.el.getXY();  \r
3905     },\r
3906 \r
3907     // private\r
3908     onInvalidDrop : function(target, e, id){\r
3909         this.beforeInvalidDrop(target, e, id);\r
3910         if(this.cachedTarget){\r
3911             if(this.cachedTarget.isNotifyTarget){\r
3912                 this.cachedTarget.notifyOut(this, e, this.dragData);\r
3913             }\r
3914             this.cacheTarget = null;\r
3915         }\r
3916         this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);\r
3917 \r
3918         if(this.afterInvalidDrop){\r
3919             /**\r
3920              * An empty function by default, but provided so that you can perform a custom action\r
3921              * after an invalid drop has occurred by providing an implementation.\r
3922              * @param {Event} e The event object\r
3923              * @param {String} id The id of the dropped element\r
3924              * @method afterInvalidDrop\r
3925              */\r
3926             this.afterInvalidDrop(e, id);\r
3927         }\r
3928     },\r
3929 \r
3930     // private\r
3931     afterRepair : function(){\r
3932         if(Ext.enableFx){\r
3933             this.el.highlight(this.hlColor || "c3daf9");\r
3934         }\r
3935         this.dragging = false;\r
3936     },\r
3937 \r
3938     /**\r
3939      * An empty function by default, but provided so that you can perform a custom action after an invalid\r
3940      * drop has occurred.\r
3941      * @param {Ext.dd.DragDrop} target The drop target\r
3942      * @param {Event} e The event object\r
3943      * @param {String} id The id of the dragged element\r
3944      * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel\r
3945      */\r
3946     beforeInvalidDrop : function(target, e, id){\r
3947         return true;\r
3948     },\r
3949 \r
3950     // private\r
3951     handleMouseDown : function(e){\r
3952         if(this.dragging) {\r
3953             return;\r
3954         }\r
3955         var data = this.getDragData(e);\r
3956         if(data && this.onBeforeDrag(data, e) !== false){\r
3957             this.dragData = data;\r
3958             this.proxy.stop();\r
3959             Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);\r
3960         } \r
3961     },\r
3962 \r
3963     /**\r
3964      * An empty function by default, but provided so that you can perform a custom action before the initial\r
3965      * drag event begins and optionally cancel it.\r
3966      * @param {Object} data An object containing arbitrary data to be shared with drop targets\r
3967      * @param {Event} e The event object\r
3968      * @return {Boolean} isValid True if the drag event is valid, else false to cancel\r
3969      */\r
3970     onBeforeDrag : function(data, e){\r
3971         return true;\r
3972     },\r
3973 \r
3974     /**\r
3975      * An empty function by default, but provided so that you can perform a custom action once the initial\r
3976      * drag event has begun.  The drag cannot be canceled from this function.\r
3977      * @param {Number} x The x position of the click on the dragged object\r
3978      * @param {Number} y The y position of the click on the dragged object\r
3979      */\r
3980     onStartDrag : Ext.emptyFn,\r
3981 \r
3982     // private override\r
3983     startDrag : function(x, y){\r
3984         this.proxy.reset();\r
3985         this.dragging = true;\r
3986         this.proxy.update("");\r
3987         this.onInitDrag(x, y);\r
3988         this.proxy.show();\r
3989     },\r
3990 \r
3991     // private\r
3992     onInitDrag : function(x, y){\r
3993         var clone = this.el.dom.cloneNode(true);\r
3994         clone.id = Ext.id(); // prevent duplicate ids\r
3995         this.proxy.update(clone);\r
3996         this.onStartDrag(x, y);\r
3997         return true;\r
3998     },\r
3999 \r
4000     /**\r
4001      * Returns the drag source's underlying {@link Ext.dd.StatusProxy}\r
4002      * @return {Ext.dd.StatusProxy} proxy The StatusProxy\r
4003      */\r
4004     getProxy : function(){\r
4005         return this.proxy;  \r
4006     },\r
4007 \r
4008     /**\r
4009      * Hides the drag source's {@link Ext.dd.StatusProxy}\r
4010      */\r
4011     hideProxy : function(){\r
4012         this.proxy.hide();  \r
4013         this.proxy.reset(true);\r
4014         this.dragging = false;\r
4015     },\r
4016 \r
4017     // private\r
4018     triggerCacheRefresh : function(){\r
4019         Ext.dd.DDM.refreshCache(this.groups);\r
4020     },\r
4021 \r
4022     // private - override to prevent hiding\r
4023     b4EndDrag: function(e) {\r
4024     },\r
4025 \r
4026     // private - override to prevent moving\r
4027     endDrag : function(e){\r
4028         this.onEndDrag(this.dragData, e);\r
4029     },\r
4030 \r
4031     // private\r
4032     onEndDrag : function(data, e){\r
4033     },\r
4034     \r
4035     // private - pin to cursor\r
4036     autoOffset : function(x, y) {\r
4037         this.setDelta(-12, -20);\r
4038     }    \r
4039 });/**\r
4040  * @class Ext.dd.DropTarget\r
4041  * @extends Ext.dd.DDTarget\r
4042  * A simple class that provides the basic implementation needed to make any element a drop target that can have\r
4043  * draggable items dropped onto it.  The drop has no effect until an implementation of notifyDrop is provided.\r
4044  * @constructor\r
4045  * @param {Mixed} el The container element\r
4046  * @param {Object} config\r
4047  */\r
4048 Ext.dd.DropTarget = function(el, config){\r
4049     this.el = Ext.get(el);\r
4050     \r
4051     Ext.apply(this, config);\r
4052     \r
4053     if(this.containerScroll){\r
4054         Ext.dd.ScrollManager.register(this.el);\r
4055     }\r
4056     \r
4057     Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, \r
4058           {isTarget: true});\r
4059 \r
4060 };\r
4061 \r
4062 Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, {\r
4063     /**\r
4064      * @cfg {String} ddGroup\r
4065      * A named drag drop group to which this object belongs.  If a group is specified, then this object will only\r
4066      * interact with other drag drop objects in the same group (defaults to undefined).\r
4067      */\r
4068     /**\r
4069      * @cfg {String} overClass\r
4070      * The CSS class applied to the drop target element while the drag source is over it (defaults to "").\r
4071      */\r
4072     /**\r
4073      * @cfg {String} dropAllowed\r
4074      * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").\r
4075      */\r
4076     dropAllowed : "x-dd-drop-ok",\r
4077     /**\r
4078      * @cfg {String} dropNotAllowed\r
4079      * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").\r
4080      */\r
4081     dropNotAllowed : "x-dd-drop-nodrop",\r
4082 \r
4083     // private\r
4084     isTarget : true,\r
4085 \r
4086     // private\r
4087     isNotifyTarget : true,\r
4088 \r
4089     /**\r
4090      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the\r
4091      * target.  This default implementation adds the CSS class specified by overClass (if any) to the drop element\r
4092      * and returns the dropAllowed config value.  This method should be overridden if drop validation is required.\r
4093      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
4094      * @param {Event} e The event\r
4095      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4096      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4097      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4098      */\r
4099     notifyEnter : function(dd, e, data){\r
4100         if(this.overClass){\r
4101             this.el.addClass(this.overClass);\r
4102         }\r
4103         return this.dropAllowed;\r
4104     },\r
4105 \r
4106     /**\r
4107      * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.\r
4108      * This method will be called on every mouse movement while the drag source is over the drop target.\r
4109      * This default implementation simply returns the dropAllowed config value.\r
4110      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
4111      * @param {Event} e The event\r
4112      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4113      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4114      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4115      */\r
4116     notifyOver : function(dd, e, data){\r
4117         return this.dropAllowed;\r
4118     },\r
4119 \r
4120     /**\r
4121      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged\r
4122      * out of the target without dropping.  This default implementation simply removes the CSS class specified by\r
4123      * overClass (if any) from the drop element.\r
4124      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
4125      * @param {Event} e The event\r
4126      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4127      */\r
4128     notifyOut : function(dd, e, data){\r
4129         if(this.overClass){\r
4130             this.el.removeClass(this.overClass);\r
4131         }\r
4132     },\r
4133 \r
4134     /**\r
4135      * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has\r
4136      * been dropped on it.  This method has no default implementation and returns false, so you must provide an\r
4137      * implementation that does something to process the drop event and returns true so that the drag source's\r
4138      * repair action does not run.\r
4139      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
4140      * @param {Event} e The event\r
4141      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4142      * @return {Boolean} True if the drop was valid, else false\r
4143      */\r
4144     notifyDrop : function(dd, e, data){\r
4145         return false;\r
4146     }\r
4147 });/**\r
4148  * @class Ext.dd.DragZone\r
4149  * @extends Ext.dd.DragSource\r
4150  * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>\r
4151  * <p>This class does not move the drag target nodes, but a proxy element which may contain\r
4152  * any DOM structure you wish. The DOM element to show in the proxy is provided by either a\r
4153  * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>\r
4154  * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some\r
4155  * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class\r
4156  * is the most efficient way to "activate" those nodes.</p>\r
4157  * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.\r
4158  * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure\r
4159  * the DragZone with  an implementation of the {@link #getDragData} method which interrogates the passed\r
4160  * mouse event to see if it has taken place within an element, or class of elements. This is easily done\r
4161  * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a\r
4162  * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following\r
4163  * technique. Knowledge of the use of the DataView is required:</p><pre><code>\r
4164 myDataView.on('render', function() {\r
4165     myDataView.dragZone = new Ext.dd.DragZone(myDataView.getEl(), {\r
4166 \r
4167 //      On receipt of a mousedown event, see if it is within a DataView node.\r
4168 //      Return a drag data object if so.\r
4169         getDragData: function(e) {\r
4170 \r
4171 //          Use the DataView's own itemSelector (a mandatory property) to\r
4172 //          test if the mousedown is within one of the DataView's nodes.\r
4173             var sourceEl = e.getTarget(myDataView.itemSelector, 10);\r
4174 \r
4175 //          If the mousedown is within a DataView node, clone the node to produce\r
4176 //          a ddel element for use by the drag proxy. Also add application data\r
4177 //          to the returned data object.\r
4178             if (sourceEl) {\r
4179                 d = sourceEl.cloneNode(true);\r
4180                 d.id = Ext.id();\r
4181                 return {\r
4182                     ddel: d,\r
4183                     sourceEl: sourceEl,\r
4184                     repairXY: Ext.fly(sourceEl).getXY(),\r
4185                     sourceStore: myDataView.store,\r
4186                     draggedRecord: v.getRecord(sourceEl)\r
4187                 }\r
4188             }\r
4189         },\r
4190 \r
4191 //      Provide coordinates for the proxy to slide back to on failed drag.\r
4192 //      This is the original XY coordinates of the draggable element captured\r
4193 //      in the getDragData method.\r
4194         getRepairXY: function() {\r
4195             return this.dragData.repairXY;\r
4196         }\r
4197     });\r
4198 });</code></pre>\r
4199  * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which\r
4200  * cooperates with this DragZone.\r
4201  * @constructor\r
4202  * @param {Mixed} el The container element\r
4203  * @param {Object} config\r
4204  */\r
4205 Ext.dd.DragZone = function(el, config){\r
4206     Ext.dd.DragZone.superclass.constructor.call(this, el, config);\r
4207     if(this.containerScroll){\r
4208         Ext.dd.ScrollManager.register(this.el);\r
4209     }\r
4210 };\r
4211 \r
4212 Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {\r
4213     /**\r
4214      * This property contains the data representing the dragged object. This data is set up by the implementation\r
4215      * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain\r
4216      * any other data according to the application's needs.\r
4217      * @type Object\r
4218      * @property dragData\r
4219      */\r
4220     /**\r
4221      * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager\r
4222      * for auto scrolling during drag operations.\r
4223      */\r
4224     /**\r
4225      * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair\r
4226      * method after a failed drop (defaults to "c3daf9" - light blue)\r
4227      */\r
4228 \r
4229     /**\r
4230      * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}\r
4231      * for a valid target to drag based on the mouse down. Override this method\r
4232      * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned\r
4233      * object has a "ddel" attribute (with an HTML Element) for other functions to work.\r
4234      * @param {EventObject} e The mouse down event\r
4235      * @return {Object} The dragData\r
4236      */\r
4237     getDragData : function(e){\r
4238         return Ext.dd.Registry.getHandleFromEvent(e);\r
4239     },\r
4240     \r
4241     /**\r
4242      * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the\r
4243      * this.dragData.ddel\r
4244      * @param {Number} x The x position of the click on the dragged object\r
4245      * @param {Number} y The y position of the click on the dragged object\r
4246      * @return {Boolean} true to continue the drag, false to cancel\r
4247      */\r
4248     onInitDrag : function(x, y){\r
4249         this.proxy.update(this.dragData.ddel.cloneNode(true));\r
4250         this.onStartDrag(x, y);\r
4251         return true;\r
4252     },\r
4253     \r
4254     /**\r
4255      * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel \r
4256      */\r
4257     afterRepair : function(){\r
4258         if(Ext.enableFx){\r
4259             Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");\r
4260         }\r
4261         this.dragging = false;\r
4262     },\r
4263 \r
4264     /**\r
4265      * Called before a repair of an invalid drop to get the XY to animate to. By default returns\r
4266      * the XY of this.dragData.ddel\r
4267      * @param {EventObject} e The mouse up event\r
4268      * @return {Array} The xy location (e.g. [100, 200])\r
4269      */\r
4270     getRepairXY : function(e){\r
4271         return Ext.Element.fly(this.dragData.ddel).getXY();  \r
4272     }\r
4273 });/**\r
4274  * @class Ext.dd.DropZone\r
4275  * @extends Ext.dd.DropTarget\r
4276  * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>\r
4277  * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.\r
4278  * However a simpler way to allow a DropZone to manage any number of target elements is to configure the\r
4279  * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed\r
4280  * mouse event to see if it has taken place within an element, or class of elements. This is easily done\r
4281  * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a\r
4282  * {@link Ext.DomQuery} selector.</p>\r
4283  * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over\r
4284  * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},\r
4285  * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations\r
4286  * of these methods to provide application-specific behaviour for these events to update both\r
4287  * application state, and UI state.</p>\r
4288  * <p>For example to make a GridPanel a cooperating target with the example illustrated in\r
4289  * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>\r
4290 myGridPanel.on('render', function() {\r
4291     myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {\r
4292 \r
4293 //      If the mouse is over a grid row, return that node. This is\r
4294 //      provided as the "target" parameter in all "onNodeXXXX" node event handling functions\r
4295         getTargetFromEvent: function(e) {\r
4296             return e.getTarget(myGridPanel.getView().rowSelector);\r
4297         },\r
4298 \r
4299 //      On entry into a target node, highlight that node.\r
4300         onNodeEnter : function(target, dd, e, data){ \r
4301             Ext.fly(target).addClass('my-row-highlight-class');\r
4302         },\r
4303 \r
4304 //      On exit from a target node, unhighlight that node.\r
4305         onNodeOut : function(target, dd, e, data){ \r
4306             Ext.fly(target).removeClass('my-row-highlight-class');\r
4307         },\r
4308 \r
4309 //      While over a target node, return the default drop allowed class which\r
4310 //      places a "tick" icon into the drag proxy.\r
4311         onNodeOver : function(target, dd, e, data){ \r
4312             return Ext.dd.DropZone.prototype.dropAllowed;\r
4313         },\r
4314 \r
4315 //      On node drop we can interrogate the target to find the underlying\r
4316 //      application object that is the real target of the dragged data.\r
4317 //      In this case, it is a Record in the GridPanel's Store.\r
4318 //      We can use the data set up by the DragZone's getDragData method to read\r
4319 //      any data we decided to attach in the DragZone's getDragData method.\r
4320         onNodeDrop : function(target, dd, e, data){\r
4321             var rowIndex = myGridPanel.getView().findRowIndex(target);\r
4322             var r = myGridPanel.getStore().getAt(rowIndex);\r
4323             Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +\r
4324                 ' on Record id ' + r.id);\r
4325             return true;\r
4326         }\r
4327     });\r
4328 }\r
4329 </code></pre>\r
4330  * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which\r
4331  * cooperates with this DropZone.\r
4332  * @constructor\r
4333  * @param {Mixed} el The container element\r
4334  * @param {Object} config\r
4335  */\r
4336 Ext.dd.DropZone = function(el, config){\r
4337     Ext.dd.DropZone.superclass.constructor.call(this, el, config);\r
4338 };\r
4339 \r
4340 Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {\r
4341     /**\r
4342      * Returns a custom data object associated with the DOM node that is the target of the event.  By default\r
4343      * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to\r
4344      * provide your own custom lookup.\r
4345      * @param {Event} e The event\r
4346      * @return {Object} data The custom data\r
4347      */\r
4348     getTargetFromEvent : function(e){\r
4349         return Ext.dd.Registry.getTargetFromEvent(e);\r
4350     },\r
4351 \r
4352     /**\r
4353      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node\r
4354      * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.\r
4355      * This method has no default implementation and should be overridden to provide\r
4356      * node-specific processing if necessary.\r
4357      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from \r
4358      * {@link #getTargetFromEvent} for this node)\r
4359      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4360      * @param {Event} e The event\r
4361      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4362      */\r
4363     onNodeEnter : function(n, dd, e, data){\r
4364         \r
4365     },\r
4366 \r
4367     /**\r
4368      * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node\r
4369      * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.\r
4370      * The default implementation returns this.dropNotAllowed, so it should be\r
4371      * overridden to provide the proper feedback.\r
4372      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
4373      * {@link #getTargetFromEvent} for this node)\r
4374      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4375      * @param {Event} e The event\r
4376      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4377      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4378      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4379      */\r
4380     onNodeOver : function(n, dd, e, data){\r
4381         return this.dropAllowed;\r
4382     },\r
4383 \r
4384     /**\r
4385      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of\r
4386      * the drop node without dropping.  This method has no default implementation and should be overridden to provide\r
4387      * node-specific processing if necessary.\r
4388      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
4389      * {@link #getTargetFromEvent} for this node)\r
4390      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4391      * @param {Event} e The event\r
4392      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4393      */\r
4394     onNodeOut : function(n, dd, e, data){\r
4395         \r
4396     },\r
4397 \r
4398     /**\r
4399      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto\r
4400      * the drop node.  The default implementation returns false, so it should be overridden to provide the\r
4401      * appropriate processing of the drop event and return true so that the drag source's repair action does not run.\r
4402      * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from\r
4403      * {@link #getTargetFromEvent} for this node)\r
4404      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4405      * @param {Event} e The event\r
4406      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4407      * @return {Boolean} True if the drop was valid, else false\r
4408      */\r
4409     onNodeDrop : function(n, dd, e, data){\r
4410         return false;\r
4411     },\r
4412 \r
4413     /**\r
4414      * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,\r
4415      * but not over any of its registered drop nodes.  The default implementation returns this.dropNotAllowed, so\r
4416      * it should be overridden to provide the proper feedback if necessary.\r
4417      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4418      * @param {Event} e The event\r
4419      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4420      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4421      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4422      */\r
4423     onContainerOver : function(dd, e, data){\r
4424         return this.dropNotAllowed;\r
4425     },\r
4426 \r
4427     /**\r
4428      * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,\r
4429      * but not on any of its registered drop nodes.  The default implementation returns false, so it should be\r
4430      * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to\r
4431      * be able to accept drops.  It should return true when valid so that the drag source's repair action does not run.\r
4432      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4433      * @param {Event} e The event\r
4434      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4435      * @return {Boolean} True if the drop was valid, else false\r
4436      */\r
4437     onContainerDrop : function(dd, e, data){\r
4438         return false;\r
4439     },\r
4440 \r
4441     /**\r
4442      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over\r
4443      * the zone.  The default implementation returns this.dropNotAllowed and expects that only registered drop\r
4444      * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops\r
4445      * you should override this method and provide a custom implementation.\r
4446      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4447      * @param {Event} e The event\r
4448      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4449      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4450      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4451      */\r
4452     notifyEnter : function(dd, e, data){\r
4453         return this.dropNotAllowed;\r
4454     },\r
4455 \r
4456     /**\r
4457      * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.\r
4458      * This method will be called on every mouse movement while the drag source is over the drop zone.\r
4459      * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically\r
4460      * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits\r
4461      * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a\r
4462      * registered node, it will call {@link #onContainerOver}.\r
4463      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4464      * @param {Event} e The event\r
4465      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4466      * @return {String} status The CSS class that communicates the drop status back to the source so that the\r
4467      * underlying {@link Ext.dd.StatusProxy} can be updated\r
4468      */\r
4469     notifyOver : function(dd, e, data){\r
4470         var n = this.getTargetFromEvent(e);\r
4471         if(!n){ // not over valid drop target\r
4472             if(this.lastOverNode){\r
4473                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
4474                 this.lastOverNode = null;\r
4475             }\r
4476             return this.onContainerOver(dd, e, data);\r
4477         }\r
4478         if(this.lastOverNode != n){\r
4479             if(this.lastOverNode){\r
4480                 this.onNodeOut(this.lastOverNode, dd, e, data);\r
4481             }\r
4482             this.onNodeEnter(n, dd, e, data);\r
4483             this.lastOverNode = n;\r
4484         }\r
4485         return this.onNodeOver(n, dd, e, data);\r
4486     },\r
4487 \r
4488     /**\r
4489      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged\r
4490      * out of the zone without dropping.  If the drag source is currently over a registered node, the notification\r
4491      * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.\r
4492      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target\r
4493      * @param {Event} e The event\r
4494      * @param {Object} data An object containing arbitrary data supplied by the drag zone\r
4495      */\r
4496     notifyOut : function(dd, e, data){\r
4497         if(this.lastOverNode){\r
4498             this.onNodeOut(this.lastOverNode, dd, e, data);\r
4499             this.lastOverNode = null;\r
4500         }\r
4501     },\r
4502 \r
4503     /**\r
4504      * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has\r
4505      * been dropped on it.  The drag zone will look up the target node based on the event passed in, and if there\r
4506      * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,\r
4507      * otherwise it will call {@link #onContainerDrop}.\r
4508      * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone\r
4509      * @param {Event} e The event\r
4510      * @param {Object} data An object containing arbitrary data supplied by the drag source\r
4511      * @return {Boolean} True if the drop was valid, else false\r
4512      */\r
4513     notifyDrop : function(dd, e, data){\r
4514         if(this.lastOverNode){\r
4515             this.onNodeOut(this.lastOverNode, dd, e, data);\r
4516             this.lastOverNode = null;\r
4517         }\r
4518         var n = this.getTargetFromEvent(e);\r
4519         return n ?\r
4520             this.onNodeDrop(n, dd, e, data) :\r
4521             this.onContainerDrop(dd, e, data);\r
4522     },\r
4523 \r
4524     // private\r
4525     triggerCacheRefresh : function(){\r
4526         Ext.dd.DDM.refreshCache(this.groups);\r
4527     }  \r
4528 });/**\r
4529  * @class Ext.Element\r
4530  */\r
4531 Ext.Element.addMethods({\r
4532     /**\r
4533      * Initializes a {@link Ext.dd.DD} drag drop object for this element.\r
4534      * @param {String} group The group the DD object is member of\r
4535      * @param {Object} config The DD config object\r
4536      * @param {Object} overrides An object containing methods to override/implement on the DD object\r
4537      * @return {Ext.dd.DD} The DD object\r
4538      */\r
4539     initDD : function(group, config, overrides){\r
4540         var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);\r
4541         return Ext.apply(dd, overrides);\r
4542     },\r
4543 \r
4544     /**\r
4545      * Initializes a {@link Ext.dd.DDProxy} object for this element.\r
4546      * @param {String} group The group the DDProxy object is member of\r
4547      * @param {Object} config The DDProxy config object\r
4548      * @param {Object} overrides An object containing methods to override/implement on the DDProxy object\r
4549      * @return {Ext.dd.DDProxy} The DDProxy object\r
4550      */\r
4551     initDDProxy : function(group, config, overrides){\r
4552         var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);\r
4553         return Ext.apply(dd, overrides);\r
4554     },\r
4555 \r
4556     /**\r
4557      * Initializes a {@link Ext.dd.DDTarget} object for this element.\r
4558      * @param {String} group The group the DDTarget object is member of\r
4559      * @param {Object} config The DDTarget config object\r
4560      * @param {Object} overrides An object containing methods to override/implement on the DDTarget object\r
4561      * @return {Ext.dd.DDTarget} The DDTarget object\r
4562      */\r
4563     initDDTarget : function(group, config, overrides){\r
4564         var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);\r
4565         return Ext.apply(dd, overrides);\r
4566     }\r
4567 });