Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / src / dd / DDCore.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 });