3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
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
17 var Event=Ext.EventManager;
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:
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}.
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:
46 * dd = new Ext.dd.DragDrop("div1", "group1");
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...
53 * dd.onDragDrop = function(e, id) {
54 * alert("dd was dropped on " + id);
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
64 Ext.dd.DragDrop = function(id, sGroup, config) {
66 this.init(id, sGroup, config);
70 Ext.dd.DragDrop.prototype = {
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
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
91 * Configuration attributes passed into the constructor
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:
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
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 <a> elements:<pre><code>
125 * @property invalidHandleTypes
128 invalidHandleTypes: null,
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>
137 * @property invalidHandleIds
140 invalidHandleIds: null,
143 * An Array of CSS class names for elements to be considered in valid as drag handles.
144 * @property invalidHandleClasses
147 invalidHandleClasses: null,
150 * The linked element's absolute X position at the time the drag was
152 * @property startPageX
159 * The linked element's absolute X position at the time the drag was
161 * @property startPageY
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.
173 * @type object An object in the format {'group1':true, 'group2':true}
178 * Individual drag/drop instances can be locked. This will prevent
179 * onmousedown start drag.
195 * When set to true, other DD objects in cooperating DDGroups do not receive
196 * notification events when this DD object is dragged over them. Defaults to false.
203 * Unlock this instace
211 * By default, all instances can be a drop target. This can be disabled by
212 * setting isTarget to false.
219 * The padding configured for this drag and drop object for calculating
220 * the drop zone intersection with this object.
222 * @type int[] An array containing the 4 padding values: [top, right, bottom, left]
227 * Cached reference to the linked element
234 * Internal typeof flag
235 * @property __ygDragDrop
241 * Set to true when horizontal contraints are applied
242 * @property constrainX
249 * Set to true when vertical contraints are applied
250 * @property constrainY
257 * The left constraint
265 * The right constraint
281 * The down constraint
289 * Maintain offsets when we resetconstraints. Set to true when you want
290 * the position of the element relative to its parent to stay the same
291 * when the page changes
293 * @property maintainOffset
296 maintainOffset: false,
299 * Array of pixel locations the element will snap to if we specified a
300 * horizontal graduation/interval. This array is generated automatically
301 * when you define a tick interval.
308 * Array of pixel locations the element will snap to if we specified a
309 * vertical graduation/interval. This array is generated automatically
310 * when you define a tick interval.
317 * By default the drag and drop instance will only respond to the primary
318 * button click (left button for a right-handed mouse). Set to true to
319 * allow drag and drop to start with any mouse click that is propogated
321 * @property primaryButtonOnly
324 primaryButtonOnly: true,
327 * The available property is false until the linked dom element is accessible.
328 * @property available
334 * By default, drags can only be initiated if the mousedown occurs in the
335 * region the linked element is. This is done in part to work around a
336 * bug in some browsers that mis-report the mousedown if the previous
337 * mouseup happened outside of the window. This property is set to true
338 * if outer handles are defined.
340 * @property hasOuterHandles
344 hasOuterHandles: false,
347 * Code that executes immediately before the startDrag event
348 * @method b4StartDrag
351 b4StartDrag: function(x, y) { },
354 * Abstract method called after a drag/drop object is clicked
355 * and the drag or mousedown time thresholds have beeen met.
357 * @param {int} X click location
358 * @param {int} Y click location
360 startDrag: function(x, y) { /* override this */ },
363 * Code that executes immediately before the onDrag event
367 b4Drag: function(e) { },
370 * Abstract method called during the onMouseMove event while dragging an
373 * @param {Event} e the mousemove event
375 onDrag: function(e) { /* override this */ },
378 * Abstract method called when this element fist begins hovering over
379 * another DragDrop obj
380 * @method onDragEnter
381 * @param {Event} e the mousemove event
382 * @param {String|DragDrop[]} id In POINT mode, the element
383 * id this is hovering over. In INTERSECT mode, an array of one or more
384 * dragdrop items being hovered over.
386 onDragEnter: function(e, id) { /* override this */ },
389 * Code that executes immediately before the onDragOver event
393 b4DragOver: function(e) { },
396 * Abstract method called when this element is hovering over another
399 * @param {Event} e the mousemove event
400 * @param {String|DragDrop[]} id In POINT mode, the element
401 * id this is hovering over. In INTERSECT mode, an array of dd items
402 * being hovered over.
404 onDragOver: function(e, id) { /* override this */ },
407 * Code that executes immediately before the onDragOut event
411 b4DragOut: function(e) { },
414 * Abstract method called when we are no longer hovering over an element
416 * @param {Event} e the mousemove event
417 * @param {String|DragDrop[]} id In POINT mode, the element
418 * id this was hovering over. In INTERSECT mode, an array of dd items
419 * that the mouse is no longer over.
421 onDragOut: function(e, id) { /* override this */ },
424 * Code that executes immediately before the onDragDrop event
428 b4DragDrop: function(e) { },
431 * Abstract method called when this item is dropped on another DragDrop
434 * @param {Event} e the mouseup event
435 * @param {String|DragDrop[]} id In POINT mode, the element
436 * id this was dropped on. In INTERSECT mode, an array of dd items this
439 onDragDrop: function(e, id) { /* override this */ },
442 * Abstract method called when this item is dropped on an area with no
444 * @method onInvalidDrop
445 * @param {Event} e the mouseup event
447 onInvalidDrop: function(e) { /* override this */ },
450 * Code that executes immediately before the endDrag event
454 b4EndDrag: function(e) { },
457 * Fired when we are done dragging the object
459 * @param {Event} e the mouseup event
461 endDrag: function(e) { /* override this */ },
464 * Code executed immediately before the onMouseDown event
465 * @method b4MouseDown
466 * @param {Event} e the mousedown event
469 b4MouseDown: function(e) { },
472 * Event handler that fires when a drag/drop obj gets a mousedown
473 * @method onMouseDown
474 * @param {Event} e the mousedown event
476 onMouseDown: function(e) { /* override this */ },
479 * Event handler that fires when a drag/drop obj gets a mouseup
481 * @param {Event} e the mouseup event
483 onMouseUp: function(e) { /* override this */ },
486 * Override the onAvailable method to do what is needed after the initial
487 * position was determined.
488 * @method onAvailable
490 onAvailable: function () {
494 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
497 defaultPadding : {left:0, right:0, top:0, bottom:0},
500 * Initializes the drag drop object's constraints to restrict movement to a certain element.
504 var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
505 { dragElId: "existingProxyDiv" });
506 dd.startDrag = function(){
507 this.constrainTo("parent-id");
510 * Or you can initalize it using the {@link Ext.Element} object:
512 Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
513 startDrag : function(){
514 this.constrainTo("parent-id");
518 * @param {Mixed} constrainTo The element to constrain to.
519 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
520 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
521 * an object containing the sides to pad. For example: {right:10, bottom:10}
522 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
524 constrainTo : function(constrainTo, pad, inContent){
525 if(Ext.isNumber(pad)){
526 pad = {left: pad, right:pad, top:pad, bottom:pad};
528 pad = pad || this.defaultPadding;
529 var b = Ext.get(this.getEl()).getBox(),
530 ce = Ext.get(constrainTo),
534 if(cd == document.body){
535 c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()};
538 c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
542 var topSpace = b.y - c.y,
543 leftSpace = b.x - c.x;
545 this.resetConstraints();
546 this.setXConstraint(leftSpace - (pad.left||0), // left
547 c.width - leftSpace - b.width - (pad.right||0), //right
550 this.setYConstraint(topSpace - (pad.top||0), //top
551 c.height - topSpace - b.height - (pad.bottom||0), //bottom
557 * Returns a reference to the linked element
559 * @return {HTMLElement} the html element
563 this._domRef = Ext.getDom(this.id);
570 * Returns a reference to the actual element to drag. By default this is
571 * the same as the html element, but it can be assigned to another
572 * element. An example of this can be found in Ext.dd.DDProxy
574 * @return {HTMLElement} the html element
576 getDragEl: function() {
577 return Ext.getDom(this.dragElId);
581 * Sets up the DragDrop object. Must be called in the constructor of any
582 * Ext.dd.DragDrop subclass
584 * @param id the id of the linked element
585 * @param {String} sGroup the group of related items
586 * @param {object} config configuration attributes
588 init: function(id, sGroup, config) {
589 this.initTarget(id, sGroup, config);
590 Event.on(this.id, "mousedown", this.handleMouseDown, this);
591 // Event.on(this.id, "selectstart", Event.preventDefault);
595 * Initializes Targeting functionality only... the object does not
596 * get a mousedown handler.
598 * @param id the id of the linked element
599 * @param {String} sGroup the group of related items
600 * @param {object} config configuration attributes
602 initTarget: function(id, sGroup, config) {
604 // configuration attributes
605 this.config = config || {};
607 // create a local reference to the drag and drop manager
608 this.DDM = Ext.dd.DDM;
609 // initialize the groups array
612 // assume that we have an element reference instead of an id if the
613 // parameter is not a string
614 if (typeof id !== "string") {
621 // add to an interaction group
622 this.addToGroup((sGroup) ? sGroup : "default");
624 // We don't want to register this as the handle with the manager
625 // so we just set the id rather than calling the setter.
626 this.handleElId = id;
628 // the linked element is the element that gets dragged by default
629 this.setDragElId(id);
631 // by default, clicked anchors will not start drag operations.
632 this.invalidHandleTypes = { A: "A" };
633 this.invalidHandleIds = {};
634 this.invalidHandleClasses = [];
638 this.handleOnAvailable();
642 * Applies the configuration parameters that were passed into the constructor.
643 * This is supposed to happen at each level through the inheritance chain. So
644 * a DDProxy implentation will execute apply config on DDProxy, DD, and
645 * DragDrop in order to get all of the parameters that are available in
647 * @method applyConfig
649 applyConfig: function() {
651 // configurable properties:
652 // padding, isTarget, maintainOffset, primaryButtonOnly
653 this.padding = this.config.padding || [0, 0, 0, 0];
654 this.isTarget = (this.config.isTarget !== false);
655 this.maintainOffset = (this.config.maintainOffset);
656 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
661 * Executed when the linked element is available
662 * @method handleOnAvailable
665 handleOnAvailable: function() {
666 this.available = true;
667 this.resetConstraints();
672 * Configures the padding for the target zone in px. Effectively expands
673 * (or reduces) the virtual object size for targeting calculations.
674 * Supports css-style shorthand; if only one parameter is passed, all sides
675 * will have that padding, and if only two are passed, the top and bottom
676 * will have the first param, the left and right the second.
678 * @param {int} iTop Top pad
679 * @param {int} iRight Right pad
680 * @param {int} iBot Bot pad
681 * @param {int} iLeft Left pad
683 setPadding: function(iTop, iRight, iBot, iLeft) {
684 // this.padding = [iLeft, iRight, iTop, iBot];
685 if (!iRight && 0 !== iRight) {
686 this.padding = [iTop, iTop, iTop, iTop];
687 } else if (!iBot && 0 !== iBot) {
688 this.padding = [iTop, iRight, iTop, iRight];
690 this.padding = [iTop, iRight, iBot, iLeft];
695 * Stores the initial placement of the linked element.
696 * @method setInitPosition
697 * @param {int} diffX the X offset, default 0
698 * @param {int} diffY the Y offset, default 0
700 setInitPosition: function(diffX, diffY) {
701 var el = this.getEl();
703 if (!this.DDM.verifyEl(el)) {
710 var p = Dom.getXY( el );
712 this.initPageX = p[0] - dx;
713 this.initPageY = p[1] - dy;
715 this.lastPageX = p[0];
716 this.lastPageY = p[1];
718 this.setStartPosition(p);
722 * Sets the start position of the element. This is set when the obj
723 * is initialized, the reset when a drag is started.
724 * @method setStartPosition
725 * @param pos current position (from previous lookup)
728 setStartPosition: function(pos) {
729 var p = pos || Dom.getXY( this.getEl() );
730 this.deltaSetXY = null;
732 this.startPageX = p[0];
733 this.startPageY = p[1];
737 * Add this instance to a group of related drag/drop objects. All
738 * instances belong to at least one group, and can belong to as many
741 * @param sGroup {string} the name of the group
743 addToGroup: function(sGroup) {
744 this.groups[sGroup] = true;
745 this.DDM.regDragDrop(this, sGroup);
749 * Remove's this instance from the supplied interaction group
750 * @method removeFromGroup
751 * @param {string} sGroup The group to drop
753 removeFromGroup: function(sGroup) {
754 if (this.groups[sGroup]) {
755 delete this.groups[sGroup];
758 this.DDM.removeDDFromGroup(this, sGroup);
762 * Allows you to specify that an element other than the linked element
763 * will be moved with the cursor during a drag
764 * @method setDragElId
765 * @param id {string} the id of the element that will be used to initiate the drag
767 setDragElId: function(id) {
772 * Allows you to specify a child of the linked element that should be
773 * used to initiate the drag operation. An example of this would be if
774 * you have a content div with text and links. Clicking anywhere in the
775 * content area would normally start the drag operation. Use this method
776 * to specify that an element inside of the content div is the element
777 * that starts the drag operation.
778 * @method setHandleElId
779 * @param id {string} the id of the element that will be used to
782 setHandleElId: function(id) {
783 if (typeof id !== "string") {
786 this.handleElId = id;
787 this.DDM.regHandle(this.id, id);
791 * Allows you to set an element outside of the linked element as a drag
793 * @method setOuterHandleElId
794 * @param id the id of the element that will be used to initiate the drag
796 setOuterHandleElId: function(id) {
797 if (typeof id !== "string") {
800 Event.on(id, "mousedown",
801 this.handleMouseDown, this);
802 this.setHandleElId(id);
804 this.hasOuterHandles = true;
808 * Remove all drag and drop hooks for this element
812 Event.un(this.id, "mousedown",
813 this.handleMouseDown);
815 this.DDM._remove(this);
818 destroy : function(){
823 * Returns true if this instance is locked, or the drag drop mgr is locked
824 * (meaning that all drag/drop is disabled on the page.)
826 * @return {boolean} true if this obj or all drag/drop is locked, else
829 isLocked: function() {
830 return (this.DDM.isLocked() || this.locked);
834 * Fired when this object is clicked
835 * @method handleMouseDown
837 * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
840 handleMouseDown: function(e, oDD){
841 if (this.primaryButtonOnly && e.button != 0) {
845 if (this.isLocked()) {
849 this.DDM.refreshCache(this.groups);
851 var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e));
852 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
854 if (this.clickValidator(e)) {
856 // set the initial element position
857 this.setStartPosition();
862 this.DDM.handleMouseDown(e, this);
864 this.DDM.stopEvent(e);
872 clickValidator: function(e) {
873 var target = e.getTarget();
874 return ( this.isValidHandleChild(target) &&
875 (this.id == this.handleElId ||
876 this.DDM.handleWasClicked(target, this.id)) );
880 * Allows you to specify a tag name that should not start a drag operation
881 * when clicked. This is designed to facilitate embedding links within a
882 * drag handle that do something other than start the drag.
883 * @method addInvalidHandleType
884 * @param {string} tagName the type of element to exclude
886 addInvalidHandleType: function(tagName) {
887 var type = tagName.toUpperCase();
888 this.invalidHandleTypes[type] = type;
892 * Lets you to specify an element id for a child of a drag handle
893 * that should not initiate a drag
894 * @method addInvalidHandleId
895 * @param {string} id the element id of the element you wish to ignore
897 addInvalidHandleId: function(id) {
898 if (typeof id !== "string") {
901 this.invalidHandleIds[id] = id;
905 * Lets you specify a css class of elements that will not initiate a drag
906 * @method addInvalidHandleClass
907 * @param {string} cssClass the class of the elements you wish to ignore
909 addInvalidHandleClass: function(cssClass) {
910 this.invalidHandleClasses.push(cssClass);
914 * Unsets an excluded tag name set by addInvalidHandleType
915 * @method removeInvalidHandleType
916 * @param {string} tagName the type of element to unexclude
918 removeInvalidHandleType: function(tagName) {
919 var type = tagName.toUpperCase();
920 // this.invalidHandleTypes[type] = null;
921 delete this.invalidHandleTypes[type];
925 * Unsets an invalid handle id
926 * @method removeInvalidHandleId
927 * @param {string} id the id of the element to re-enable
929 removeInvalidHandleId: function(id) {
930 if (typeof id !== "string") {
933 delete this.invalidHandleIds[id];
937 * Unsets an invalid css class
938 * @method removeInvalidHandleClass
939 * @param {string} cssClass the class of the element(s) you wish to
942 removeInvalidHandleClass: function(cssClass) {
943 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
944 if (this.invalidHandleClasses[i] == cssClass) {
945 delete this.invalidHandleClasses[i];
951 * Checks the tag exclusion list to see if this click should be ignored
952 * @method isValidHandleChild
953 * @param {HTMLElement} node the HTMLElement to evaluate
954 * @return {boolean} true if this is a valid tag type, false if not
956 isValidHandleChild: function(node) {
959 // var n = (node.nodeName == "#text") ? node.parentNode : node;
962 nodeName = node.nodeName.toUpperCase();
964 nodeName = node.nodeName;
966 valid = valid && !this.invalidHandleTypes[nodeName];
967 valid = valid && !this.invalidHandleIds[node.id];
969 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
970 valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]);
979 * Create the array of horizontal tick marks if an interval was specified
980 * in setXConstraint().
984 setXTicks: function(iStartX, iTickSize) {
986 this.xTickSize = iTickSize;
990 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
992 this.xTicks[this.xTicks.length] = i;
997 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
999 this.xTicks[this.xTicks.length] = i;
1004 this.xTicks.sort(this.DDM.numericSort) ;
1008 * Create the array of vertical tick marks if an interval was specified in
1013 setYTicks: function(iStartY, iTickSize) {
1015 this.yTickSize = iTickSize;
1019 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1021 this.yTicks[this.yTicks.length] = i;
1026 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1028 this.yTicks[this.yTicks.length] = i;
1033 this.yTicks.sort(this.DDM.numericSort) ;
1037 * By default, the element can be dragged any place on the screen. Use
1038 * this method to limit the horizontal travel of the element. Pass in
1039 * 0,0 for the parameters if you want to lock the drag to the y axis.
1040 * @method setXConstraint
1041 * @param {int} iLeft the number of pixels the element can move to the left
1042 * @param {int} iRight the number of pixels the element can move to the
1044 * @param {int} iTickSize optional parameter for specifying that the
1046 * should move iTickSize pixels at a time.
1048 setXConstraint: function(iLeft, iRight, iTickSize) {
1049 this.leftConstraint = iLeft;
1050 this.rightConstraint = iRight;
1052 this.minX = this.initPageX - iLeft;
1053 this.maxX = this.initPageX + iRight;
1054 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1056 this.constrainX = true;
1060 * Clears any constraints applied to this instance. Also clears ticks
1061 * since they can't exist independent of a constraint at this time.
1062 * @method clearConstraints
1064 clearConstraints: function() {
1065 this.constrainX = false;
1066 this.constrainY = false;
1071 * Clears any tick interval defined for this instance
1072 * @method clearTicks
1074 clearTicks: function() {
1082 * By default, the element can be dragged any place on the screen. Set
1083 * this to limit the vertical travel of the element. Pass in 0,0 for the
1084 * parameters if you want to lock the drag to the x axis.
1085 * @method setYConstraint
1086 * @param {int} iUp the number of pixels the element can move up
1087 * @param {int} iDown the number of pixels the element can move down
1088 * @param {int} iTickSize optional parameter for specifying that the
1089 * element should move iTickSize pixels at a time.
1091 setYConstraint: function(iUp, iDown, iTickSize) {
1092 this.topConstraint = iUp;
1093 this.bottomConstraint = iDown;
1095 this.minY = this.initPageY - iUp;
1096 this.maxY = this.initPageY + iDown;
1097 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1099 this.constrainY = true;
1104 * resetConstraints must be called if you manually reposition a dd element.
1105 * @method resetConstraints
1106 * @param {boolean} maintainOffset
1108 resetConstraints: function() {
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;
1115 this.setInitPosition(dx, dy);
1117 // This is the first time we have detected the element's position
1119 this.setInitPosition();
1122 if (this.constrainX) {
1123 this.setXConstraint( this.leftConstraint,
1124 this.rightConstraint,
1128 if (this.constrainY) {
1129 this.setYConstraint( this.topConstraint,
1130 this.bottomConstraint,
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.
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
1145 getTick: function(val, tickArray) {
1147 // If tick interval is not defined, it is effectively 1 pixel,
1148 // so we return the value passed to us.
1150 } else if (tickArray[0] >= val) {
1151 // The value is lower than the first tick, so we return the first
1153 return tickArray[0];
1155 for (var i=0, len=tickArray.length; i<len; ++i) {
1157 if (tickArray[next] && tickArray[next] >= val) {
1158 var diff1 = val - tickArray[i];
1159 var diff2 = tickArray[next] - val;
1160 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1164 // The value is larger than the last tick, so we return the last
1166 return tickArray[tickArray.length - 1];
1173 * @return {string} string representation of the dd obj
1175 toString: function() {
1176 return ("DragDrop " + this.id);
1183 * The drag and drop utility provides a framework for building drag and drop
1184 * applications. In addition to enabling drag and drop for specific elements,
1185 * the drag and drop elements are tracked by the manager class, and the
1186 * interactions between the various elements are tracked during the drag and
1187 * the implementing code is notified about these important moments.
1190 // Only load the library once. Rewriting the manager class would orphan
1191 // existing drag and drop instances.
1192 if (!Ext.dd.DragDropMgr) {
1195 * @class Ext.dd.DragDropMgr
1196 * DragDropMgr is a singleton that tracks the element interaction for
1197 * all DragDrop items in the window. Generally, you will not call
1198 * this class directly, but it does have helper methods that could
1199 * be useful in your DragDrop implementations.
1202 Ext.dd.DragDropMgr = function() {
1204 var Event = Ext.EventManager;
1209 * Two dimensional Array of registered DragDrop objects. The first
1210 * dimension is the DragDrop item group, the second the DragDrop
1220 * Array of element ids defined as drag handles. Used to determine
1221 * if the element that generated the mousedown event is actually the
1222 * handle and not the html element itself.
1223 * @property handleIds
1231 * the DragDrop object that is currently being dragged
1232 * @property dragCurrent
1240 * the DragDrop object(s) that are being hovered over
1241 * @property dragOvers
1249 * the X distance between the cursor and the object being dragged
1258 * the Y distance between the cursor and the object being dragged
1267 * Flag to determine if we should prevent the default behavior of the
1268 * events we define. By default this is true, but this can be set to
1269 * false if you need the default behavior (not recommended)
1270 * @property preventDefault
1274 preventDefault: true,
1277 * Flag to determine if we should stop the propagation of the events
1278 * we generate. This is true by default but you may want to set it to
1279 * false if the html element contains other features that require the
1281 * @property stopPropagation
1285 stopPropagation: true,
1288 * Internal flag that is set to true when drag and drop has been
1290 * @property initialized
1297 * All drag and drop can be disabled.
1305 * Called the first time an element is registered.
1311 this.initialized = true;
1315 * In point mode, drag and drop interaction is defined by the
1316 * location of the cursor during the drag/drop
1324 * In intersect mode, drag and drop interaction is defined by the
1325 * overlap of two or more drag and drop objects.
1326 * @property INTERSECT
1333 * The current drag and drop mode. Default: POINT
1341 * Runs method on all drag and drop objects
1342 * @method _execOnAll
1346 _execOnAll: function(sMethod, args) {
1347 for (var i in this.ids) {
1348 for (var j in this.ids[i]) {
1349 var oDD = this.ids[i][j];
1350 if (! this.isTypeOfDD(oDD)) {
1353 oDD[sMethod].apply(oDD, args);
1359 * Drag and drop initialization. Sets up the global event handlers
1364 _onLoad: function() {
1369 Event.on(document, "mouseup", this.handleMouseUp, this, true);
1370 Event.on(document, "mousemove", this.handleMouseMove, this, true);
1371 Event.on(window, "unload", this._onUnload, this, true);
1372 Event.on(window, "resize", this._onResize, this, true);
1373 // Event.on(window, "mouseout", this._test);
1378 * Reset constraints on all drag and drop objs
1383 _onResize: function(e) {
1384 this._execOnAll("resetConstraints", []);
1388 * Lock all drag and drop functionality
1392 lock: function() { this.locked = true; },
1395 * Unlock all drag and drop functionality
1399 unlock: function() { this.locked = false; },
1402 * Is drag and drop locked?
1404 * @return {boolean} True if drag and drop is locked, false otherwise.
1407 isLocked: function() { return this.locked; },
1410 * Location cache that is set for all drag drop objects when a drag is
1411 * initiated, cleared when the drag is finished.
1412 * @property locationCache
1419 * Set useCache to false if you want to force object the lookup of each
1420 * drag and drop linked element constantly during a drag.
1421 * @property useCache
1428 * The number of pixels that the mouse needs to move after the
1429 * mousedown before the drag is initiated. Default=3;
1430 * @property clickPixelThresh
1434 clickPixelThresh: 3,
1437 * The number of milliseconds after the mousedown event to initiate the
1438 * drag if we don't get a mouseup event. Default=350
1439 * @property clickTimeThresh
1443 clickTimeThresh: 350,
1446 * Flag that indicates that either the drag pixel threshold or the
1447 * mousdown time threshold has been met
1448 * @property dragThreshMet
1453 dragThreshMet: false,
1456 * Timeout used for the click time threshold
1457 * @property clickTimeout
1465 * The X position of the mousedown event stored for later use when a
1466 * drag threshold is met.
1475 * The Y position of the mousedown event stored for later use when a
1476 * drag threshold is met.
1485 * Each DragDrop instance must be registered with the DragDropMgr.
1486 * This is executed in DragDrop.init()
1487 * @method regDragDrop
1488 * @param {DragDrop} oDD the DragDrop object to register
1489 * @param {String} sGroup the name of the group this element belongs to
1492 regDragDrop: function(oDD, sGroup) {
1493 if (!this.initialized) { this.init(); }
1495 if (!this.ids[sGroup]) {
1496 this.ids[sGroup] = {};
1498 this.ids[sGroup][oDD.id] = oDD;
1502 * Removes the supplied dd instance from the supplied group. Executed
1503 * by DragDrop.removeFromGroup, so don't call this function directly.
1504 * @method removeDDFromGroup
1508 removeDDFromGroup: function(oDD, sGroup) {
1509 if (!this.ids[sGroup]) {
1510 this.ids[sGroup] = {};
1513 var obj = this.ids[sGroup];
1514 if (obj && obj[oDD.id]) {
1520 * Unregisters a drag and drop item. This is executed in
1521 * DragDrop.unreg, use that method instead of calling this directly.
1526 _remove: function(oDD) {
1527 for (var g in oDD.groups) {
1528 if (g && this.ids[g] && this.ids[g][oDD.id]) {
1529 delete this.ids[g][oDD.id];
1532 delete this.handleIds[oDD.id];
1536 * Each DragDrop handle element must be registered. This is done
1537 * automatically when executing DragDrop.setHandleElId()
1539 * @param {String} sDDId the DragDrop id this element is a handle for
1540 * @param {String} sHandleId the id of the element that is the drag
1544 regHandle: function(sDDId, sHandleId) {
1545 if (!this.handleIds[sDDId]) {
1546 this.handleIds[sDDId] = {};
1548 this.handleIds[sDDId][sHandleId] = sHandleId;
1552 * Utility function to determine if a given element has been
1553 * registered as a drag drop item.
1554 * @method isDragDrop
1555 * @param {String} id the element id to check
1556 * @return {boolean} true if this element is a DragDrop item,
1560 isDragDrop: function(id) {
1561 return ( this.getDDById(id) ) ? true : false;
1565 * Returns the drag and drop instances that are in all groups the
1566 * passed in instance belongs to.
1567 * @method getRelated
1568 * @param {DragDrop} p_oDD the obj to get related data for
1569 * @param {boolean} bTargetsOnly if true, only return targetable objs
1570 * @return {DragDrop[]} the related instances
1573 getRelated: function(p_oDD, bTargetsOnly) {
1575 for (var i in p_oDD.groups) {
1576 for (var j in this.ids[i]) {
1577 var dd = this.ids[i][j];
1578 if (! this.isTypeOfDD(dd)) {
1581 if (!bTargetsOnly || dd.isTarget) {
1582 oDDs[oDDs.length] = dd;
1591 * Returns true if the specified dd target is a legal target for
1592 * the specifice drag obj
1593 * @method isLegalTarget
1594 * @param {DragDrop} oDD the drag obj
1595 * @param {DragDrop} oTargetDD the target
1596 * @return {boolean} true if the target is a legal target for the
1600 isLegalTarget: function (oDD, oTargetDD) {
1601 var targets = this.getRelated(oDD, true);
1602 for (var i=0, len=targets.length;i<len;++i) {
1603 if (targets[i].id == oTargetDD.id) {
1612 * My goal is to be able to transparently determine if an object is
1613 * typeof DragDrop, and the exact subclass of DragDrop. typeof
1614 * returns "object", oDD.constructor.toString() always returns
1615 * "DragDrop" and not the name of the subclass. So for now it just
1616 * evaluates a well-known variable in DragDrop.
1617 * @method isTypeOfDD
1618 * @param {Object} the object to evaluate
1619 * @return {boolean} true if typeof oDD = DragDrop
1622 isTypeOfDD: function (oDD) {
1623 return (oDD && oDD.__ygDragDrop);
1627 * Utility function to determine if a given element has been
1628 * registered as a drag drop handle for the given Drag Drop object.
1630 * @param {String} id the element id to check
1631 * @return {boolean} true if this element is a DragDrop handle, false
1635 isHandle: function(sDDId, sHandleId) {
1636 return ( this.handleIds[sDDId] &&
1637 this.handleIds[sDDId][sHandleId] );
1641 * Returns the DragDrop instance for a given id
1643 * @param {String} id the id of the DragDrop object
1644 * @return {DragDrop} the drag drop object, null if it is not found
1647 getDDById: function(id) {
1648 for (var i in this.ids) {
1649 if (this.ids[i][id]) {
1650 return this.ids[i][id];
1657 * Fired after a registered DragDrop object gets the mousedown event.
1658 * Sets up the events required to track the object being dragged
1659 * @method handleMouseDown
1660 * @param {Event} e the event
1661 * @param oDD the DragDrop object being dragged
1665 handleMouseDown: function(e, oDD) {
1667 Ext.QuickTips.disable();
1669 if(this.dragCurrent){
1670 // the original browser mouseup wasn't handled (e.g. outside FF browser window)
1671 // so clean up first to avoid breaking the next drag
1672 this.handleMouseUp(e);
1675 this.currentTarget = e.getTarget();
1676 this.dragCurrent = oDD;
1678 var el = oDD.getEl();
1680 // track start position
1681 this.startX = e.getPageX();
1682 this.startY = e.getPageY();
1684 this.deltaX = this.startX - el.offsetLeft;
1685 this.deltaY = this.startY - el.offsetTop;
1687 this.dragThreshMet = false;
1689 this.clickTimeout = setTimeout(
1691 var DDM = Ext.dd.DDM;
1692 DDM.startDrag(DDM.startX, DDM.startY);
1694 this.clickTimeThresh );
1698 * Fired when either the drag pixel threshol or the mousedown hold
1699 * time threshold has been met.
1701 * @param x {int} the X position of the original mousedown
1702 * @param y {int} the Y position of the original mousedown
1705 startDrag: function(x, y) {
1706 clearTimeout(this.clickTimeout);
1707 if (this.dragCurrent) {
1708 this.dragCurrent.b4StartDrag(x, y);
1709 this.dragCurrent.startDrag(x, y);
1711 this.dragThreshMet = true;
1715 * Internal function to handle the mouseup event. Will be invoked
1716 * from the context of the document.
1717 * @method handleMouseUp
1718 * @param {Event} e the event
1722 handleMouseUp: function(e) {
1725 Ext.QuickTips.enable();
1727 if (! this.dragCurrent) {
1731 clearTimeout(this.clickTimeout);
1733 if (this.dragThreshMet) {
1734 this.fireEvents(e, true);
1744 * Utility to stop event propagation and event default, if these
1745 * features are turned on.
1747 * @param {Event} e the event as returned by this.getEvent()
1750 stopEvent: function(e){
1751 if(this.stopPropagation) {
1752 e.stopPropagation();
1755 if (this.preventDefault) {
1761 * Internal function to clean up event handlers after the drag
1762 * operation is complete
1764 * @param {Event} e the event
1768 stopDrag: function(e) {
1769 // Fire the drag end event for the item that was dragged
1770 if (this.dragCurrent) {
1771 if (this.dragThreshMet) {
1772 this.dragCurrent.b4EndDrag(e);
1773 this.dragCurrent.endDrag(e);
1776 this.dragCurrent.onMouseUp(e);
1779 this.dragCurrent = null;
1780 this.dragOvers = {};
1784 * Internal function to handle the mousemove event. Will be invoked
1785 * from the context of the html element.
1787 * @TODO figure out what we can do about mouse events lost when the
1788 * user drags objects beyond the window boundary. Currently we can
1789 * detect this in internet explorer by verifying that the mouse is
1790 * down during the mousemove event. Firefox doesn't give us the
1791 * button state on the mousemove event.
1792 * @method handleMouseMove
1793 * @param {Event} e the event
1797 handleMouseMove: function(e) {
1798 if (! this.dragCurrent) {
1801 // var button = e.which || e.button;
1803 // check for IE mouseup outside of page boundary
1804 if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1806 return this.handleMouseUp(e);
1809 if (!this.dragThreshMet) {
1810 var diffX = Math.abs(this.startX - e.getPageX());
1811 var diffY = Math.abs(this.startY - e.getPageY());
1812 if (diffX > this.clickPixelThresh ||
1813 diffY > this.clickPixelThresh) {
1814 this.startDrag(this.startX, this.startY);
1818 if (this.dragThreshMet) {
1819 this.dragCurrent.b4Drag(e);
1820 this.dragCurrent.onDrag(e);
1821 if(!this.dragCurrent.moveOnly){
1822 this.fireEvents(e, false);
1832 * Iterates over all of the DragDrop elements to find ones we are
1833 * hovering over or dropping on
1834 * @method fireEvents
1835 * @param {Event} e the event
1836 * @param {boolean} isDrop is this a drop op or a mouseover op?
1840 fireEvents: function(e, isDrop) {
1841 var dc = this.dragCurrent;
1843 // If the user did the mouse up outside of the window, we could
1844 // get here even though we have ended the drag.
1845 if (!dc || dc.isLocked()) {
1849 var pt = e.getPoint();
1851 // cache the previous dragOver array
1859 // Check to see if the object(s) we were hovering over is no longer
1860 // being hovered over so we can fire the onDragOut event
1861 for (var i in this.dragOvers) {
1863 var ddo = this.dragOvers[i];
1865 if (! this.isTypeOfDD(ddo)) {
1869 if (! this.isOverTarget(pt, ddo, this.mode)) {
1870 outEvts.push( ddo );
1874 delete this.dragOvers[i];
1877 for (var sGroup in dc.groups) {
1879 if ("string" != typeof sGroup) {
1883 for (i in this.ids[sGroup]) {
1884 var oDD = this.ids[sGroup][i];
1885 if (! this.isTypeOfDD(oDD)) {
1889 if (oDD.isTarget && !oDD.isLocked() && ((oDD != dc) || (dc.ignoreSelf === false))) {
1890 if (this.isOverTarget(pt, oDD, this.mode)) {
1891 // look for drop interactions
1893 dropEvts.push( oDD );
1894 // look for drag enter and drag over interactions
1897 // initial drag over: dragEnter fires
1898 if (!oldOvers[oDD.id]) {
1899 enterEvts.push( oDD );
1900 // subsequent drag overs: dragOver fires
1902 overEvts.push( oDD );
1905 this.dragOvers[oDD.id] = oDD;
1913 if (outEvts.length) {
1914 dc.b4DragOut(e, outEvts);
1915 dc.onDragOut(e, outEvts);
1918 if (enterEvts.length) {
1919 dc.onDragEnter(e, enterEvts);
1922 if (overEvts.length) {
1923 dc.b4DragOver(e, overEvts);
1924 dc.onDragOver(e, overEvts);
1927 if (dropEvts.length) {
1928 dc.b4DragDrop(e, dropEvts);
1929 dc.onDragDrop(e, dropEvts);
1933 // fire dragout events
1935 for (i=0, len=outEvts.length; i<len; ++i) {
1936 dc.b4DragOut(e, outEvts[i].id);
1937 dc.onDragOut(e, outEvts[i].id);
1940 // fire enter events
1941 for (i=0,len=enterEvts.length; i<len; ++i) {
1942 // dc.b4DragEnter(e, oDD.id);
1943 dc.onDragEnter(e, enterEvts[i].id);
1947 for (i=0,len=overEvts.length; i<len; ++i) {
1948 dc.b4DragOver(e, overEvts[i].id);
1949 dc.onDragOver(e, overEvts[i].id);
1953 for (i=0, len=dropEvts.length; i<len; ++i) {
1954 dc.b4DragDrop(e, dropEvts[i].id);
1955 dc.onDragDrop(e, dropEvts[i].id);
1960 // notify about a drop that did not find a target
1961 if (isDrop && !dropEvts.length) {
1962 dc.onInvalidDrop(e);
1968 * Helper function for getting the best match from the list of drag
1969 * and drop objects returned by the drag and drop events when we are
1970 * in INTERSECT mode. It returns either the first object that the
1971 * cursor is over, or the object that has the greatest overlap with
1972 * the dragged element.
1973 * @method getBestMatch
1974 * @param {DragDrop[]} dds The array of drag and drop objects
1976 * @return {DragDrop} The best single match
1979 getBestMatch: function(dds) {
1981 // Return null if the input is not what we expect
1982 //if (!dds || !dds.length || dds.length == 0) {
1984 // If there is only one item, it wins
1985 //} else if (dds.length == 1) {
1987 var len = dds.length;
1992 // Loop through the targeted items
1993 for (var i=0; i<len; ++i) {
1995 // If the cursor is over the object, it wins. If the
1996 // cursor is over multiple matches, the first one we come
1998 if (dd.cursorIsOver) {
2001 // Otherwise the object with the most overlap wins
2004 winner.overlap.getArea() < dd.overlap.getArea()) {
2015 * Refreshes the cache of the top-left and bottom-right points of the
2016 * drag and drop objects in the specified group(s). This is in the
2017 * format that is stored in the drag and drop instance, so typical
2020 * Ext.dd.DragDropMgr.refreshCache(ddinstance.groups);
2024 * Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2026 * @TODO this really should be an indexed array. Alternatively this
2027 * method could accept both.
2028 * @method refreshCache
2029 * @param {Object} groups an associative array of groups to refresh
2032 refreshCache: function(groups) {
2033 for (var sGroup in groups) {
2034 if ("string" != typeof sGroup) {
2037 for (var i in this.ids[sGroup]) {
2038 var oDD = this.ids[sGroup][i];
2040 if (this.isTypeOfDD(oDD)) {
2041 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2042 var loc = this.getLocation(oDD);
2044 this.locationCache[oDD.id] = loc;
2046 delete this.locationCache[oDD.id];
2047 // this will unregister the drag and drop object if
2048 // the element is not in a usable state
2057 * This checks to make sure an element exists and is in the DOM. The
2058 * main purpose is to handle cases where innerHTML is used to remove
2059 * drag and drop objects from the DOM. IE provides an 'unspecified
2060 * error' when trying to access the offsetParent of such an element
2062 * @param {HTMLElement} el the element to check
2063 * @return {boolean} true if the element looks usable
2066 verifyEl: function(el) {
2071 parent = el.offsetParent;
2074 parent = el.offsetParent;
2085 * Returns a Region object containing the drag and drop element's position
2086 * and size, including the padding configured for it
2087 * @method getLocation
2088 * @param {DragDrop} oDD the drag and drop object to get the
2090 * @return {Ext.lib.Region} a Region object representing the total area
2091 * the element occupies, including any padding
2092 * the instance is configured for.
2095 getLocation: function(oDD) {
2096 if (! this.isTypeOfDD(oDD)) {
2100 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2103 pos= Ext.lib.Dom.getXY(el);
2111 x2 = x1 + el.offsetWidth;
2113 y2 = y1 + el.offsetHeight;
2115 t = y1 - oDD.padding[0];
2116 r = x2 + oDD.padding[1];
2117 b = y2 + oDD.padding[2];
2118 l = x1 - oDD.padding[3];
2120 return new Ext.lib.Region( t, r, b, l );
2124 * Checks the cursor location to see if it over the target
2125 * @method isOverTarget
2126 * @param {Ext.lib.Point} pt The point to evaluate
2127 * @param {DragDrop} oTarget the DragDrop object we are inspecting
2128 * @return {boolean} true if the mouse is over the target
2132 isOverTarget: function(pt, oTarget, intersect) {
2133 // use cache if available
2134 var loc = this.locationCache[oTarget.id];
2135 if (!loc || !this.useCache) {
2136 loc = this.getLocation(oTarget);
2137 this.locationCache[oTarget.id] = loc;
2145 oTarget.cursorIsOver = loc.contains( pt );
2147 // DragDrop is using this as a sanity check for the initial mousedown
2148 // in this case we are done. In POINT mode, if the drag obj has no
2149 // contraints, we are also done. Otherwise we need to evaluate the
2150 // location of the target as related to the actual location of the
2152 var dc = this.dragCurrent;
2153 if (!dc || !dc.getTargetCoord ||
2154 (!intersect && !dc.constrainX && !dc.constrainY)) {
2155 return oTarget.cursorIsOver;
2158 oTarget.overlap = null;
2160 // Get the current location of the drag element, this is the
2161 // location of the mouse event less the delta that represents
2162 // where the original mousedown happened on the element. We
2163 // need to consider constraints and ticks as well.
2164 var pos = dc.getTargetCoord(pt.x, pt.y);
2166 var el = dc.getDragEl();
2167 var curRegion = new Ext.lib.Region( pos.y,
2168 pos.x + el.offsetWidth,
2169 pos.y + el.offsetHeight,
2172 var overlap = curRegion.intersect(loc);
2175 oTarget.overlap = overlap;
2176 return (intersect) ? true : oTarget.cursorIsOver;
2183 * unload event handler
2188 _onUnload: function(e, me) {
2189 Ext.dd.DragDropMgr.unregAll();
2193 * Cleans up the drag and drop events and objects.
2198 unregAll: function() {
2200 if (this.dragCurrent) {
2202 this.dragCurrent = null;
2205 this._execOnAll("unreg", []);
2207 for (var i in this.elementCache) {
2208 delete this.elementCache[i];
2211 this.elementCache = {};
2216 * A cache of DOM elements
2217 * @property elementCache
2224 * Get the wrapper for the DOM element specified
2225 * @method getElWrapper
2226 * @param {String} id the id of the element to get
2227 * @return {Ext.dd.DDM.ElementWrapper} the wrapped element
2229 * @deprecated This wrapper isn't that useful
2232 getElWrapper: function(id) {
2233 var oWrapper = this.elementCache[id];
2234 if (!oWrapper || !oWrapper.el) {
2235 oWrapper = this.elementCache[id] =
2236 new this.ElementWrapper(Ext.getDom(id));
2242 * Returns the actual DOM element
2243 * @method getElement
2244 * @param {String} id the id of the elment to get
2245 * @return {Object} The element
2246 * @deprecated use Ext.lib.Ext.getDom instead
2249 getElement: function(id) {
2250 return Ext.getDom(id);
2254 * Returns the style property for the DOM element (i.e.,
2255 * document.getElById(id).style)
2257 * @param {String} id the id of the elment to get
2258 * @return {Object} The style property of the element
2259 * @deprecated use Ext.lib.Dom instead
2262 getCss: function(id) {
2263 var el = Ext.getDom(id);
2264 return (el) ? el.style : null;
2268 * Inner class for cached elements
2269 * @class Ext.dd.DragDropMgr.ElementWrapper
2274 ElementWrapper: function(el) {
2279 this.el = el || null;
2284 this.id = this.el && el.id;
2286 * A reference to the style property
2289 this.css = this.el && el.style;
2293 * Returns the X position of an html element
2295 * @param el the element for which to get the position
2296 * @return {int} the X coordinate
2298 * @deprecated use Ext.lib.Dom.getX instead
2301 getPosX: function(el) {
2302 return Ext.lib.Dom.getX(el);
2306 * Returns the Y position of an html element
2308 * @param el the element for which to get the position
2309 * @return {int} the Y coordinate
2310 * @deprecated use Ext.lib.Dom.getY instead
2313 getPosY: function(el) {
2314 return Ext.lib.Dom.getY(el);
2318 * Swap two nodes. In IE, we use the native method, for others we
2319 * emulate the IE behavior
2321 * @param n1 the first node to swap
2322 * @param n2 the other node to swap
2325 swapNode: function(n1, n2) {
2329 var p = n2.parentNode;
2330 var s = n2.nextSibling;
2333 p.insertBefore(n1, n2);
2334 } else if (n2 == n1.nextSibling) {
2335 p.insertBefore(n2, n1);
2337 n1.parentNode.replaceChild(n2, n1);
2338 p.insertBefore(n1, s);
2344 * Returns the current scroll position
2349 getScroll: function () {
2350 var t, l, dde=document.documentElement, db=document.body;
2351 if (dde && (dde.scrollTop || dde.scrollLeft)) {
2360 return { top: t, left: l };
2364 * Returns the specified element style property
2366 * @param {HTMLElement} el the element
2367 * @param {string} styleProp the style property
2368 * @return {string} The value of the style property
2369 * @deprecated use Ext.lib.Dom.getStyle
2372 getStyle: function(el, styleProp) {
2373 return Ext.fly(el).getStyle(styleProp);
2377 * Gets the scrollTop
2378 * @method getScrollTop
2379 * @return {int} the document's scrollTop
2382 getScrollTop: function () {
2383 return this.getScroll().top;
2387 * Gets the scrollLeft
2388 * @method getScrollLeft
2389 * @return {int} the document's scrollTop
2392 getScrollLeft: function () {
2393 return this.getScroll().left;
2397 * Sets the x/y position of an element to the location of the
2400 * @param {HTMLElement} moveEl The element to move
2401 * @param {HTMLElement} targetEl The position reference element
2404 moveToEl: function (moveEl, targetEl) {
2405 var aCoord = Ext.lib.Dom.getXY(targetEl);
2406 Ext.lib.Dom.setXY(moveEl, aCoord);
2410 * Numeric array sort function
2411 * @method numericSort
2414 numericSort: function(a, b) {
2420 * @property _timeoutCount
2427 * Trying to make the load order less important. Without this we get
2428 * an error if this file is loaded before the Event Utility.
2429 * @method _addListeners
2433 _addListeners: function() {
2434 var DDM = Ext.dd.DDM;
2435 if ( Ext.lib.Event && document ) {
2438 if (DDM._timeoutCount > 2000) {
2440 setTimeout(DDM._addListeners, 10);
2441 if (document && document.body) {
2442 DDM._timeoutCount += 1;
2449 * Recursively searches the immediate parent and all child nodes for
2450 * the handle element in order to determine wheter or not it was
2452 * @method handleWasClicked
2453 * @param node the html element to inspect
2456 handleWasClicked: function(node, id) {
2457 if (this.isHandle(id, node.id)) {
2460 // check to see if this is a text node child of the one we want
2461 var p = node.parentNode;
2464 if (this.isHandle(id, p.id)) {
2479 // shorter alias, save a few bytes
2480 Ext.dd.DDM = Ext.dd.DragDropMgr;
2481 Ext.dd.DDM._addListeners();
2487 * A DragDrop implementation where the linked element follows the
2488 * mouse cursor during a drag.
2489 * @extends Ext.dd.DragDrop
2491 * @param {String} id the id of the linked element
2492 * @param {String} sGroup the group of related DragDrop items
2493 * @param {object} config an object containing configurable attributes
2494 * Valid properties for DD:
2497 Ext.dd.DD = function(id, sGroup, config) {
2499 this.init(id, sGroup, config);
2503 Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, {
2506 * When set to true, the utility automatically tries to scroll the browser
2507 * window when a drag and drop element is dragged near the viewport boundary.
2515 * Sets the pointer offset to the distance between the linked element's top
2516 * left corner and the location the element was clicked
2517 * @method autoOffset
2518 * @param {int} iPageX the X coordinate of the click
2519 * @param {int} iPageY the Y coordinate of the click
2521 autoOffset: function(iPageX, iPageY) {
2522 var x = iPageX - this.startPageX;
2523 var y = iPageY - this.startPageY;
2524 this.setDelta(x, y);
2528 * Sets the pointer offset. You can call this directly to force the
2529 * offset to be in a particular location (e.g., pass in 0,0 to set it
2530 * to the center of the object)
2532 * @param {int} iDeltaX the distance from the left
2533 * @param {int} iDeltaY the distance from the top
2535 setDelta: function(iDeltaX, iDeltaY) {
2536 this.deltaX = iDeltaX;
2537 this.deltaY = iDeltaY;
2541 * Sets the drag element to the location of the mousedown or click event,
2542 * maintaining the cursor location relative to the location on the element
2543 * that was clicked. Override this if you want to place the element in a
2544 * location other than where the cursor is.
2545 * @method setDragElPos
2546 * @param {int} iPageX the X coordinate of the mousedown or drag event
2547 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2549 setDragElPos: function(iPageX, iPageY) {
2550 // the first time we do this, we are going to check to make sure
2551 // the element has css positioning
2553 var el = this.getDragEl();
2554 this.alignElWithMouse(el, iPageX, iPageY);
2558 * Sets the element to the location of the mousedown or click event,
2559 * maintaining the cursor location relative to the location on the element
2560 * that was clicked. Override this if you want to place the element in a
2561 * location other than where the cursor is.
2562 * @method alignElWithMouse
2563 * @param {HTMLElement} el the element to move
2564 * @param {int} iPageX the X coordinate of the mousedown or drag event
2565 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2567 alignElWithMouse: function(el, iPageX, iPageY) {
2568 var oCoord = this.getTargetCoord(iPageX, iPageY);
2569 var fly = el.dom ? el : Ext.fly(el, '_dd');
2570 if (!this.deltaSetXY) {
2571 var aCoord = [oCoord.x, oCoord.y];
2573 var newLeft = fly.getLeft(true);
2574 var newTop = fly.getTop(true);
2575 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2577 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2580 this.cachePosition(oCoord.x, oCoord.y);
2581 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2586 * Saves the most recent position so that we can reset the constraints and
2587 * tick marks on-demand. We need to know this so that we can calculate the
2588 * number of pixels the element is offset from its original position.
2589 * @method cachePosition
2590 * @param iPageX the current x position (optional, this just makes it so we
2591 * don't have to look it up again)
2592 * @param iPageY the current y position (optional, this just makes it so we
2593 * don't have to look it up again)
2595 cachePosition: function(iPageX, iPageY) {
2597 this.lastPageX = iPageX;
2598 this.lastPageY = iPageY;
2600 var aCoord = Ext.lib.Dom.getXY(this.getEl());
2601 this.lastPageX = aCoord[0];
2602 this.lastPageY = aCoord[1];
2607 * Auto-scroll the window if the dragged object has been moved beyond the
2608 * visible window boundary.
2609 * @method autoScroll
2610 * @param {int} x the drag element's x position
2611 * @param {int} y the drag element's y position
2612 * @param {int} h the height of the drag element
2613 * @param {int} w the width of the drag element
2616 autoScroll: function(x, y, h, w) {
2619 // The client height
2620 var clientH = Ext.lib.Dom.getViewHeight();
2623 var clientW = Ext.lib.Dom.getViewWidth();
2625 // The amt scrolled down
2626 var st = this.DDM.getScrollTop();
2628 // The amt scrolled right
2629 var sl = this.DDM.getScrollLeft();
2631 // Location of the bottom of the element
2634 // Location of the right of the element
2637 // The distance from the cursor to the bottom of the visible area,
2638 // adjusted so that we don't scroll if the cursor is beyond the
2639 // element drag constraints
2640 var toBot = (clientH + st - y - this.deltaY);
2642 // The distance from the cursor to the right of the visible area
2643 var toRight = (clientW + sl - x - this.deltaX);
2646 // How close to the edge the cursor must be before we scroll
2647 // var thresh = (document.all) ? 100 : 40;
2650 // How many pixels to scroll per autoscroll op. This helps to reduce
2651 // clunky scrolling. IE is more sensitive about this ... it needs this
2652 // value to be higher.
2653 var scrAmt = (document.all) ? 80 : 30;
2655 // Scroll down if we are near the bottom of the visible page and the
2656 // obj extends below the crease
2657 if ( bot > clientH && toBot < thresh ) {
2658 window.scrollTo(sl, st + scrAmt);
2661 // Scroll up if the window is scrolled down and the top of the object
2662 // goes above the top border
2663 if ( y < st && st > 0 && y - st < thresh ) {
2664 window.scrollTo(sl, st - scrAmt);
2667 // Scroll right if the obj is beyond the right border and the cursor is
2669 if ( right > clientW && toRight < thresh ) {
2670 window.scrollTo(sl + scrAmt, st);
2673 // Scroll left if the window has been scrolled to the right and the obj
2674 // extends past the left border
2675 if ( x < sl && sl > 0 && x - sl < thresh ) {
2676 window.scrollTo(sl - scrAmt, st);
2682 * Finds the location the element should be placed if we want to move
2683 * it to where the mouse location less the click offset would place us.
2684 * @method getTargetCoord
2685 * @param {int} iPageX the X coordinate of the click
2686 * @param {int} iPageY the Y coordinate of the click
2687 * @return an object that contains the coordinates (Object.x and Object.y)
2690 getTargetCoord: function(iPageX, iPageY) {
2691 var x = iPageX - this.deltaX;
2692 var y = iPageY - this.deltaY;
2694 if (this.constrainX) {
2695 if (x < this.minX) { x = this.minX; }
2696 if (x > this.maxX) { x = this.maxX; }
2699 if (this.constrainY) {
2700 if (y < this.minY) { y = this.minY; }
2701 if (y > this.maxY) { y = this.maxY; }
2704 x = this.getTick(x, this.xTicks);
2705 y = this.getTick(y, this.yTicks);
2712 * Sets up config options specific to this class. Overrides
2713 * Ext.dd.DragDrop, but all versions of this method through the
2714 * inheritance chain are called
2716 applyConfig: function() {
2717 Ext.dd.DD.superclass.applyConfig.call(this);
2718 this.scroll = (this.config.scroll !== false);
2722 * Event that fires prior to the onMouseDown event. Overrides
2725 b4MouseDown: function(e) {
2726 // this.resetConstraints();
2727 this.autoOffset(e.getPageX(),
2732 * Event that fires prior to the onDrag event. Overrides
2735 b4Drag: function(e) {
2736 this.setDragElPos(e.getPageX(),
2740 toString: function() {
2741 return ("DD " + this.id);
2744 //////////////////////////////////////////////////////////////////////////
2745 // Debugging ygDragDrop events that can be overridden
2746 //////////////////////////////////////////////////////////////////////////
2748 startDrag: function(x, y) {
2751 onDrag: function(e) {
2754 onDragEnter: function(e, id) {
2757 onDragOver: function(e, id) {
2760 onDragOut: function(e, id) {
2763 onDragDrop: function(e, id) {
2766 endDrag: function(e) {
2773 * @class Ext.dd.DDProxy
2774 * A DragDrop implementation that inserts an empty, bordered div into
2775 * the document that follows the cursor during drag operations. At the time of
2776 * the click, the frame div is resized to the dimensions of the linked html
2777 * element, and moved to the exact location of the linked element.
2779 * References to the "frame" element refer to the single proxy element that
2780 * was created to be dragged in place of all DDProxy elements on the
2783 * @extends Ext.dd.DD
2785 * @param {String} id the id of the linked html element
2786 * @param {String} sGroup the group of related DragDrop objects
2787 * @param {object} config an object containing configurable attributes
2788 * Valid properties for DDProxy in addition to those in DragDrop:
2789 * resizeFrame, centerFrame, dragElId
2791 Ext.dd.DDProxy = function(id, sGroup, config) {
2793 this.init(id, sGroup, config);
2799 * The default drag frame div id
2800 * @property Ext.dd.DDProxy.dragElId
2804 Ext.dd.DDProxy.dragElId = "ygddfdiv";
2806 Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, {
2809 * By default we resize the drag frame to be the same size as the element
2810 * we want to drag (this is to get the frame effect). We can turn it off
2811 * if we want a different behavior.
2812 * @property resizeFrame
2818 * By default the frame is positioned exactly where the drag element is, so
2819 * we use the cursor offset provided by Ext.dd.DD. Another option that works only if
2820 * you do not have constraints on the obj is to have the drag frame centered
2821 * around the cursor. Set centerFrame to true for this effect.
2822 * @property centerFrame
2828 * Creates the proxy element if it does not yet exist
2829 * @method createFrame
2831 createFrame: function() {
2833 var body = document.body;
2835 if (!body || !body.firstChild) {
2836 setTimeout( function() { self.createFrame(); }, 50 );
2840 var div = this.getDragEl();
2843 div = document.createElement("div");
2844 div.id = this.dragElId;
2847 s.position = "absolute";
2848 s.visibility = "hidden";
2850 s.border = "2px solid #aaa";
2853 // appendChild can blow up IE if invoked prior to the window load event
2854 // while rendering a table. It is possible there are other scenarios
2855 // that would cause this to happen as well.
2856 body.insertBefore(div, body.firstChild);
2861 * Initialization for the drag frame element. Must be called in the
2862 * constructor of all subclasses
2865 initFrame: function() {
2869 applyConfig: function() {
2870 Ext.dd.DDProxy.superclass.applyConfig.call(this);
2872 this.resizeFrame = (this.config.resizeFrame !== false);
2873 this.centerFrame = (this.config.centerFrame);
2874 this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
2878 * Resizes the drag frame to the dimensions of the clicked object, positions
2879 * it over the object, and finally displays it
2881 * @param {int} iPageX X click position
2882 * @param {int} iPageY Y click position
2885 showFrame: function(iPageX, iPageY) {
2886 var el = this.getEl();
2887 var dragEl = this.getDragEl();
2888 var s = dragEl.style;
2890 this._resizeProxy();
2892 if (this.centerFrame) {
2893 this.setDelta( Math.round(parseInt(s.width, 10)/2),
2894 Math.round(parseInt(s.height, 10)/2) );
2897 this.setDragElPos(iPageX, iPageY);
2899 Ext.fly(dragEl).show();
2903 * The proxy is automatically resized to the dimensions of the linked
2904 * element when a drag is initiated, unless resizeFrame is set to false
2905 * @method _resizeProxy
2908 _resizeProxy: function() {
2909 if (this.resizeFrame) {
2910 var el = this.getEl();
2911 Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2915 // overrides Ext.dd.DragDrop
2916 b4MouseDown: function(e) {
2917 var x = e.getPageX();
2918 var y = e.getPageY();
2919 this.autoOffset(x, y);
2920 this.setDragElPos(x, y);
2923 // overrides Ext.dd.DragDrop
2924 b4StartDrag: function(x, y) {
2925 // show the drag frame
2926 this.showFrame(x, y);
2929 // overrides Ext.dd.DragDrop
2930 b4EndDrag: function(e) {
2931 Ext.fly(this.getDragEl()).hide();
2934 // overrides Ext.dd.DragDrop
2935 // By default we try to move the element to the last location of the frame.
2936 // This is so that the default behavior mirrors that of Ext.dd.DD.
2937 endDrag: function(e) {
2939 var lel = this.getEl();
2940 var del = this.getDragEl();
2942 // Show the drag frame briefly so we can get its position
2943 del.style.visibility = "";
2946 // Hide the linked element before the move to get around a Safari
2948 lel.style.visibility = "hidden";
2949 Ext.dd.DDM.moveToEl(lel, del);
2950 del.style.visibility = "hidden";
2951 lel.style.visibility = "";
2956 beforeMove : function(){
2960 afterDrag : function(){
2964 toString: function() {
2965 return ("DDProxy " + this.id);
2970 * @class Ext.dd.DDTarget
2971 * A DragDrop implementation that does not move, but can be a drop
2972 * target. You would get the same result by simply omitting implementation
2973 * for the event callbacks, but this way we reduce the processing cost of the
2974 * event listener and the callbacks.
2975 * @extends Ext.dd.DragDrop
2977 * @param {String} id the id of the element that is a drop target
2978 * @param {String} sGroup the group of related DragDrop objects
2979 * @param {object} config an object containing configurable attributes
2980 * Valid properties for DDTarget in addition to those in
2984 Ext.dd.DDTarget = function(id, sGroup, config) {
2986 this.initTarget(id, sGroup, config);
2990 // Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop();
2991 Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, {
2994 * Overridden and disabled. A DDTarget does not support being dragged.
2997 getDragEl: Ext.emptyFn,
3000 * Overridden and disabled. A DDTarget does not support being dragged.
3003 isValidHandleChild: Ext.emptyFn,
3006 * Overridden and disabled. A DDTarget does not support being dragged.
3009 startDrag: Ext.emptyFn,
3012 * Overridden and disabled. A DDTarget does not support being dragged.
3015 endDrag: Ext.emptyFn,
3018 * Overridden and disabled. A DDTarget does not support being dragged.
3021 onDrag: Ext.emptyFn,
3024 * Overridden and disabled. A DDTarget does not support being dragged.
3027 onDragDrop: Ext.emptyFn,
3030 * Overridden and disabled. A DDTarget does not support being dragged.
3033 onDragEnter: Ext.emptyFn,
3036 * Overridden and disabled. A DDTarget does not support being dragged.
3039 onDragOut: Ext.emptyFn,
3042 * Overridden and disabled. A DDTarget does not support being dragged.
3045 onDragOver: Ext.emptyFn,
3048 * Overridden and disabled. A DDTarget does not support being dragged.
3051 onInvalidDrop: Ext.emptyFn,
3054 * Overridden and disabled. A DDTarget does not support being dragged.
3057 onMouseDown: Ext.emptyFn,
3060 * Overridden and disabled. A DDTarget does not support being dragged.
3063 onMouseUp: Ext.emptyFn,
3066 * Overridden and disabled. A DDTarget does not support being dragged.
3069 setXConstraint: Ext.emptyFn,
3072 * Overridden and disabled. A DDTarget does not support being dragged.
3075 setYConstraint: Ext.emptyFn,
3078 * Overridden and disabled. A DDTarget does not support being dragged.
3081 resetConstraints: Ext.emptyFn,
3084 * Overridden and disabled. A DDTarget does not support being dragged.
3087 clearConstraints: Ext.emptyFn,
3090 * Overridden and disabled. A DDTarget does not support being dragged.
3093 clearTicks: Ext.emptyFn,
3096 * Overridden and disabled. A DDTarget does not support being dragged.
3099 setInitPosition: Ext.emptyFn,
3102 * Overridden and disabled. A DDTarget does not support being dragged.
3105 setDragElId: Ext.emptyFn,
3108 * Overridden and disabled. A DDTarget does not support being dragged.
3111 setHandleElId: Ext.emptyFn,
3114 * Overridden and disabled. A DDTarget does not support being dragged.
3117 setOuterHandleElId: Ext.emptyFn,
3120 * Overridden and disabled. A DDTarget does not support being dragged.
3123 addInvalidHandleClass: Ext.emptyFn,
3126 * Overridden and disabled. A DDTarget does not support being dragged.
3129 addInvalidHandleId: Ext.emptyFn,
3132 * Overridden and disabled. A DDTarget does not support being dragged.
3135 addInvalidHandleType: Ext.emptyFn,
3138 * Overridden and disabled. A DDTarget does not support being dragged.
3141 removeInvalidHandleClass: Ext.emptyFn,
3144 * Overridden and disabled. A DDTarget does not support being dragged.
3147 removeInvalidHandleId: Ext.emptyFn,
3150 * Overridden and disabled. A DDTarget does not support being dragged.
3153 removeInvalidHandleType: Ext.emptyFn,
3155 toString: function() {
3156 return ("DDTarget " + this.id);
3159 * @class Ext.dd.DragTracker
3160 * @extends Ext.util.Observable
3161 * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
3162 * as well as during the drag. This is useful for components such as {@link Ext.Slider}, where there is
3163 * an element that can be dragged around to change the Slider's value.
3164 * DragTracker provides a series of template methods that should be overridden to provide functionality
3165 * in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd.
3166 * See {@link Ext.Slider}'s initEvents function for an example implementation.
3168 Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
3170 * @cfg {Boolean} active
3171 * Defaults to <tt>false</tt>.
3175 * @cfg {Number} tolerance
3176 * Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>.
3180 * @cfg {Boolean/Number} autoStart
3181 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
3182 * Specify a Number for the number of milliseconds to defer trigger start.
3186 constructor : function(config){
3187 Ext.apply(this, config);
3191 * @param {Object} this
3192 * @param {Object} e event object
3197 * @param {Object} this
3198 * @param {Object} e event object
3203 * @param {Object} this
3204 * @param {Object} e event object
3209 * @param {Object} this
3210 * @param {Object} startXY the page coordinates of the event
3215 * @param {Object} this
3216 * @param {Object} e event object
3221 * @param {Object} this
3222 * @param {Object} e event object
3227 this.dragRegion = new Ext.lib.Region(0,0,0,0);
3230 this.initEl(this.el);
3232 Ext.dd.DragTracker.superclass.constructor.call(this, config);
3235 initEl: function(el){
3236 this.el = Ext.get(el);
3237 el.on('mousedown', this.onMouseDown, this,
3238 this.delegate ? {delegate: this.delegate} : undefined);
3241 destroy : function(){
3242 this.el.un('mousedown', this.onMouseDown, this);
3245 onMouseDown: function(e, target){
3246 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
3247 this.startXY = this.lastXY = e.getXY();
3248 this.dragTarget = this.delegate ? target : this.el.dom;
3249 if(this.preventDefault !== false){
3252 var doc = Ext.getDoc();
3253 doc.on('mouseup', this.onMouseUp, this);
3254 doc.on('mousemove', this.onMouseMove, this);
3255 doc.on('selectstart', this.stopSelect, this);
3257 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
3262 onMouseMove: function(e, target){
3263 // HACK: IE hack to see if button was released outside of window. */
3264 if(this.active && Ext.isIE && !e.browserEvent.button){
3271 var xy = e.getXY(), s = this.startXY;
3274 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
3275 this.triggerStart();
3280 this.fireEvent('mousemove', this, e);
3282 this.fireEvent('drag', this, e);
3285 onMouseUp: function(e) {
3286 var doc = Ext.getDoc();
3287 doc.un('mousemove', this.onMouseMove, this);
3288 doc.un('mouseup', this.onMouseUp, this);
3289 doc.un('selectstart', this.stopSelect, this);
3292 var wasActive = this.active;
3293 this.active = false;
3294 delete this.elRegion;
3295 this.fireEvent('mouseup', this, e);
3298 this.fireEvent('dragend', this, e);
3302 triggerStart: function(isTimer) {
3305 this.onStart(this.startXY);
3306 this.fireEvent('dragstart', this, this.startXY);
3309 clearStart : function() {
3311 clearTimeout(this.timer);
3316 stopSelect : function(e) {
3322 * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
3323 * holds the mouse button down. Return false to disallow the drag
3324 * @param {Ext.EventObject} e The event object
3326 onBeforeStart : function(e) {
3331 * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
3332 * (e.g. the user has moved the tracked element beyond the specified tolerance)
3333 * @param {Array} xy x and y co-ordinates of the original location of the tracked element
3335 onStart : function(xy) {
3340 * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
3341 * @param {Ext.EventObject} e The event object
3343 onDrag : function(e) {
3348 * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
3349 * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
3350 * @param {Ext.EventObject} e The event object
3352 onEnd : function(e) {
3357 * Returns the drag target
3358 * @return {Ext.Element} The element currently being tracked
3360 getDragTarget : function(){
3361 return this.dragTarget;
3364 getDragCt : function(){
3368 getXY : function(constrain){
3370 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
3373 getOffset : function(constrain){
3374 var xy = this.getXY(constrain);
3375 var s = this.startXY;
3376 return [s[0]-xy[0], s[1]-xy[1]];
3380 'point' : function(xy){
3383 this.elRegion = this.getDragCt().getRegion();
3386 var dr = this.dragRegion;
3393 dr.constrainTo(this.elRegion);
3395 return [dr.left, dr.top];
3399 * @class Ext.dd.ScrollManager
3400 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
3401 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
3402 * but you can also override most of the configs per scroll container by adding a
3403 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
3404 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
3406 var el = Ext.get('scroll-ct');
3407 el.ddScrollConfig = {
3413 Ext.dd.ScrollManager.register(el);
3415 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
3418 Ext.dd.ScrollManager = function(){
3419 var ddm = Ext.dd.DragDropMgr;
3424 var onStop = function(e){
3429 var triggerRefresh = function(){
3430 if(ddm.dragCurrent){
3431 ddm.refreshCache(ddm.dragCurrent.groups);
3435 var doScroll = function(){
3436 if(ddm.dragCurrent){
3437 var dds = Ext.dd.ScrollManager;
3438 var inc = proc.el.ddScrollConfig ?
3439 proc.el.ddScrollConfig.increment : dds.increment;
3441 if(proc.el.scroll(proc.dir, inc)){
3445 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
3450 var clearProc = function(){
3452 clearInterval(proc.id);
3459 var startProc = function(el, dir){
3463 var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
3464 el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;
3465 proc.id = setInterval(doScroll, freq);
3468 var onFire = function(e, isDrop){
3469 if(isDrop || !ddm.dragCurrent){ return; }
3470 var dds = Ext.dd.ScrollManager;
3471 if(!dragEl || dragEl != ddm.dragCurrent){
3472 dragEl = ddm.dragCurrent;
3473 // refresh regions on drag start
3477 var xy = Ext.lib.Event.getXY(e);
3478 var pt = new Ext.lib.Point(xy[0], xy[1]);
3480 var el = els[id], r = el._region;
3481 var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
3482 if(r && r.contains(pt) && el.isScrollable()){
3483 if(r.bottom - pt.y <= c.vthresh){
3485 startProc(el, "down");
3488 }else if(r.right - pt.x <= c.hthresh){
3490 startProc(el, "left");
3493 }else if(pt.y - r.top <= c.vthresh){
3495 startProc(el, "up");
3498 }else if(pt.x - r.left <= c.hthresh){
3500 startProc(el, "right");
3509 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
3510 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
3514 * Registers new overflow element(s) to auto scroll
3515 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
3517 register : function(el){
3518 if(Ext.isArray(el)){
3519 for(var i = 0, len = el.length; i < len; i++) {
3520 this.register(el[i]);
3529 * Unregisters overflow element(s) so they are no longer scrolled
3530 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
3532 unregister : function(el){
3533 if(Ext.isArray(el)){
3534 for(var i = 0, len = el.length; i < len; i++) {
3535 this.unregister(el[i]);
3544 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
3545 * trigger scrolling (defaults to 25)
3550 * The number of pixels from the right or left edge of a container the pointer needs to be to
3551 * trigger scrolling (defaults to 25)
3557 * The number of pixels to scroll in each scroll increment (defaults to 50)
3563 * The frequency of scrolls in milliseconds (defaults to 500)
3569 * True to animate the scroll (defaults to true)
3575 * The animation duration in seconds -
3576 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
3582 * Manually trigger a cache refresh.
3584 refreshCache : function(){
3586 if(typeof els[id] == 'object'){ // for people extending the object prototype
3587 els[id]._region = els[id].getRegion();
3593 * @class Ext.dd.Registry
3594 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
3595 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
3598 Ext.dd.Registry = function(){
3603 var getId = function(el, autogen){
3604 if(typeof el == "string"){
3608 if(!id && autogen !== false){
3609 id = "extdd-" + (++autoIdSeed);
3617 * Resgister a drag drop element
3618 * @param {String/HTMLElement} element The id or DOM node to register
3619 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
3620 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
3621 * knows how to interpret, plus there are some specific properties known to the Registry that should be
3622 * populated in the data object (if applicable):
3624 Value Description<br />
3625 --------- ------------------------------------------<br />
3626 handles Array of DOM nodes that trigger dragging<br />
3627 for the element being registered<br />
3628 isHandle True if the element passed in triggers<br />
3629 dragging itself, else false
3632 register : function(el, data){
3634 if(typeof el == "string"){
3635 el = document.getElementById(el);
3638 elements[getId(el)] = data;
3639 if(data.isHandle !== false){
3640 handles[data.ddel.id] = data;
3643 var hs = data.handles;
3644 for(var i = 0, len = hs.length; i < len; i++){
3645 handles[getId(hs[i])] = data;
3651 * Unregister a drag drop element
3652 * @param {String/HTMLElement} element The id or DOM node to unregister
3654 unregister : function(el){
3655 var id = getId(el, false);
3656 var data = elements[id];
3658 delete elements[id];
3660 var hs = data.handles;
3661 for(var i = 0, len = hs.length; i < len; i++){
3662 delete handles[getId(hs[i], false)];
3669 * Returns the handle registered for a DOM Node by id
3670 * @param {String/HTMLElement} id The DOM node or id to look up
3671 * @return {Object} handle The custom handle data
3673 getHandle : function(id){
3674 if(typeof id != "string"){ // must be element?
3681 * Returns the handle that is registered for the DOM node that is the target of the event
3682 * @param {Event} e The event
3683 * @return {Object} handle The custom handle data
3685 getHandleFromEvent : function(e){
3686 var t = Ext.lib.Event.getTarget(e);
3687 return t ? handles[t.id] : null;
3691 * Returns a custom data object that is registered for a DOM node by id
3692 * @param {String/HTMLElement} id The DOM node or id to look up
3693 * @return {Object} data The custom data
3695 getTarget : function(id){
3696 if(typeof id != "string"){ // must be element?
3699 return elements[id];
3703 * Returns a custom data object that is registered for the DOM node that is the target of the event
3704 * @param {Event} e The event
3705 * @return {Object} data The custom data
3707 getTargetFromEvent : function(e){
3708 var t = Ext.lib.Event.getTarget(e);
3709 return t ? elements[t.id] || handles[t.id] : null;
3713 * @class Ext.dd.StatusProxy
3714 * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair. This is the
3715 * default drag proxy used by all Ext.dd components.
3717 * @param {Object} config
3719 Ext.dd.StatusProxy = function(config){
3720 Ext.apply(this, config);
3721 this.id = this.id || Ext.id();
3722 this.el = new Ext.Layer({
3724 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
3725 {tag: "div", cls: "x-dd-drop-icon"},
3726 {tag: "div", cls: "x-dd-drag-ghost"}
3729 shadow: !config || config.shadow !== false
3731 this.ghost = Ext.get(this.el.dom.childNodes[1]);
3732 this.dropStatus = this.dropNotAllowed;
3735 Ext.dd.StatusProxy.prototype = {
3737 * @cfg {String} dropAllowed
3738 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
3740 dropAllowed : "x-dd-drop-ok",
3742 * @cfg {String} dropNotAllowed
3743 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
3745 dropNotAllowed : "x-dd-drop-nodrop",
3748 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
3749 * over the current target element.
3750 * @param {String} cssClass The css class for the new drop status indicator image
3752 setStatus : function(cssClass){
3753 cssClass = cssClass || this.dropNotAllowed;
3754 if(this.dropStatus != cssClass){
3755 this.el.replaceClass(this.dropStatus, cssClass);
3756 this.dropStatus = cssClass;
3761 * Resets the status indicator to the default dropNotAllowed value
3762 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
3764 reset : function(clearGhost){
3765 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
3766 this.dropStatus = this.dropNotAllowed;
3768 this.ghost.update("");
3773 * Updates the contents of the ghost element
3774 * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a
3775 * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).
3777 update : function(html){
3778 if(typeof html == "string"){
3779 this.ghost.update(html);
3781 this.ghost.update("");
3782 html.style.margin = "0";
3783 this.ghost.dom.appendChild(html);
3785 var el = this.ghost.dom.firstChild;
3787 Ext.fly(el).setStyle('float', 'none');
3792 * Returns the underlying proxy {@link Ext.Layer}
3793 * @return {Ext.Layer} el
3800 * Returns the ghost element
3801 * @return {Ext.Element} el
3803 getGhost : function(){
3809 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
3811 hide : function(clear){
3819 * Stops the repair animation if it's currently running
3822 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
3828 * Displays this proxy
3835 * Force the Layer to sync its shadow and shim positions to the element
3842 * Causes the proxy to return to its position of origin via an animation. Should be called after an
3843 * invalid drop operation by the item being dragged.
3844 * @param {Array} xy The XY position of the element ([x, y])
3845 * @param {Function} callback The function to call after the repair is complete.
3846 * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
3848 repair : function(xy, callback, scope){
3849 this.callback = callback;
3851 if(xy && this.animRepair !== false){
3852 this.el.addClass("x-dd-drag-repair");
3853 this.el.hideUnders(true);
3854 this.anim = this.el.shift({
3855 duration: this.repairDuration || .5,
3859 callback: this.afterRepair,
3868 afterRepair : function(){
3870 if(typeof this.callback == "function"){
3871 this.callback.call(this.scope || this);
3873 this.callback = null;
3877 destroy: function(){
3878 Ext.destroy(this.ghost, this.el);
3881 * @class Ext.dd.DragSource
3882 * @extends Ext.dd.DDProxy
3883 * A simple class that provides the basic implementation needed to make any element draggable.
3885 * @param {Mixed} el The container element
3886 * @param {Object} config
3888 Ext.dd.DragSource = function(el, config){
3889 this.el = Ext.get(el);
3894 Ext.apply(this, config);
3897 this.proxy = new Ext.dd.StatusProxy();
3899 Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
3900 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
3902 this.dragging = false;
3905 Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
3907 * @cfg {String} ddGroup
3908 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
3909 * interact with other drag drop objects in the same group (defaults to undefined).
3912 * @cfg {String} dropAllowed
3913 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3915 dropAllowed : "x-dd-drop-ok",
3917 * @cfg {String} dropNotAllowed
3918 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3920 dropNotAllowed : "x-dd-drop-nodrop",
3923 * Returns the data object associated with this drag source
3924 * @return {Object} data An object containing arbitrary data
3926 getDragData : function(e){
3927 return this.dragData;
3931 onDragEnter : function(e, id){
3932 var target = Ext.dd.DragDropMgr.getDDById(id);
3933 this.cachedTarget = target;
3934 if(this.beforeDragEnter(target, e, id) !== false){
3935 if(target.isNotifyTarget){
3936 var status = target.notifyEnter(this, e, this.dragData);
3937 this.proxy.setStatus(status);
3939 this.proxy.setStatus(this.dropAllowed);
3942 if(this.afterDragEnter){
3944 * An empty function by default, but provided so that you can perform a custom action
3945 * when the dragged item enters the drop target by providing an implementation.
3946 * @param {Ext.dd.DragDrop} target The drop target
3947 * @param {Event} e The event object
3948 * @param {String} id The id of the dragged element
3949 * @method afterDragEnter
3951 this.afterDragEnter(target, e, id);
3957 * An empty function by default, but provided so that you can perform a custom action
3958 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
3959 * @param {Ext.dd.DragDrop} target The drop target
3960 * @param {Event} e The event object
3961 * @param {String} id The id of the dragged element
3962 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3964 beforeDragEnter : function(target, e, id){
3969 alignElWithMouse: function() {
3970 Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
3975 onDragOver : function(e, id){
3976 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
3977 if(this.beforeDragOver(target, e, id) !== false){
3978 if(target.isNotifyTarget){
3979 var status = target.notifyOver(this, e, this.dragData);
3980 this.proxy.setStatus(status);
3983 if(this.afterDragOver){
3985 * An empty function by default, but provided so that you can perform a custom action
3986 * while the dragged item is over the drop target by providing an implementation.
3987 * @param {Ext.dd.DragDrop} target The drop target
3988 * @param {Event} e The event object
3989 * @param {String} id The id of the dragged element
3990 * @method afterDragOver
3992 this.afterDragOver(target, e, id);
3998 * An empty function by default, but provided so that you can perform a custom action
3999 * while the dragged item is over the drop target and optionally cancel the onDragOver.
4000 * @param {Ext.dd.DragDrop} target The drop target
4001 * @param {Event} e The event object
4002 * @param {String} id The id of the dragged element
4003 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
4005 beforeDragOver : function(target, e, id){
4010 onDragOut : function(e, id){
4011 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
4012 if(this.beforeDragOut(target, e, id) !== false){
4013 if(target.isNotifyTarget){
4014 target.notifyOut(this, e, this.dragData);
4017 if(this.afterDragOut){
4019 * An empty function by default, but provided so that you can perform a custom action
4020 * after the dragged item is dragged out of the target without dropping.
4021 * @param {Ext.dd.DragDrop} target The drop target
4022 * @param {Event} e The event object
4023 * @param {String} id The id of the dragged element
4024 * @method afterDragOut
4026 this.afterDragOut(target, e, id);
4029 this.cachedTarget = null;
4033 * An empty function by default, but provided so that you can perform a custom action before the dragged
4034 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
4035 * @param {Ext.dd.DragDrop} target The drop target
4036 * @param {Event} e The event object
4037 * @param {String} id The id of the dragged element
4038 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
4040 beforeDragOut : function(target, e, id){
4045 onDragDrop : function(e, id){
4046 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
4047 if(this.beforeDragDrop(target, e, id) !== false){
4048 if(target.isNotifyTarget){
4049 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
4050 this.onValidDrop(target, e, id);
4052 this.onInvalidDrop(target, e, id);
4055 this.onValidDrop(target, e, id);
4058 if(this.afterDragDrop){
4060 * An empty function by default, but provided so that you can perform a custom action
4061 * after a valid drag drop has occurred by providing an implementation.
4062 * @param {Ext.dd.DragDrop} target The drop target
4063 * @param {Event} e The event object
4064 * @param {String} id The id of the dropped element
4065 * @method afterDragDrop
4067 this.afterDragDrop(target, e, id);
4070 delete this.cachedTarget;
4074 * An empty function by default, but provided so that you can perform a custom action before the dragged
4075 * item is dropped onto the target and optionally cancel the onDragDrop.
4076 * @param {Ext.dd.DragDrop} target The drop target
4077 * @param {Event} e The event object
4078 * @param {String} id The id of the dragged element
4079 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
4081 beforeDragDrop : function(target, e, id){
4086 onValidDrop : function(target, e, id){
4088 if(this.afterValidDrop){
4090 * An empty function by default, but provided so that you can perform a custom action
4091 * after a valid drop has occurred by providing an implementation.
4092 * @param {Object} target The target DD
4093 * @param {Event} e The event object
4094 * @param {String} id The id of the dropped element
4095 * @method afterInvalidDrop
4097 this.afterValidDrop(target, e, id);
4102 getRepairXY : function(e, data){
4103 return this.el.getXY();
4107 onInvalidDrop : function(target, e, id){
4108 this.beforeInvalidDrop(target, e, id);
4109 if(this.cachedTarget){
4110 if(this.cachedTarget.isNotifyTarget){
4111 this.cachedTarget.notifyOut(this, e, this.dragData);
4113 this.cacheTarget = null;
4115 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
4117 if(this.afterInvalidDrop){
4119 * An empty function by default, but provided so that you can perform a custom action
4120 * after an invalid drop has occurred by providing an implementation.
4121 * @param {Event} e The event object
4122 * @param {String} id The id of the dropped element
4123 * @method afterInvalidDrop
4125 this.afterInvalidDrop(e, id);
4130 afterRepair : function(){
4132 this.el.highlight(this.hlColor || "c3daf9");
4134 this.dragging = false;
4138 * An empty function by default, but provided so that you can perform a custom action after an invalid
4139 * drop has occurred.
4140 * @param {Ext.dd.DragDrop} target The drop target
4141 * @param {Event} e The event object
4142 * @param {String} id The id of the dragged element
4143 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
4145 beforeInvalidDrop : function(target, e, id){
4150 handleMouseDown : function(e){
4154 var data = this.getDragData(e);
4155 if(data && this.onBeforeDrag(data, e) !== false){
4156 this.dragData = data;
4158 Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
4163 * An empty function by default, but provided so that you can perform a custom action before the initial
4164 * drag event begins and optionally cancel it.
4165 * @param {Object} data An object containing arbitrary data to be shared with drop targets
4166 * @param {Event} e The event object
4167 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
4169 onBeforeDrag : function(data, e){
4174 * An empty function by default, but provided so that you can perform a custom action once the initial
4175 * drag event has begun. The drag cannot be canceled from this function.
4176 * @param {Number} x The x position of the click on the dragged object
4177 * @param {Number} y The y position of the click on the dragged object
4179 onStartDrag : Ext.emptyFn,
4182 startDrag : function(x, y){
4184 this.dragging = true;
4185 this.proxy.update("");
4186 this.onInitDrag(x, y);
4191 onInitDrag : function(x, y){
4192 var clone = this.el.dom.cloneNode(true);
4193 clone.id = Ext.id(); // prevent duplicate ids
4194 this.proxy.update(clone);
4195 this.onStartDrag(x, y);
4200 * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
4201 * @return {Ext.dd.StatusProxy} proxy The StatusProxy
4203 getProxy : function(){
4208 * Hides the drag source's {@link Ext.dd.StatusProxy}
4210 hideProxy : function(){
4212 this.proxy.reset(true);
4213 this.dragging = false;
4217 triggerCacheRefresh : function(){
4218 Ext.dd.DDM.refreshCache(this.groups);
4221 // private - override to prevent hiding
4222 b4EndDrag: function(e) {
4225 // private - override to prevent moving
4226 endDrag : function(e){
4227 this.onEndDrag(this.dragData, e);
4231 onEndDrag : function(data, e){
4234 // private - pin to cursor
4235 autoOffset : function(x, y) {
4236 this.setDelta(-12, -20);
4239 destroy: function(){
4240 Ext.dd.DragSource.superclass.destroy.call(this);
4241 Ext.destroy(this.proxy);
4244 * @class Ext.dd.DropTarget
4245 * @extends Ext.dd.DDTarget
4246 * A simple class that provides the basic implementation needed to make any element a drop target that can have
4247 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
4249 * @param {Mixed} el The container element
4250 * @param {Object} config
4252 Ext.dd.DropTarget = function(el, config){
4253 this.el = Ext.get(el);
4255 Ext.apply(this, config);
4257 if(this.containerScroll){
4258 Ext.dd.ScrollManager.register(this.el);
4261 Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
4266 Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, {
4268 * @cfg {String} ddGroup
4269 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
4270 * interact with other drag drop objects in the same group (defaults to undefined).
4273 * @cfg {String} overClass
4274 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
4277 * @cfg {String} dropAllowed
4278 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
4280 dropAllowed : "x-dd-drop-ok",
4282 * @cfg {String} dropNotAllowed
4283 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
4285 dropNotAllowed : "x-dd-drop-nodrop",
4291 isNotifyTarget : true,
4294 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the
4295 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
4296 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
4297 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
4298 * @param {Event} e The event
4299 * @param {Object} data An object containing arbitrary data supplied by the drag source
4300 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4301 * underlying {@link Ext.dd.StatusProxy} can be updated
4303 notifyEnter : function(dd, e, data){
4305 this.el.addClass(this.overClass);
4307 return this.dropAllowed;
4311 * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.
4312 * This method will be called on every mouse movement while the drag source is over the drop target.
4313 * This default implementation simply returns the dropAllowed config value.
4314 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
4315 * @param {Event} e The event
4316 * @param {Object} data An object containing arbitrary data supplied by the drag source
4317 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4318 * underlying {@link Ext.dd.StatusProxy} can be updated
4320 notifyOver : function(dd, e, data){
4321 return this.dropAllowed;
4325 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged
4326 * out of the target without dropping. This default implementation simply removes the CSS class specified by
4327 * overClass (if any) from the drop element.
4328 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
4329 * @param {Event} e The event
4330 * @param {Object} data An object containing arbitrary data supplied by the drag source
4332 notifyOut : function(dd, e, data){
4334 this.el.removeClass(this.overClass);
4339 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has
4340 * been dropped on it. This method has no default implementation and returns false, so you must provide an
4341 * implementation that does something to process the drop event and returns true so that the drag source's
4342 * repair action does not run.
4343 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
4344 * @param {Event} e The event
4345 * @param {Object} data An object containing arbitrary data supplied by the drag source
4346 * @return {Boolean} True if the drop was valid, else false
4348 notifyDrop : function(dd, e, data){
4352 * @class Ext.dd.DragZone
4353 * @extends Ext.dd.DragSource
4354 * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
4355 * <p>This class does not move the drag target nodes, but a proxy element which may contain
4356 * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
4357 * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
4358 * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
4359 * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
4360 * is the most efficient way to "activate" those nodes.</p>
4361 * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
4362 * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
4363 * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
4364 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
4365 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
4366 * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
4367 * technique. Knowledge of the use of the DataView is required:</p><pre><code>
4368 myDataView.on('render', function(v) {
4369 myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
4371 // On receipt of a mousedown event, see if it is within a DataView node.
4372 // Return a drag data object if so.
4373 getDragData: function(e) {
4375 // Use the DataView's own itemSelector (a mandatory property) to
4376 // test if the mousedown is within one of the DataView's nodes.
4377 var sourceEl = e.getTarget(v.itemSelector, 10);
4379 // If the mousedown is within a DataView node, clone the node to produce
4380 // a ddel element for use by the drag proxy. Also add application data
4381 // to the returned data object.
4383 d = sourceEl.cloneNode(true);
4388 repairXY: Ext.fly(sourceEl).getXY(),
4389 sourceStore: v.store,
4390 draggedRecord: v.{@link Ext.DataView#getRecord getRecord}(sourceEl)
4395 // Provide coordinates for the proxy to slide back to on failed drag.
4396 // This is the original XY coordinates of the draggable element captured
4397 // in the getDragData method.
4398 getRepairXY: function() {
4399 return this.dragData.repairXY;
4403 * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
4404 * cooperates with this DragZone.
4406 * @param {Mixed} el The container element
4407 * @param {Object} config
4409 Ext.dd.DragZone = function(el, config){
4410 Ext.dd.DragZone.superclass.constructor.call(this, el, config);
4411 if(this.containerScroll){
4412 Ext.dd.ScrollManager.register(this.el);
4416 Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
4418 * This property contains the data representing the dragged object. This data is set up by the implementation
4419 * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
4420 * any other data according to the application's needs.
4422 * @property dragData
4425 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
4426 * for auto scrolling during drag operations.
4429 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
4430 * method after a failed drop (defaults to "c3daf9" - light blue)
4434 * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
4435 * for a valid target to drag based on the mouse down. Override this method
4436 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
4437 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
4438 * @param {EventObject} e The mouse down event
4439 * @return {Object} The dragData
4441 getDragData : function(e){
4442 return Ext.dd.Registry.getHandleFromEvent(e);
4446 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
4447 * this.dragData.ddel
4448 * @param {Number} x The x position of the click on the dragged object
4449 * @param {Number} y The y position of the click on the dragged object
4450 * @return {Boolean} true to continue the drag, false to cancel
4452 onInitDrag : function(x, y){
4453 this.proxy.update(this.dragData.ddel.cloneNode(true));
4454 this.onStartDrag(x, y);
4459 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
4461 afterRepair : function(){
4463 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4465 this.dragging = false;
4469 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
4470 * the XY of this.dragData.ddel
4471 * @param {EventObject} e The mouse up event
4472 * @return {Array} The xy location (e.g. [100, 200])
4474 getRepairXY : function(e){
4475 return Ext.Element.fly(this.dragData.ddel).getXY();
4478 * @class Ext.dd.DropZone
4479 * @extends Ext.dd.DropTarget
4480 * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>
4481 * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
4482 * However a simpler way to allow a DropZone to manage any number of target elements is to configure the
4483 * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
4484 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
4485 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
4486 * {@link Ext.DomQuery} selector.</p>
4487 * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
4488 * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
4489 * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
4490 * of these methods to provide application-specific behaviour for these events to update both
4491 * application state, and UI state.</p>
4492 * <p>For example to make a GridPanel a cooperating target with the example illustrated in
4493 * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>
4494 myGridPanel.on('render', function() {
4495 myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
4497 // If the mouse is over a grid row, return that node. This is
4498 // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
4499 getTargetFromEvent: function(e) {
4500 return e.getTarget(myGridPanel.getView().rowSelector);
4503 // On entry into a target node, highlight that node.
4504 onNodeEnter : function(target, dd, e, data){
4505 Ext.fly(target).addClass('my-row-highlight-class');
4508 // On exit from a target node, unhighlight that node.
4509 onNodeOut : function(target, dd, e, data){
4510 Ext.fly(target).removeClass('my-row-highlight-class');
4513 // While over a target node, return the default drop allowed class which
4514 // places a "tick" icon into the drag proxy.
4515 onNodeOver : function(target, dd, e, data){
4516 return Ext.dd.DropZone.prototype.dropAllowed;
4519 // On node drop we can interrogate the target to find the underlying
4520 // application object that is the real target of the dragged data.
4521 // In this case, it is a Record in the GridPanel's Store.
4522 // We can use the data set up by the DragZone's getDragData method to read
4523 // any data we decided to attach in the DragZone's getDragData method.
4524 onNodeDrop : function(target, dd, e, data){
4525 var rowIndex = myGridPanel.getView().findRowIndex(target);
4526 var r = myGridPanel.getStore().getAt(rowIndex);
4527 Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
4528 ' on Record id ' + r.id);
4534 * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
4535 * cooperates with this DropZone.
4537 * @param {Mixed} el The container element
4538 * @param {Object} config
4540 Ext.dd.DropZone = function(el, config){
4541 Ext.dd.DropZone.superclass.constructor.call(this, el, config);
4544 Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {
4546 * Returns a custom data object associated with the DOM node that is the target of the event. By default
4547 * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
4548 * provide your own custom lookup.
4549 * @param {Event} e The event
4550 * @return {Object} data The custom data
4552 getTargetFromEvent : function(e){
4553 return Ext.dd.Registry.getTargetFromEvent(e);
4557 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
4558 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
4559 * This method has no default implementation and should be overridden to provide
4560 * node-specific processing if necessary.
4561 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4562 * {@link #getTargetFromEvent} for this node)
4563 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4564 * @param {Event} e The event
4565 * @param {Object} data An object containing arbitrary data supplied by the drag source
4567 onNodeEnter : function(n, dd, e, data){
4572 * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
4573 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
4574 * The default implementation returns this.dropNotAllowed, so it should be
4575 * overridden to provide the proper feedback.
4576 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4577 * {@link #getTargetFromEvent} for this node)
4578 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4579 * @param {Event} e The event
4580 * @param {Object} data An object containing arbitrary data supplied by the drag source
4581 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4582 * underlying {@link Ext.dd.StatusProxy} can be updated
4584 onNodeOver : function(n, dd, e, data){
4585 return this.dropAllowed;
4589 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
4590 * the drop node without dropping. This method has no default implementation and should be overridden to provide
4591 * node-specific processing if necessary.
4592 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4593 * {@link #getTargetFromEvent} for this node)
4594 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4595 * @param {Event} e The event
4596 * @param {Object} data An object containing arbitrary data supplied by the drag source
4598 onNodeOut : function(n, dd, e, data){
4603 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
4604 * the drop node. The default implementation returns false, so it should be overridden to provide the
4605 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
4606 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4607 * {@link #getTargetFromEvent} for this node)
4608 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4609 * @param {Event} e The event
4610 * @param {Object} data An object containing arbitrary data supplied by the drag source
4611 * @return {Boolean} True if the drop was valid, else false
4613 onNodeDrop : function(n, dd, e, data){
4618 * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
4619 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
4620 * it should be overridden to provide the proper feedback if necessary.
4621 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4622 * @param {Event} e The event
4623 * @param {Object} data An object containing arbitrary data supplied by the drag source
4624 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4625 * underlying {@link Ext.dd.StatusProxy} can be updated
4627 onContainerOver : function(dd, e, data){
4628 return this.dropNotAllowed;
4632 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
4633 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
4634 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
4635 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
4636 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4637 * @param {Event} e The event
4638 * @param {Object} data An object containing arbitrary data supplied by the drag source
4639 * @return {Boolean} True if the drop was valid, else false
4641 onContainerDrop : function(dd, e, data){
4646 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
4647 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
4648 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
4649 * you should override this method and provide a custom implementation.
4650 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4651 * @param {Event} e The event
4652 * @param {Object} data An object containing arbitrary data supplied by the drag source
4653 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4654 * underlying {@link Ext.dd.StatusProxy} can be updated
4656 notifyEnter : function(dd, e, data){
4657 return this.dropNotAllowed;
4661 * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
4662 * This method will be called on every mouse movement while the drag source is over the drop zone.
4663 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
4664 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
4665 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
4666 * registered node, it will call {@link #onContainerOver}.
4667 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4668 * @param {Event} e The event
4669 * @param {Object} data An object containing arbitrary data supplied by the drag source
4670 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4671 * underlying {@link Ext.dd.StatusProxy} can be updated
4673 notifyOver : function(dd, e, data){
4674 var n = this.getTargetFromEvent(e);
4675 if(!n){ // not over valid drop target
4676 if(this.lastOverNode){
4677 this.onNodeOut(this.lastOverNode, dd, e, data);
4678 this.lastOverNode = null;
4680 return this.onContainerOver(dd, e, data);
4682 if(this.lastOverNode != n){
4683 if(this.lastOverNode){
4684 this.onNodeOut(this.lastOverNode, dd, e, data);
4686 this.onNodeEnter(n, dd, e, data);
4687 this.lastOverNode = n;
4689 return this.onNodeOver(n, dd, e, data);
4693 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
4694 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
4695 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
4696 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
4697 * @param {Event} e The event
4698 * @param {Object} data An object containing arbitrary data supplied by the drag zone
4700 notifyOut : function(dd, e, data){
4701 if(this.lastOverNode){
4702 this.onNodeOut(this.lastOverNode, dd, e, data);
4703 this.lastOverNode = null;
4708 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
4709 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
4710 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
4711 * otherwise it will call {@link #onContainerDrop}.
4712 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
4713 * @param {Event} e The event
4714 * @param {Object} data An object containing arbitrary data supplied by the drag source
4715 * @return {Boolean} True if the drop was valid, else false
4717 notifyDrop : function(dd, e, data){
4718 if(this.lastOverNode){
4719 this.onNodeOut(this.lastOverNode, dd, e, data);
4720 this.lastOverNode = null;
4722 var n = this.getTargetFromEvent(e);
4724 this.onNodeDrop(n, dd, e, data) :
4725 this.onContainerDrop(dd, e, data);
4729 triggerCacheRefresh : function(){
4730 Ext.dd.DDM.refreshCache(this.groups);
4733 * @class Ext.Element
4735 Ext.Element.addMethods({
4737 * Initializes a {@link Ext.dd.DD} drag drop object for this element.
4738 * @param {String} group The group the DD object is member of
4739 * @param {Object} config The DD config object
4740 * @param {Object} overrides An object containing methods to override/implement on the DD object
4741 * @return {Ext.dd.DD} The DD object
4743 initDD : function(group, config, overrides){
4744 var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
4745 return Ext.apply(dd, overrides);
4749 * Initializes a {@link Ext.dd.DDProxy} object for this element.
4750 * @param {String} group The group the DDProxy object is member of
4751 * @param {Object} config The DDProxy config object
4752 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
4753 * @return {Ext.dd.DDProxy} The DDProxy object
4755 initDDProxy : function(group, config, overrides){
4756 var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
4757 return Ext.apply(dd, overrides);
4761 * Initializes a {@link Ext.dd.DDTarget} object for this element.
4762 * @param {String} group The group the DDTarget object is member of
4763 * @param {Object} config The DDTarget config object
4764 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
4765 * @return {Ext.dd.DDTarget} The DDTarget object
4767 initDDTarget : function(group, config, overrides){
4768 var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
4769 return Ext.apply(dd, overrides);