3 * Copyright(c) 2006-2009 Ext JS, LLC
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.
190 lock: function() { this.locked = true; },
193 * When set to true, other DD objects in cooperating DDGroups do not receive
194 * notification events when this DD object is dragged over them. Defaults to false.
201 * Unlock this instace
204 unlock: function() { this.locked = false; },
207 * By default, all instances can be a drop target. This can be disabled by
208 * setting isTarget to false.
215 * The padding configured for this drag and drop object for calculating
216 * the drop zone intersection with this object.
218 * @type int[] An array containing the 4 padding values: [top, right, bottom, left]
223 * Cached reference to the linked element
230 * Internal typeof flag
231 * @property __ygDragDrop
237 * Set to true when horizontal contraints are applied
238 * @property constrainX
245 * Set to true when vertical contraints are applied
246 * @property constrainY
253 * The left constraint
261 * The right constraint
278 * The down constraint
286 * Maintain offsets when we resetconstraints. Set to true when you want
287 * the position of the element relative to its parent to stay the same
288 * when the page changes
290 * @property maintainOffset
293 maintainOffset: false,
296 * Array of pixel locations the element will snap to if we specified a
297 * horizontal graduation/interval. This array is generated automatically
298 * when you define a tick interval.
305 * Array of pixel locations the element will snap to if we specified a
306 * vertical graduation/interval. This array is generated automatically
307 * when you define a tick interval.
314 * By default the drag and drop instance will only respond to the primary
315 * button click (left button for a right-handed mouse). Set to true to
316 * allow drag and drop to start with any mouse click that is propogated
318 * @property primaryButtonOnly
321 primaryButtonOnly: true,
324 * The availabe property is false until the linked dom element is accessible.
325 * @property available
331 * By default, drags can only be initiated if the mousedown occurs in the
332 * region the linked element is. This is done in part to work around a
333 * bug in some browsers that mis-report the mousedown if the previous
334 * mouseup happened outside of the window. This property is set to true
335 * if outer handles are defined.
337 * @property hasOuterHandles
341 hasOuterHandles: false,
344 * Code that executes immediately before the startDrag event
345 * @method b4StartDrag
348 b4StartDrag: function(x, y) { },
351 * Abstract method called after a drag/drop object is clicked
352 * and the drag or mousedown time thresholds have beeen met.
354 * @param {int} X click location
355 * @param {int} Y click location
357 startDrag: function(x, y) { /* override this */ },
360 * Code that executes immediately before the onDrag event
364 b4Drag: function(e) { },
367 * Abstract method called during the onMouseMove event while dragging an
370 * @param {Event} e the mousemove event
372 onDrag: function(e) { /* override this */ },
375 * Abstract method called when this element fist begins hovering over
376 * another DragDrop obj
377 * @method onDragEnter
378 * @param {Event} e the mousemove event
379 * @param {String|DragDrop[]} id In POINT mode, the element
380 * id this is hovering over. In INTERSECT mode, an array of one or more
381 * dragdrop items being hovered over.
383 onDragEnter: function(e, id) { /* override this */ },
386 * Code that executes immediately before the onDragOver event
390 b4DragOver: function(e) { },
393 * Abstract method called when this element is hovering over another
396 * @param {Event} e the mousemove event
397 * @param {String|DragDrop[]} id In POINT mode, the element
398 * id this is hovering over. In INTERSECT mode, an array of dd items
399 * being hovered over.
401 onDragOver: function(e, id) { /* override this */ },
404 * Code that executes immediately before the onDragOut event
408 b4DragOut: function(e) { },
411 * Abstract method called when we are no longer hovering over an element
413 * @param {Event} e the mousemove event
414 * @param {String|DragDrop[]} id In POINT mode, the element
415 * id this was hovering over. In INTERSECT mode, an array of dd items
416 * that the mouse is no longer over.
418 onDragOut: function(e, id) { /* override this */ },
421 * Code that executes immediately before the onDragDrop event
425 b4DragDrop: function(e) { },
428 * Abstract method called when this item is dropped on another DragDrop
431 * @param {Event} e the mouseup event
432 * @param {String|DragDrop[]} id In POINT mode, the element
433 * id this was dropped on. In INTERSECT mode, an array of dd items this
436 onDragDrop: function(e, id) { /* override this */ },
439 * Abstract method called when this item is dropped on an area with no
441 * @method onInvalidDrop
442 * @param {Event} e the mouseup event
444 onInvalidDrop: function(e) { /* override this */ },
447 * Code that executes immediately before the endDrag event
451 b4EndDrag: function(e) { },
454 * Fired when we are done dragging the object
456 * @param {Event} e the mouseup event
458 endDrag: function(e) { /* override this */ },
461 * Code executed immediately before the onMouseDown event
462 * @method b4MouseDown
463 * @param {Event} e the mousedown event
466 b4MouseDown: function(e) { },
469 * Event handler that fires when a drag/drop obj gets a mousedown
470 * @method onMouseDown
471 * @param {Event} e the mousedown event
473 onMouseDown: function(e) { /* override this */ },
476 * Event handler that fires when a drag/drop obj gets a mouseup
478 * @param {Event} e the mouseup event
480 onMouseUp: function(e) { /* override this */ },
483 * Override the onAvailable method to do what is needed after the initial
484 * position was determined.
485 * @method onAvailable
487 onAvailable: function () {
491 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
494 defaultPadding : {left:0, right:0, top:0, bottom:0},
497 * Initializes the drag drop object's constraints to restrict movement to a certain element.
501 var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
502 { dragElId: "existingProxyDiv" });
503 dd.startDrag = function(){
504 this.constrainTo("parent-id");
507 * Or you can initalize it using the {@link Ext.Element} object:
509 Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
510 startDrag : function(){
511 this.constrainTo("parent-id");
515 * @param {Mixed} constrainTo The element to constrain to.
516 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
517 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
518 * an object containing the sides to pad. For example: {right:10, bottom:10}
519 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
521 constrainTo : function(constrainTo, pad, inContent){
522 if(typeof pad == "number"){
523 pad = {left: pad, right:pad, top:pad, bottom:pad};
525 pad = pad || this.defaultPadding;
526 var b = Ext.get(this.getEl()).getBox();
527 var ce = Ext.get(constrainTo);
528 var s = ce.getScroll();
530 if(cd == document.body){
531 c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()};
534 c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
538 var topSpace = b.y - c.y;
539 var leftSpace = b.x - c.x;
541 this.resetConstraints();
542 this.setXConstraint(leftSpace - (pad.left||0), // left
543 c.width - leftSpace - b.width - (pad.right||0), //right
546 this.setYConstraint(topSpace - (pad.top||0), //top
547 c.height - topSpace - b.height - (pad.bottom||0), //bottom
553 * Returns a reference to the linked element
555 * @return {HTMLElement} the html element
559 this._domRef = Ext.getDom(this.id);
566 * Returns a reference to the actual element to drag. By default this is
567 * the same as the html element, but it can be assigned to another
568 * element. An example of this can be found in Ext.dd.DDProxy
570 * @return {HTMLElement} the html element
572 getDragEl: function() {
573 return Ext.getDom(this.dragElId);
577 * Sets up the DragDrop object. Must be called in the constructor of any
578 * Ext.dd.DragDrop subclass
580 * @param id the id of the linked element
581 * @param {String} sGroup the group of related items
582 * @param {object} config configuration attributes
584 init: function(id, sGroup, config) {
585 this.initTarget(id, sGroup, config);
586 Event.on(this.id, "mousedown", this.handleMouseDown, this);
587 // Event.on(this.id, "selectstart", Event.preventDefault);
591 * Initializes Targeting functionality only... the object does not
592 * get a mousedown handler.
594 * @param id the id of the linked element
595 * @param {String} sGroup the group of related items
596 * @param {object} config configuration attributes
598 initTarget: function(id, sGroup, config) {
600 // configuration attributes
601 this.config = config || {};
603 // create a local reference to the drag and drop manager
604 this.DDM = Ext.dd.DDM;
605 // initialize the groups array
608 // assume that we have an element reference instead of an id if the
609 // parameter is not a string
610 if (typeof id !== "string") {
617 // add to an interaction group
618 this.addToGroup((sGroup) ? sGroup : "default");
620 // We don't want to register this as the handle with the manager
621 // so we just set the id rather than calling the setter.
622 this.handleElId = id;
624 // the linked element is the element that gets dragged by default
625 this.setDragElId(id);
627 // by default, clicked anchors will not start drag operations.
628 this.invalidHandleTypes = { A: "A" };
629 this.invalidHandleIds = {};
630 this.invalidHandleClasses = [];
634 this.handleOnAvailable();
638 * Applies the configuration parameters that were passed into the constructor.
639 * This is supposed to happen at each level through the inheritance chain. So
640 * a DDProxy implentation will execute apply config on DDProxy, DD, and
641 * DragDrop in order to get all of the parameters that are available in
643 * @method applyConfig
645 applyConfig: function() {
647 // configurable properties:
648 // padding, isTarget, maintainOffset, primaryButtonOnly
649 this.padding = this.config.padding || [0, 0, 0, 0];
650 this.isTarget = (this.config.isTarget !== false);
651 this.maintainOffset = (this.config.maintainOffset);
652 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
657 * Executed when the linked element is available
658 * @method handleOnAvailable
661 handleOnAvailable: function() {
662 this.available = true;
663 this.resetConstraints();
668 * Configures the padding for the target zone in px. Effectively expands
669 * (or reduces) the virtual object size for targeting calculations.
670 * Supports css-style shorthand; if only one parameter is passed, all sides
671 * will have that padding, and if only two are passed, the top and bottom
672 * will have the first param, the left and right the second.
674 * @param {int} iTop Top pad
675 * @param {int} iRight Right pad
676 * @param {int} iBot Bot pad
677 * @param {int} iLeft Left pad
679 setPadding: function(iTop, iRight, iBot, iLeft) {
680 // this.padding = [iLeft, iRight, iTop, iBot];
681 if (!iRight && 0 !== iRight) {
682 this.padding = [iTop, iTop, iTop, iTop];
683 } else if (!iBot && 0 !== iBot) {
684 this.padding = [iTop, iRight, iTop, iRight];
686 this.padding = [iTop, iRight, iBot, iLeft];
691 * Stores the initial placement of the linked element.
692 * @method setInitPosition
693 * @param {int} diffX the X offset, default 0
694 * @param {int} diffY the Y offset, default 0
696 setInitPosition: function(diffX, diffY) {
697 var el = this.getEl();
699 if (!this.DDM.verifyEl(el)) {
706 var p = Dom.getXY( el );
708 this.initPageX = p[0] - dx;
709 this.initPageY = p[1] - dy;
711 this.lastPageX = p[0];
712 this.lastPageY = p[1];
715 this.setStartPosition(p);
719 * Sets the start position of the element. This is set when the obj
720 * is initialized, the reset when a drag is started.
721 * @method setStartPosition
722 * @param pos current position (from previous lookup)
725 setStartPosition: function(pos) {
726 var p = pos || Dom.getXY( this.getEl() );
727 this.deltaSetXY = null;
729 this.startPageX = p[0];
730 this.startPageY = p[1];
734 * Add this instance to a group of related drag/drop objects. All
735 * instances belong to at least one group, and can belong to as many
738 * @param sGroup {string} the name of the group
740 addToGroup: function(sGroup) {
741 this.groups[sGroup] = true;
742 this.DDM.regDragDrop(this, sGroup);
746 * Remove's this instance from the supplied interaction group
747 * @method removeFromGroup
748 * @param {string} sGroup The group to drop
750 removeFromGroup: function(sGroup) {
751 if (this.groups[sGroup]) {
752 delete this.groups[sGroup];
755 this.DDM.removeDDFromGroup(this, sGroup);
759 * Allows you to specify that an element other than the linked element
760 * will be moved with the cursor during a drag
761 * @method setDragElId
762 * @param id {string} the id of the element that will be used to initiate the drag
764 setDragElId: function(id) {
769 * Allows you to specify a child of the linked element that should be
770 * used to initiate the drag operation. An example of this would be if
771 * you have a content div with text and links. Clicking anywhere in the
772 * content area would normally start the drag operation. Use this method
773 * to specify that an element inside of the content div is the element
774 * that starts the drag operation.
775 * @method setHandleElId
776 * @param id {string} the id of the element that will be used to
779 setHandleElId: function(id) {
780 if (typeof id !== "string") {
783 this.handleElId = id;
784 this.DDM.regHandle(this.id, id);
788 * Allows you to set an element outside of the linked element as a drag
790 * @method setOuterHandleElId
791 * @param id the id of the element that will be used to initiate the drag
793 setOuterHandleElId: function(id) {
794 if (typeof id !== "string") {
797 Event.on(id, "mousedown",
798 this.handleMouseDown, this);
799 this.setHandleElId(id);
801 this.hasOuterHandles = true;
805 * Remove all drag and drop hooks for this element
809 Event.un(this.id, "mousedown",
810 this.handleMouseDown);
812 this.DDM._remove(this);
815 destroy : function(){
820 * Returns true if this instance is locked, or the drag drop mgr is locked
821 * (meaning that all drag/drop is disabled on the page.)
823 * @return {boolean} true if this obj or all drag/drop is locked, else
826 isLocked: function() {
827 return (this.DDM.isLocked() || this.locked);
831 * Fired when this object is clicked
832 * @method handleMouseDown
834 * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
837 handleMouseDown: function(e, oDD){
838 if (this.primaryButtonOnly && e.button != 0) {
842 if (this.isLocked()) {
846 this.DDM.refreshCache(this.groups);
848 var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e));
849 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
851 if (this.clickValidator(e)) {
853 // set the initial element position
854 this.setStartPosition();
860 this.DDM.handleMouseDown(e, this);
862 this.DDM.stopEvent(e);
870 clickValidator: function(e) {
871 var target = e.getTarget();
872 return ( this.isValidHandleChild(target) &&
873 (this.id == this.handleElId ||
874 this.DDM.handleWasClicked(target, this.id)) );
878 * Allows you to specify a tag name that should not start a drag operation
879 * when clicked. This is designed to facilitate embedding links within a
880 * drag handle that do something other than start the drag.
881 * @method addInvalidHandleType
882 * @param {string} tagName the type of element to exclude
884 addInvalidHandleType: function(tagName) {
885 var type = tagName.toUpperCase();
886 this.invalidHandleTypes[type] = type;
890 * Lets you to specify an element id for a child of a drag handle
891 * that should not initiate a drag
892 * @method addInvalidHandleId
893 * @param {string} id the element id of the element you wish to ignore
895 addInvalidHandleId: function(id) {
896 if (typeof id !== "string") {
899 this.invalidHandleIds[id] = id;
903 * Lets you specify a css class of elements that will not initiate a drag
904 * @method addInvalidHandleClass
905 * @param {string} cssClass the class of the elements you wish to ignore
907 addInvalidHandleClass: function(cssClass) {
908 this.invalidHandleClasses.push(cssClass);
912 * Unsets an excluded tag name set by addInvalidHandleType
913 * @method removeInvalidHandleType
914 * @param {string} tagName the type of element to unexclude
916 removeInvalidHandleType: function(tagName) {
917 var type = tagName.toUpperCase();
918 // this.invalidHandleTypes[type] = null;
919 delete this.invalidHandleTypes[type];
923 * Unsets an invalid handle id
924 * @method removeInvalidHandleId
925 * @param {string} id the id of the element to re-enable
927 removeInvalidHandleId: function(id) {
928 if (typeof id !== "string") {
931 delete this.invalidHandleIds[id];
935 * Unsets an invalid css class
936 * @method removeInvalidHandleClass
937 * @param {string} cssClass the class of the element(s) you wish to
940 removeInvalidHandleClass: function(cssClass) {
941 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
942 if (this.invalidHandleClasses[i] == cssClass) {
943 delete this.invalidHandleClasses[i];
949 * Checks the tag exclusion list to see if this click should be ignored
950 * @method isValidHandleChild
951 * @param {HTMLElement} node the HTMLElement to evaluate
952 * @return {boolean} true if this is a valid tag type, false if not
954 isValidHandleChild: function(node) {
957 // var n = (node.nodeName == "#text") ? node.parentNode : node;
960 nodeName = node.nodeName.toUpperCase();
962 nodeName = node.nodeName;
964 valid = valid && !this.invalidHandleTypes[nodeName];
965 valid = valid && !this.invalidHandleIds[node.id];
967 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
968 valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]);
977 * Create the array of horizontal tick marks if an interval was specified
978 * in setXConstraint().
982 setXTicks: function(iStartX, iTickSize) {
984 this.xTickSize = iTickSize;
988 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
990 this.xTicks[this.xTicks.length] = i;
995 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
997 this.xTicks[this.xTicks.length] = i;
1002 this.xTicks.sort(this.DDM.numericSort) ;
1006 * Create the array of vertical tick marks if an interval was specified in
1011 setYTicks: function(iStartY, iTickSize) {
1013 this.yTickSize = iTickSize;
1017 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1019 this.yTicks[this.yTicks.length] = i;
1024 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1026 this.yTicks[this.yTicks.length] = i;
1031 this.yTicks.sort(this.DDM.numericSort) ;
1035 * By default, the element can be dragged any place on the screen. Use
1036 * this method to limit the horizontal travel of the element. Pass in
1037 * 0,0 for the parameters if you want to lock the drag to the y axis.
1038 * @method setXConstraint
1039 * @param {int} iLeft the number of pixels the element can move to the left
1040 * @param {int} iRight the number of pixels the element can move to the
1042 * @param {int} iTickSize optional parameter for specifying that the
1044 * should move iTickSize pixels at a time.
1046 setXConstraint: function(iLeft, iRight, iTickSize) {
1047 this.leftConstraint = iLeft;
1048 this.rightConstraint = iRight;
1050 this.minX = this.initPageX - iLeft;
1051 this.maxX = this.initPageX + iRight;
1052 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1054 this.constrainX = true;
1058 * Clears any constraints applied to this instance. Also clears ticks
1059 * since they can't exist independent of a constraint at this time.
1060 * @method clearConstraints
1062 clearConstraints: function() {
1063 this.constrainX = false;
1064 this.constrainY = false;
1069 * Clears any tick interval defined for this instance
1070 * @method clearTicks
1072 clearTicks: function() {
1080 * By default, the element can be dragged any place on the screen. Set
1081 * this to limit the vertical travel of the element. Pass in 0,0 for the
1082 * parameters if you want to lock the drag to the x axis.
1083 * @method setYConstraint
1084 * @param {int} iUp the number of pixels the element can move up
1085 * @param {int} iDown the number of pixels the element can move down
1086 * @param {int} iTickSize optional parameter for specifying that the
1087 * element should move iTickSize pixels at a time.
1089 setYConstraint: function(iUp, iDown, iTickSize) {
1090 this.topConstraint = iUp;
1091 this.bottomConstraint = iDown;
1093 this.minY = this.initPageY - iUp;
1094 this.maxY = this.initPageY + iDown;
1095 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1097 this.constrainY = true;
1102 * resetConstraints must be called if you manually reposition a dd element.
1103 * @method resetConstraints
1104 * @param {boolean} maintainOffset
1106 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) {
1148 // If tick interval is not defined, it is effectively 1 pixel,
1149 // so we return the value passed to us.
1151 } else if (tickArray[0] >= val) {
1152 // The value is lower than the first tick, so we return the first
1154 return tickArray[0];
1156 for (var i=0, len=tickArray.length; i<len; ++i) {
1158 if (tickArray[next] && tickArray[next] >= val) {
1159 var diff1 = val - tickArray[i];
1160 var diff2 = tickArray[next] - val;
1161 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1165 // The value is larger than the last tick, so we return the last
1167 return tickArray[tickArray.length - 1];
1174 * @return {string} string representation of the dd obj
1176 toString: function() {
1177 return ("DragDrop " + this.id);
1184 * The drag and drop utility provides a framework for building drag and drop
1185 * applications. In addition to enabling drag and drop for specific elements,
1186 * the drag and drop elements are tracked by the manager class, and the
1187 * interactions between the various elements are tracked during the drag and
1188 * the implementing code is notified about these important moments.
1191 // Only load the library once. Rewriting the manager class would orphan
1192 // existing drag and drop instances.
1193 if (!Ext.dd.DragDropMgr) {
1196 * @class Ext.dd.DragDropMgr
1197 * DragDropMgr is a singleton that tracks the element interaction for
1198 * all DragDrop items in the window. Generally, you will not call
1199 * this class directly, but it does have helper methods that could
1200 * be useful in your DragDrop implementations.
1203 Ext.dd.DragDropMgr = function() {
1205 var Event = Ext.EventManager;
1210 * Two dimensional Array of registered DragDrop objects. The first
1211 * dimension is the DragDrop item group, the second the DragDrop
1214 * @type {string: string}
1221 * Array of element ids defined as drag handles. Used to determine
1222 * if the element that generated the mousedown event is actually the
1223 * handle and not the html element itself.
1224 * @property handleIds
1225 * @type {string: string}
1232 * the DragDrop object that is currently being dragged
1233 * @property dragCurrent
1241 * the DragDrop object(s) that are being hovered over
1242 * @property dragOvers
1250 * the X distance between the cursor and the object being dragged
1259 * the Y distance between the cursor and the object being dragged
1268 * Flag to determine if we should prevent the default behavior of the
1269 * events we define. By default this is true, but this can be set to
1270 * false if you need the default behavior (not recommended)
1271 * @property preventDefault
1275 preventDefault: true,
1278 * Flag to determine if we should stop the propagation of the events
1279 * we generate. This is true by default but you may want to set it to
1280 * false if the html element contains other features that require the
1282 * @property stopPropagation
1286 stopPropagation: true,
1289 * Internal flag that is set to true when drag and drop has been
1291 * @property initialized
1298 * All drag and drop can be disabled.
1306 * Called the first time an element is registered.
1312 this.initialized = true;
1316 * In point mode, drag and drop interaction is defined by the
1317 * location of the cursor during the drag/drop
1325 * In intersect mode, drag and drop interaction is defined by the
1326 * overlap of two or more drag and drop objects.
1327 * @property INTERSECT
1334 * The current drag and drop mode. Default: POINT
1342 * Runs method on all drag and drop objects
1343 * @method _execOnAll
1347 _execOnAll: function(sMethod, args) {
1348 for (var i in this.ids) {
1349 for (var j in this.ids[i]) {
1350 var oDD = this.ids[i][j];
1351 if (! this.isTypeOfDD(oDD)) {
1354 oDD[sMethod].apply(oDD, args);
1360 * Drag and drop initialization. Sets up the global event handlers
1365 _onLoad: function() {
1370 Event.on(document, "mouseup", this.handleMouseUp, this, true);
1371 Event.on(document, "mousemove", this.handleMouseMove, this, true);
1372 Event.on(window, "unload", this._onUnload, this, true);
1373 Event.on(window, "resize", this._onResize, this, true);
1374 // Event.on(window, "mouseout", this._test);
1379 * Reset constraints on all drag and drop objs
1384 _onResize: function(e) {
1385 this._execOnAll("resetConstraints", []);
1389 * Lock all drag and drop functionality
1393 lock: function() { this.locked = true; },
1396 * Unlock all drag and drop functionality
1400 unlock: function() { this.locked = false; },
1403 * Is drag and drop locked?
1405 * @return {boolean} True if drag and drop is locked, false otherwise.
1408 isLocked: function() { return this.locked; },
1411 * Location cache that is set for all drag drop objects when a drag is
1412 * initiated, cleared when the drag is finished.
1413 * @property locationCache
1420 * Set useCache to false if you want to force object the lookup of each
1421 * drag and drop linked element constantly during a drag.
1422 * @property useCache
1429 * The number of pixels that the mouse needs to move after the
1430 * mousedown before the drag is initiated. Default=3;
1431 * @property clickPixelThresh
1435 clickPixelThresh: 3,
1438 * The number of milliseconds after the mousedown event to initiate the
1439 * drag if we don't get a mouseup event. Default=1000
1440 * @property clickTimeThresh
1444 clickTimeThresh: 350,
1447 * Flag that indicates that either the drag pixel threshold or the
1448 * mousdown time threshold has been met
1449 * @property dragThreshMet
1454 dragThreshMet: false,
1457 * Timeout used for the click time threshold
1458 * @property clickTimeout
1466 * The X position of the mousedown event stored for later use when a
1467 * drag threshold is met.
1476 * The Y position of the mousedown event stored for later use when a
1477 * drag threshold is met.
1486 * Each DragDrop instance must be registered with the DragDropMgr.
1487 * This is executed in DragDrop.init()
1488 * @method regDragDrop
1489 * @param {DragDrop} oDD the DragDrop object to register
1490 * @param {String} sGroup the name of the group this element belongs to
1493 regDragDrop: function(oDD, sGroup) {
1494 if (!this.initialized) { this.init(); }
1496 if (!this.ids[sGroup]) {
1497 this.ids[sGroup] = {};
1499 this.ids[sGroup][oDD.id] = oDD;
1503 * Removes the supplied dd instance from the supplied group. Executed
1504 * by DragDrop.removeFromGroup, so don't call this function directly.
1505 * @method removeDDFromGroup
1509 removeDDFromGroup: function(oDD, sGroup) {
1510 if (!this.ids[sGroup]) {
1511 this.ids[sGroup] = {};
1514 var obj = this.ids[sGroup];
1515 if (obj && obj[oDD.id]) {
1521 * Unregisters a drag and drop item. This is executed in
1522 * DragDrop.unreg, use that method instead of calling this directly.
1527 _remove: function(oDD) {
1528 for (var g in oDD.groups) {
1529 if (g && this.ids[g] && this.ids[g][oDD.id]) {
1530 delete this.ids[g][oDD.id];
1533 delete this.handleIds[oDD.id];
1537 * Each DragDrop handle element must be registered. This is done
1538 * automatically when executing DragDrop.setHandleElId()
1540 * @param {String} sDDId the DragDrop id this element is a handle for
1541 * @param {String} sHandleId the id of the element that is the drag
1545 regHandle: function(sDDId, sHandleId) {
1546 if (!this.handleIds[sDDId]) {
1547 this.handleIds[sDDId] = {};
1549 this.handleIds[sDDId][sHandleId] = sHandleId;
1553 * Utility function to determine if a given element has been
1554 * registered as a drag drop item.
1555 * @method isDragDrop
1556 * @param {String} id the element id to check
1557 * @return {boolean} true if this element is a DragDrop item,
1561 isDragDrop: function(id) {
1562 return ( this.getDDById(id) ) ? true : false;
1566 * Returns the drag and drop instances that are in all groups the
1567 * passed in instance belongs to.
1568 * @method getRelated
1569 * @param {DragDrop} p_oDD the obj to get related data for
1570 * @param {boolean} bTargetsOnly if true, only return targetable objs
1571 * @return {DragDrop[]} the related instances
1574 getRelated: function(p_oDD, bTargetsOnly) {
1576 for (var i in p_oDD.groups) {
1577 for (var j in this.ids[i]) {
1578 var dd = this.ids[i][j];
1579 if (! this.isTypeOfDD(dd)) {
1582 if (!bTargetsOnly || dd.isTarget) {
1583 oDDs[oDDs.length] = dd;
1592 * Returns true if the specified dd target is a legal target for
1593 * the specifice drag obj
1594 * @method isLegalTarget
1595 * @param {DragDrop} the drag obj
1596 * @param {DragDrop} the target
1597 * @return {boolean} true if the target is a legal target for the
1601 isLegalTarget: function (oDD, oTargetDD) {
1602 var targets = this.getRelated(oDD, true);
1603 for (var i=0, len=targets.length;i<len;++i) {
1604 if (targets[i].id == oTargetDD.id) {
1613 * My goal is to be able to transparently determine if an object is
1614 * typeof DragDrop, and the exact subclass of DragDrop. typeof
1615 * returns "object", oDD.constructor.toString() always returns
1616 * "DragDrop" and not the name of the subclass. So for now it just
1617 * evaluates a well-known variable in DragDrop.
1618 * @method isTypeOfDD
1619 * @param {Object} the object to evaluate
1620 * @return {boolean} true if typeof oDD = DragDrop
1623 isTypeOfDD: function (oDD) {
1624 return (oDD && oDD.__ygDragDrop);
1628 * Utility function to determine if a given element has been
1629 * registered as a drag drop handle for the given Drag Drop object.
1631 * @param {String} id the element id to check
1632 * @return {boolean} true if this element is a DragDrop handle, false
1636 isHandle: function(sDDId, sHandleId) {
1637 return ( this.handleIds[sDDId] &&
1638 this.handleIds[sDDId][sHandleId] );
1642 * Returns the DragDrop instance for a given id
1644 * @param {String} id the id of the DragDrop object
1645 * @return {DragDrop} the drag drop object, null if it is not found
1648 getDDById: function(id) {
1649 for (var i in this.ids) {
1650 if (this.ids[i][id]) {
1651 return this.ids[i][id];
1658 * Fired after a registered DragDrop object gets the mousedown event.
1659 * Sets up the events required to track the object being dragged
1660 * @method handleMouseDown
1661 * @param {Event} e the event
1662 * @param oDD the DragDrop object being dragged
1666 handleMouseDown: function(e, oDD) {
1668 Ext.QuickTips.disable();
1670 if(this.dragCurrent){
1671 // the original browser mouseup wasn't handled (e.g. outside FF browser window)
1672 // so clean up first to avoid breaking the next drag
1673 this.handleMouseUp(e);
1676 this.currentTarget = e.getTarget();
1677 this.dragCurrent = oDD;
1679 var el = oDD.getEl();
1681 // track start position
1682 this.startX = e.getPageX();
1683 this.startY = e.getPageY();
1685 this.deltaX = this.startX - el.offsetLeft;
1686 this.deltaY = this.startY - el.offsetTop;
1688 this.dragThreshMet = false;
1690 this.clickTimeout = setTimeout(
1692 var DDM = Ext.dd.DDM;
1693 DDM.startDrag(DDM.startX, DDM.startY);
1695 this.clickTimeThresh );
1699 * Fired when either the drag pixel threshol or the mousedown hold
1700 * time threshold has been met.
1702 * @param x {int} the X position of the original mousedown
1703 * @param y {int} the Y position of the original mousedown
1706 startDrag: function(x, y) {
1707 clearTimeout(this.clickTimeout);
1708 if (this.dragCurrent) {
1709 this.dragCurrent.b4StartDrag(x, y);
1710 this.dragCurrent.startDrag(x, y);
1712 this.dragThreshMet = true;
1716 * Internal function to handle the mouseup event. Will be invoked
1717 * from the context of the document.
1718 * @method handleMouseUp
1719 * @param {Event} e the event
1723 handleMouseUp: function(e) {
1726 Ext.QuickTips.enable();
1728 if (! this.dragCurrent) {
1732 clearTimeout(this.clickTimeout);
1734 if (this.dragThreshMet) {
1735 this.fireEvents(e, true);
1745 * Utility to stop event propagation and event default, if these
1746 * features are turned on.
1748 * @param {Event} e the event as returned by this.getEvent()
1751 stopEvent: function(e){
1752 if(this.stopPropagation) {
1753 e.stopPropagation();
1756 if (this.preventDefault) {
1762 * Internal function to clean up event handlers after the drag
1763 * operation is complete
1765 * @param {Event} e the event
1769 stopDrag: function(e) {
1770 // Fire the drag end event for the item that was dragged
1771 if (this.dragCurrent) {
1772 if (this.dragThreshMet) {
1773 this.dragCurrent.b4EndDrag(e);
1774 this.dragCurrent.endDrag(e);
1777 this.dragCurrent.onMouseUp(e);
1780 this.dragCurrent = null;
1781 this.dragOvers = {};
1785 * Internal function to handle the mousemove event. Will be invoked
1786 * from the context of the html element.
1788 * @TODO figure out what we can do about mouse events lost when the
1789 * user drags objects beyond the window boundary. Currently we can
1790 * detect this in internet explorer by verifying that the mouse is
1791 * down during the mousemove event. Firefox doesn't give us the
1792 * button state on the mousemove event.
1793 * @method handleMouseMove
1794 * @param {Event} e the event
1798 handleMouseMove: function(e) {
1799 if (! this.dragCurrent) {
1802 // var button = e.which || e.button;
1804 // check for IE mouseup outside of page boundary
1805 if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1807 return this.handleMouseUp(e);
1810 if (!this.dragThreshMet) {
1811 var diffX = Math.abs(this.startX - e.getPageX());
1812 var diffY = Math.abs(this.startY - e.getPageY());
1813 if (diffX > this.clickPixelThresh ||
1814 diffY > this.clickPixelThresh) {
1815 this.startDrag(this.startX, this.startY);
1819 if (this.dragThreshMet) {
1820 this.dragCurrent.b4Drag(e);
1821 this.dragCurrent.onDrag(e);
1822 if(!this.dragCurrent.moveOnly){
1823 this.fireEvents(e, false);
1833 * Iterates over all of the DragDrop elements to find ones we are
1834 * hovering over or dropping on
1835 * @method fireEvents
1836 * @param {Event} e the event
1837 * @param {boolean} isDrop is this a drop op or a mouseover op?
1841 fireEvents: function(e, isDrop) {
1842 var dc = this.dragCurrent;
1844 // If the user did the mouse up outside of the window, we could
1845 // get here even though we have ended the drag.
1846 if (!dc || dc.isLocked()) {
1850 var pt = e.getPoint();
1852 // cache the previous dragOver array
1860 // Check to see if the object(s) we were hovering over is no longer
1861 // being hovered over so we can fire the onDragOut event
1862 for (var i in this.dragOvers) {
1864 var ddo = this.dragOvers[i];
1866 if (! this.isTypeOfDD(ddo)) {
1870 if (! this.isOverTarget(pt, ddo, this.mode)) {
1871 outEvts.push( ddo );
1875 delete this.dragOvers[i];
1878 for (var sGroup in dc.groups) {
1880 if ("string" != typeof sGroup) {
1884 for (i in this.ids[sGroup]) {
1885 var oDD = this.ids[sGroup][i];
1886 if (! this.isTypeOfDD(oDD)) {
1890 if (oDD.isTarget && !oDD.isLocked() && ((oDD != dc) || (dc.ignoreSelf === false))) {
1891 if (this.isOverTarget(pt, oDD, this.mode)) {
1892 // look for drop interactions
1894 dropEvts.push( oDD );
1895 // look for drag enter and drag over interactions
1898 // initial drag over: dragEnter fires
1899 if (!oldOvers[oDD.id]) {
1900 enterEvts.push( oDD );
1901 // subsequent drag overs: dragOver fires
1903 overEvts.push( oDD );
1906 this.dragOvers[oDD.id] = oDD;
1914 if (outEvts.length) {
1915 dc.b4DragOut(e, outEvts);
1916 dc.onDragOut(e, outEvts);
1919 if (enterEvts.length) {
1920 dc.onDragEnter(e, enterEvts);
1923 if (overEvts.length) {
1924 dc.b4DragOver(e, overEvts);
1925 dc.onDragOver(e, overEvts);
1928 if (dropEvts.length) {
1929 dc.b4DragDrop(e, dropEvts);
1930 dc.onDragDrop(e, dropEvts);
1934 // fire dragout events
1936 for (i=0, len=outEvts.length; i<len; ++i) {
1937 dc.b4DragOut(e, outEvts[i].id);
1938 dc.onDragOut(e, outEvts[i].id);
1941 // fire enter events
1942 for (i=0,len=enterEvts.length; i<len; ++i) {
1943 // dc.b4DragEnter(e, oDD.id);
1944 dc.onDragEnter(e, enterEvts[i].id);
1948 for (i=0,len=overEvts.length; i<len; ++i) {
1949 dc.b4DragOver(e, overEvts[i].id);
1950 dc.onDragOver(e, overEvts[i].id);
1954 for (i=0, len=dropEvts.length; i<len; ++i) {
1955 dc.b4DragDrop(e, dropEvts[i].id);
1956 dc.onDragDrop(e, dropEvts[i].id);
1961 // notify about a drop that did not find a target
1962 if (isDrop && !dropEvts.length) {
1963 dc.onInvalidDrop(e);
1969 * Helper function for getting the best match from the list of drag
1970 * and drop objects returned by the drag and drop events when we are
1971 * in INTERSECT mode. It returns either the first object that the
1972 * cursor is over, or the object that has the greatest overlap with
1973 * the dragged element.
1974 * @method getBestMatch
1975 * @param {DragDrop[]} dds The array of drag and drop objects
1977 * @return {DragDrop} The best single match
1980 getBestMatch: function(dds) {
1982 // Return null if the input is not what we expect
1983 //if (!dds || !dds.length || dds.length == 0) {
1985 // If there is only one item, it wins
1986 //} else if (dds.length == 1) {
1988 var len = dds.length;
1993 // Loop through the targeted items
1994 for (var i=0; i<len; ++i) {
1996 // If the cursor is over the object, it wins. If the
1997 // cursor is over multiple matches, the first one we come
1999 if (dd.cursorIsOver) {
2002 // Otherwise the object with the most overlap wins
2005 winner.overlap.getArea() < dd.overlap.getArea()) {
2016 * Refreshes the cache of the top-left and bottom-right points of the
2017 * drag and drop objects in the specified group(s). This is in the
2018 * format that is stored in the drag and drop instance, so typical
2021 * Ext.dd.DragDropMgr.refreshCache(ddinstance.groups);
2025 * Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2027 * @TODO this really should be an indexed array. Alternatively this
2028 * method could accept both.
2029 * @method refreshCache
2030 * @param {Object} groups an associative array of groups to refresh
2033 refreshCache: function(groups) {
2034 for (var sGroup in groups) {
2035 if ("string" != typeof sGroup) {
2038 for (var i in this.ids[sGroup]) {
2039 var oDD = this.ids[sGroup][i];
2041 if (this.isTypeOfDD(oDD)) {
2042 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2043 var loc = this.getLocation(oDD);
2045 this.locationCache[oDD.id] = loc;
2047 delete this.locationCache[oDD.id];
2048 // this will unregister the drag and drop object if
2049 // the element is not in a usable state
2058 * This checks to make sure an element exists and is in the DOM. The
2059 * main purpose is to handle cases where innerHTML is used to remove
2060 * drag and drop objects from the DOM. IE provides an 'unspecified
2061 * error' when trying to access the offsetParent of such an element
2063 * @param {HTMLElement} el the element to check
2064 * @return {boolean} true if the element looks usable
2067 verifyEl: function(el) {
2072 parent = el.offsetParent;
2075 parent = el.offsetParent;
2086 * Returns a Region object containing the drag and drop element's position
2087 * and size, including the padding configured for it
2088 * @method getLocation
2089 * @param {DragDrop} oDD the drag and drop object to get the
2091 * @return {Ext.lib.Region} a Region object representing the total area
2092 * the element occupies, including any padding
2093 * the instance is configured for.
2096 getLocation: function(oDD) {
2097 if (! this.isTypeOfDD(oDD)) {
2101 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2104 pos= Ext.lib.Dom.getXY(el);
2112 x2 = x1 + el.offsetWidth;
2114 y2 = y1 + el.offsetHeight;
2116 t = y1 - oDD.padding[0];
2117 r = x2 + oDD.padding[1];
2118 b = y2 + oDD.padding[2];
2119 l = x1 - oDD.padding[3];
2121 return new Ext.lib.Region( t, r, b, l );
2125 * Checks the cursor location to see if it over the target
2126 * @method isOverTarget
2127 * @param {Ext.lib.Point} pt The point to evaluate
2128 * @param {DragDrop} oTarget the DragDrop object we are inspecting
2129 * @return {boolean} true if the mouse is over the target
2133 isOverTarget: function(pt, oTarget, intersect) {
2134 // use cache if available
2135 var loc = this.locationCache[oTarget.id];
2136 if (!loc || !this.useCache) {
2137 loc = this.getLocation(oTarget);
2138 this.locationCache[oTarget.id] = loc;
2146 oTarget.cursorIsOver = loc.contains( pt );
2148 // DragDrop is using this as a sanity check for the initial mousedown
2149 // in this case we are done. In POINT mode, if the drag obj has no
2150 // contraints, we are also done. Otherwise we need to evaluate the
2151 // location of the target as related to the actual location of the
2153 var dc = this.dragCurrent;
2154 if (!dc || !dc.getTargetCoord ||
2155 (!intersect && !dc.constrainX && !dc.constrainY)) {
2156 return oTarget.cursorIsOver;
2159 oTarget.overlap = null;
2161 // Get the current location of the drag element, this is the
2162 // location of the mouse event less the delta that represents
2163 // where the original mousedown happened on the element. We
2164 // need to consider constraints and ticks as well.
2165 var pos = dc.getTargetCoord(pt.x, pt.y);
2167 var el = dc.getDragEl();
2168 var curRegion = new Ext.lib.Region( pos.y,
2169 pos.x + el.offsetWidth,
2170 pos.y + el.offsetHeight,
2173 var overlap = curRegion.intersect(loc);
2176 oTarget.overlap = overlap;
2177 return (intersect) ? true : oTarget.cursorIsOver;
2184 * unload event handler
2189 _onUnload: function(e, me) {
2190 Ext.dd.DragDropMgr.unregAll();
2194 * Cleans up the drag and drop events and objects.
2199 unregAll: function() {
2201 if (this.dragCurrent) {
2203 this.dragCurrent = null;
2206 this._execOnAll("unreg", []);
2208 for (var i in this.elementCache) {
2209 delete this.elementCache[i];
2212 this.elementCache = {};
2217 * A cache of DOM elements
2218 * @property elementCache
2225 * Get the wrapper for the DOM element specified
2226 * @method getElWrapper
2227 * @param {String} id the id of the element to get
2228 * @return {Ext.dd.DDM.ElementWrapper} the wrapped element
2230 * @deprecated This wrapper isn't that useful
2233 getElWrapper: function(id) {
2234 var oWrapper = this.elementCache[id];
2235 if (!oWrapper || !oWrapper.el) {
2236 oWrapper = this.elementCache[id] =
2237 new this.ElementWrapper(Ext.getDom(id));
2243 * Returns the actual DOM element
2244 * @method getElement
2245 * @param {String} id the id of the elment to get
2246 * @return {Object} The element
2247 * @deprecated use Ext.lib.Ext.getDom instead
2250 getElement: function(id) {
2251 return Ext.getDom(id);
2255 * Returns the style property for the DOM element (i.e.,
2256 * document.getElById(id).style)
2258 * @param {String} id the id of the elment to get
2259 * @return {Object} The style property of the element
2260 * @deprecated use Ext.lib.Dom instead
2263 getCss: function(id) {
2264 var el = Ext.getDom(id);
2265 return (el) ? el.style : null;
2269 * Inner class for cached elements
2270 * @class DragDropMgr.ElementWrapper
2275 ElementWrapper: function(el) {
2280 this.el = el || null;
2285 this.id = this.el && el.id;
2287 * A reference to the style property
2290 this.css = this.el && el.style;
2294 * Returns the X position of an html element
2296 * @param el the element for which to get the position
2297 * @return {int} the X coordinate
2299 * @deprecated use Ext.lib.Dom.getX instead
2302 getPosX: function(el) {
2303 return Ext.lib.Dom.getX(el);
2307 * Returns the Y position of an html element
2309 * @param el the element for which to get the position
2310 * @return {int} the Y coordinate
2311 * @deprecated use Ext.lib.Dom.getY instead
2314 getPosY: function(el) {
2315 return Ext.lib.Dom.getY(el);
2319 * Swap two nodes. In IE, we use the native method, for others we
2320 * emulate the IE behavior
2322 * @param n1 the first node to swap
2323 * @param n2 the other node to swap
2326 swapNode: function(n1, n2) {
2330 var p = n2.parentNode;
2331 var s = n2.nextSibling;
2334 p.insertBefore(n1, n2);
2335 } else if (n2 == n1.nextSibling) {
2336 p.insertBefore(n2, n1);
2338 n1.parentNode.replaceChild(n2, n1);
2339 p.insertBefore(n1, s);
2345 * Returns the current scroll position
2350 getScroll: function () {
2351 var t, l, dde=document.documentElement, db=document.body;
2352 if (dde && (dde.scrollTop || dde.scrollLeft)) {
2361 return { top: t, left: l };
2365 * Returns the specified element style property
2367 * @param {HTMLElement} el the element
2368 * @param {string} styleProp the style property
2369 * @return {string} The value of the style property
2370 * @deprecated use Ext.lib.Dom.getStyle
2373 getStyle: function(el, styleProp) {
2374 return Ext.fly(el).getStyle(styleProp);
2378 * Gets the scrollTop
2379 * @method getScrollTop
2380 * @return {int} the document's scrollTop
2383 getScrollTop: function () { return this.getScroll().top; },
2386 * Gets the scrollLeft
2387 * @method getScrollLeft
2388 * @return {int} the document's scrollTop
2391 getScrollLeft: function () { return this.getScroll().left; },
2394 * Sets the x/y position of an element to the location of the
2397 * @param {HTMLElement} moveEl The element to move
2398 * @param {HTMLElement} targetEl The position reference element
2401 moveToEl: function (moveEl, targetEl) {
2402 var aCoord = Ext.lib.Dom.getXY(targetEl);
2403 Ext.lib.Dom.setXY(moveEl, aCoord);
2407 * Numeric array sort function
2408 * @method numericSort
2411 numericSort: function(a, b) { return (a - b); },
2415 * @property _timeoutCount
2422 * Trying to make the load order less important. Without this we get
2423 * an error if this file is loaded before the Event Utility.
2424 * @method _addListeners
2428 _addListeners: function() {
2429 var DDM = Ext.dd.DDM;
2430 if ( Ext.lib.Event && document ) {
2433 if (DDM._timeoutCount > 2000) {
2435 setTimeout(DDM._addListeners, 10);
2436 if (document && document.body) {
2437 DDM._timeoutCount += 1;
2444 * Recursively searches the immediate parent and all child nodes for
2445 * the handle element in order to determine wheter or not it was
2447 * @method handleWasClicked
2448 * @param node the html element to inspect
2451 handleWasClicked: function(node, id) {
2452 if (this.isHandle(id, node.id)) {
2455 // check to see if this is a text node child of the one we want
2456 var p = node.parentNode;
2459 if (this.isHandle(id, p.id)) {
2474 // shorter alias, save a few bytes
2475 Ext.dd.DDM = Ext.dd.DragDropMgr;
2476 Ext.dd.DDM._addListeners();
2482 * A DragDrop implementation where the linked element follows the
2483 * mouse cursor during a drag.
2484 * @extends Ext.dd.DragDrop
2486 * @param {String} id the id of the linked element
2487 * @param {String} sGroup the group of related DragDrop items
2488 * @param {object} config an object containing configurable attributes
2489 * Valid properties for DD:
2492 Ext.dd.DD = function(id, sGroup, config) {
2494 this.init(id, sGroup, config);
2498 Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, {
2501 * When set to true, the utility automatically tries to scroll the browser
2502 * window when a drag and drop element is dragged near the viewport boundary.
2510 * Sets the pointer offset to the distance between the linked element's top
2511 * left corner and the location the element was clicked
2512 * @method autoOffset
2513 * @param {int} iPageX the X coordinate of the click
2514 * @param {int} iPageY the Y coordinate of the click
2516 autoOffset: function(iPageX, iPageY) {
2517 var x = iPageX - this.startPageX;
2518 var y = iPageY - this.startPageY;
2519 this.setDelta(x, y);
2523 * Sets the pointer offset. You can call this directly to force the
2524 * offset to be in a particular location (e.g., pass in 0,0 to set it
2525 * to the center of the object)
2527 * @param {int} iDeltaX the distance from the left
2528 * @param {int} iDeltaY the distance from the top
2530 setDelta: function(iDeltaX, iDeltaY) {
2531 this.deltaX = iDeltaX;
2532 this.deltaY = iDeltaY;
2536 * Sets the drag element to the location of the mousedown or click event,
2537 * maintaining the cursor location relative to the location on the element
2538 * that was clicked. Override this if you want to place the element in a
2539 * location other than where the cursor is.
2540 * @method setDragElPos
2541 * @param {int} iPageX the X coordinate of the mousedown or drag event
2542 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2544 setDragElPos: function(iPageX, iPageY) {
2545 // the first time we do this, we are going to check to make sure
2546 // the element has css positioning
2548 var el = this.getDragEl();
2549 this.alignElWithMouse(el, iPageX, iPageY);
2553 * Sets the element to the location of the mousedown or click event,
2554 * maintaining the cursor location relative to the location on the element
2555 * that was clicked. Override this if you want to place the element in a
2556 * location other than where the cursor is.
2557 * @method alignElWithMouse
2558 * @param {HTMLElement} el the element to move
2559 * @param {int} iPageX the X coordinate of the mousedown or drag event
2560 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2562 alignElWithMouse: function(el, iPageX, iPageY) {
2563 var oCoord = this.getTargetCoord(iPageX, iPageY);
2564 var fly = el.dom ? el : Ext.fly(el, '_dd');
2565 if (!this.deltaSetXY) {
2566 var aCoord = [oCoord.x, oCoord.y];
2568 var newLeft = fly.getLeft(true);
2569 var newTop = fly.getTop(true);
2570 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2572 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2575 this.cachePosition(oCoord.x, oCoord.y);
2576 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2581 * Saves the most recent position so that we can reset the constraints and
2582 * tick marks on-demand. We need to know this so that we can calculate the
2583 * number of pixels the element is offset from its original position.
2584 * @method cachePosition
2585 * @param iPageX the current x position (optional, this just makes it so we
2586 * don't have to look it up again)
2587 * @param iPageY the current y position (optional, this just makes it so we
2588 * don't have to look it up again)
2590 cachePosition: function(iPageX, iPageY) {
2592 this.lastPageX = iPageX;
2593 this.lastPageY = iPageY;
2595 var aCoord = Ext.lib.Dom.getXY(this.getEl());
2596 this.lastPageX = aCoord[0];
2597 this.lastPageY = aCoord[1];
2602 * Auto-scroll the window if the dragged object has been moved beyond the
2603 * visible window boundary.
2604 * @method autoScroll
2605 * @param {int} x the drag element's x position
2606 * @param {int} y the drag element's y position
2607 * @param {int} h the height of the drag element
2608 * @param {int} w the width of the drag element
2611 autoScroll: function(x, y, h, w) {
2614 // The client height
2615 var clientH = Ext.lib.Dom.getViewHeight();
2618 var clientW = Ext.lib.Dom.getViewWidth();
2620 // The amt scrolled down
2621 var st = this.DDM.getScrollTop();
2623 // The amt scrolled right
2624 var sl = this.DDM.getScrollLeft();
2626 // Location of the bottom of the element
2629 // Location of the right of the element
2632 // The distance from the cursor to the bottom of the visible area,
2633 // adjusted so that we don't scroll if the cursor is beyond the
2634 // element drag constraints
2635 var toBot = (clientH + st - y - this.deltaY);
2637 // The distance from the cursor to the right of the visible area
2638 var toRight = (clientW + sl - x - this.deltaX);
2641 // How close to the edge the cursor must be before we scroll
2642 // var thresh = (document.all) ? 100 : 40;
2645 // How many pixels to scroll per autoscroll op. This helps to reduce
2646 // clunky scrolling. IE is more sensitive about this ... it needs this
2647 // value to be higher.
2648 var scrAmt = (document.all) ? 80 : 30;
2650 // Scroll down if we are near the bottom of the visible page and the
2651 // obj extends below the crease
2652 if ( bot > clientH && toBot < thresh ) {
2653 window.scrollTo(sl, st + scrAmt);
2656 // Scroll up if the window is scrolled down and the top of the object
2657 // goes above the top border
2658 if ( y < st && st > 0 && y - st < thresh ) {
2659 window.scrollTo(sl, st - scrAmt);
2662 // Scroll right if the obj is beyond the right border and the cursor is
2664 if ( right > clientW && toRight < thresh ) {
2665 window.scrollTo(sl + scrAmt, st);
2668 // Scroll left if the window has been scrolled to the right and the obj
2669 // extends past the left border
2670 if ( x < sl && sl > 0 && x - sl < thresh ) {
2671 window.scrollTo(sl - scrAmt, st);
2677 * Finds the location the element should be placed if we want to move
2678 * it to where the mouse location less the click offset would place us.
2679 * @method getTargetCoord
2680 * @param {int} iPageX the X coordinate of the click
2681 * @param {int} iPageY the Y coordinate of the click
2682 * @return an object that contains the coordinates (Object.x and Object.y)
2685 getTargetCoord: function(iPageX, iPageY) {
2688 var x = iPageX - this.deltaX;
2689 var y = iPageY - this.deltaY;
2691 if (this.constrainX) {
2692 if (x < this.minX) { x = this.minX; }
2693 if (x > this.maxX) { x = this.maxX; }
2696 if (this.constrainY) {
2697 if (y < this.minY) { y = this.minY; }
2698 if (y > this.maxY) { y = this.maxY; }
2701 x = this.getTick(x, this.xTicks);
2702 y = this.getTick(y, this.yTicks);
2709 * Sets up config options specific to this class. Overrides
2710 * Ext.dd.DragDrop, but all versions of this method through the
2711 * inheritance chain are called
2713 applyConfig: function() {
2714 Ext.dd.DD.superclass.applyConfig.call(this);
2715 this.scroll = (this.config.scroll !== false);
2719 * Event that fires prior to the onMouseDown event. Overrides
2722 b4MouseDown: function(e) {
2723 // this.resetConstraints();
2724 this.autoOffset(e.getPageX(),
2729 * Event that fires prior to the onDrag event. Overrides
2732 b4Drag: function(e) {
2733 this.setDragElPos(e.getPageX(),
2737 toString: function() {
2738 return ("DD " + this.id);
2741 //////////////////////////////////////////////////////////////////////////
2742 // Debugging ygDragDrop events that can be overridden
2743 //////////////////////////////////////////////////////////////////////////
2745 startDrag: function(x, y) {
2748 onDrag: function(e) {
2751 onDragEnter: function(e, id) {
2754 onDragOver: function(e, id) {
2757 onDragOut: function(e, id) {
2760 onDragDrop: function(e, id) {
2763 endDrag: function(e) {
2770 * @class Ext.dd.DDProxy
2771 * A DragDrop implementation that inserts an empty, bordered div into
2772 * the document that follows the cursor during drag operations. At the time of
2773 * the click, the frame div is resized to the dimensions of the linked html
2774 * element, and moved to the exact location of the linked element.
2776 * References to the "frame" element refer to the single proxy element that
2777 * was created to be dragged in place of all DDProxy elements on the
2780 * @extends Ext.dd.DD
2782 * @param {String} id the id of the linked html element
2783 * @param {String} sGroup the group of related DragDrop objects
2784 * @param {object} config an object containing configurable attributes
2785 * Valid properties for DDProxy in addition to those in DragDrop:
2786 * resizeFrame, centerFrame, dragElId
2788 Ext.dd.DDProxy = function(id, sGroup, config) {
2790 this.init(id, sGroup, config);
2796 * The default drag frame div id
2797 * @property Ext.dd.DDProxy.dragElId
2801 Ext.dd.DDProxy.dragElId = "ygddfdiv";
2803 Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, {
2806 * By default we resize the drag frame to be the same size as the element
2807 * we want to drag (this is to get the frame effect). We can turn it off
2808 * if we want a different behavior.
2809 * @property resizeFrame
2815 * By default the frame is positioned exactly where the drag element is, so
2816 * we use the cursor offset provided by Ext.dd.DD. Another option that works only if
2817 * you do not have constraints on the obj is to have the drag frame centered
2818 * around the cursor. Set centerFrame to true for this effect.
2819 * @property centerFrame
2825 * Creates the proxy element if it does not yet exist
2826 * @method createFrame
2828 createFrame: function() {
2830 var body = document.body;
2832 if (!body || !body.firstChild) {
2833 setTimeout( function() { self.createFrame(); }, 50 );
2837 var div = this.getDragEl();
2840 div = document.createElement("div");
2841 div.id = this.dragElId;
2844 s.position = "absolute";
2845 s.visibility = "hidden";
2847 s.border = "2px solid #aaa";
2850 // appendChild can blow up IE if invoked prior to the window load event
2851 // while rendering a table. It is possible there are other scenarios
2852 // that would cause this to happen as well.
2853 body.insertBefore(div, body.firstChild);
2858 * Initialization for the drag frame element. Must be called in the
2859 * constructor of all subclasses
2862 initFrame: function() {
2866 applyConfig: function() {
2867 Ext.dd.DDProxy.superclass.applyConfig.call(this);
2869 this.resizeFrame = (this.config.resizeFrame !== false);
2870 this.centerFrame = (this.config.centerFrame);
2871 this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
2875 * Resizes the drag frame to the dimensions of the clicked object, positions
2876 * it over the object, and finally displays it
2878 * @param {int} iPageX X click position
2879 * @param {int} iPageY Y click position
2882 showFrame: function(iPageX, iPageY) {
2883 var el = this.getEl();
2884 var dragEl = this.getDragEl();
2885 var s = dragEl.style;
2887 this._resizeProxy();
2889 if (this.centerFrame) {
2890 this.setDelta( Math.round(parseInt(s.width, 10)/2),
2891 Math.round(parseInt(s.height, 10)/2) );
2894 this.setDragElPos(iPageX, iPageY);
2896 Ext.fly(dragEl).show();
2900 * The proxy is automatically resized to the dimensions of the linked
2901 * element when a drag is initiated, unless resizeFrame is set to false
2902 * @method _resizeProxy
2905 _resizeProxy: function() {
2906 if (this.resizeFrame) {
2907 var el = this.getEl();
2908 Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2912 // overrides Ext.dd.DragDrop
2913 b4MouseDown: function(e) {
2914 var x = e.getPageX();
2915 var y = e.getPageY();
2916 this.autoOffset(x, y);
2917 this.setDragElPos(x, y);
2920 // overrides Ext.dd.DragDrop
2921 b4StartDrag: function(x, y) {
2922 // show the drag frame
2923 this.showFrame(x, y);
2926 // overrides Ext.dd.DragDrop
2927 b4EndDrag: function(e) {
2928 Ext.fly(this.getDragEl()).hide();
2931 // overrides Ext.dd.DragDrop
2932 // By default we try to move the element to the last location of the frame.
2933 // This is so that the default behavior mirrors that of Ext.dd.DD.
2934 endDrag: function(e) {
2936 var lel = this.getEl();
2937 var del = this.getDragEl();
2939 // Show the drag frame briefly so we can get its position
2940 del.style.visibility = "";
2943 // Hide the linked element before the move to get around a Safari
2945 lel.style.visibility = "hidden";
2946 Ext.dd.DDM.moveToEl(lel, del);
2947 del.style.visibility = "hidden";
2948 lel.style.visibility = "";
2953 beforeMove : function(){
2957 afterDrag : function(){
2961 toString: function() {
2962 return ("DDProxy " + this.id);
2967 * @class Ext.dd.DDTarget
2968 * A DragDrop implementation that does not move, but can be a drop
2969 * target. You would get the same result by simply omitting implementation
2970 * for the event callbacks, but this way we reduce the processing cost of the
2971 * event listener and the callbacks.
2972 * @extends Ext.dd.DragDrop
2974 * @param {String} id the id of the element that is a drop target
2975 * @param {String} sGroup the group of related DragDrop objects
2976 * @param {object} config an object containing configurable attributes
2977 * Valid properties for DDTarget in addition to those in
2981 Ext.dd.DDTarget = function(id, sGroup, config) {
2983 this.initTarget(id, sGroup, config);
2987 // Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop();
2988 Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, {
2989 toString: function() {
2990 return ("DDTarget " + this.id);
2994 * @class Ext.dd.DragTracker
\r
2995 * @extends Ext.util.Observable
\r
2997 Ext.dd.DragTracker = function(config){
\r
2998 Ext.apply(this, config);
\r
3001 * @event mousedown
\r
3002 * @param {Object} this
\r
3003 * @param {Object} e event object
\r
3008 * @param {Object} this
\r
3009 * @param {Object} e event object
\r
3013 * @event mousemove
\r
3014 * @param {Object} this
\r
3015 * @param {Object} e event object
\r
3019 * @event dragstart
\r
3020 * @param {Object} this
\r
3021 * @param {Object} startXY the page coordinates of the event
\r
3026 * @param {Object} this
\r
3027 * @param {Object} e event object
\r
3032 * @param {Object} this
\r
3033 * @param {Object} e event object
\r
3038 this.dragRegion = new Ext.lib.Region(0,0,0,0);
\r
3041 this.initEl(this.el);
\r
3045 Ext.extend(Ext.dd.DragTracker, Ext.util.Observable, {
\r
3047 * @cfg {Boolean} active
\r
3048 * Defaults to <tt>false</tt>.
\r
3052 * @cfg {Number} tolerance
\r
3053 * Defaults to <tt>5</tt>.
\r
3057 * @cfg {Boolean/Number} autoStart
\r
3058 * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
\r
3059 * Specify a Number for the number of milliseconds to defer trigger start.
\r
3063 initEl: function(el){
\r
3064 this.el = Ext.get(el);
\r
3065 el.on('mousedown', this.onMouseDown, this,
\r
3066 this.delegate ? {delegate: this.delegate} : undefined);
\r
3069 destroy : function(){
\r
3070 this.el.un('mousedown', this.onMouseDown, this);
\r
3073 onMouseDown: function(e, target){
\r
3074 if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
\r
3075 this.startXY = this.lastXY = e.getXY();
\r
3076 this.dragTarget = this.delegate ? target : this.el.dom;
\r
3077 if(this.preventDefault !== false){
\r
3078 e.preventDefault();
\r
3080 var doc = Ext.getDoc();
\r
3081 doc.on('mouseup', this.onMouseUp, this);
\r
3082 doc.on('mousemove', this.onMouseMove, this);
\r
3083 doc.on('selectstart', this.stopSelect, this);
\r
3084 if(this.autoStart){
\r
3085 this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this);
\r
3090 onMouseMove: function(e, target){
\r
3091 // HACK: IE hack to see if button was released outside of window. */
\r
3092 if(this.active && Ext.isIE && !e.browserEvent.button){
\r
3093 e.preventDefault();
\r
3094 this.onMouseUp(e);
\r
3098 e.preventDefault();
\r
3099 var xy = e.getXY(), s = this.startXY;
\r
3102 if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
\r
3103 this.triggerStart();
\r
3108 this.fireEvent('mousemove', this, e);
\r
3110 this.fireEvent('drag', this, e);
\r
3113 onMouseUp: function(e){
\r
3114 var doc = Ext.getDoc();
\r
3115 doc.un('mousemove', this.onMouseMove, this);
\r
3116 doc.un('mouseup', this.onMouseUp, this);
\r
3117 doc.un('selectstart', this.stopSelect, this);
\r
3118 e.preventDefault();
\r
3119 this.clearStart();
\r
3120 var wasActive = this.active;
\r
3121 this.active = false;
\r
3122 delete this.elRegion;
\r
3123 this.fireEvent('mouseup', this, e);
\r
3126 this.fireEvent('dragend', this, e);
\r
3130 triggerStart: function(isTimer){
\r
3131 this.clearStart();
\r
3132 this.active = true;
\r
3133 this.onStart(this.startXY);
\r
3134 this.fireEvent('dragstart', this, this.startXY);
\r
3137 clearStart : function(){
\r
3139 clearTimeout(this.timer);
\r
3140 delete this.timer;
\r
3144 stopSelect : function(e){
\r
3149 onBeforeStart : function(e){
\r
3153 onStart : function(xy){
\r
3157 onDrag : function(e){
\r
3161 onEnd : function(e){
\r
3165 getDragTarget : function(){
\r
3166 return this.dragTarget;
\r
3169 getDragCt : function(){
\r
3173 getXY : function(constrain){
\r
3174 return constrain ?
\r
3175 this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
\r
3178 getOffset : function(constrain){
\r
3179 var xy = this.getXY(constrain);
\r
3180 var s = this.startXY;
\r
3181 return [s[0]-xy[0], s[1]-xy[1]];
\r
3185 'point' : function(xy){
\r
3187 if(!this.elRegion){
\r
3188 this.elRegion = this.getDragCt().getRegion();
\r
3191 var dr = this.dragRegion;
\r
3196 dr.bottom = xy[1];
\r
3198 dr.constrainTo(this.elRegion);
\r
3200 return [dr.left, dr.top];
\r
3204 * @class Ext.dd.ScrollManager
\r
3205 * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
\r
3206 * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
\r
3207 * but you can also override most of the configs per scroll container by adding a
\r
3208 * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
\r
3209 * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
\r
3211 var el = Ext.get('scroll-ct');
\r
3212 el.ddScrollConfig = {
\r
3218 Ext.dd.ScrollManager.register(el);
\r
3220 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
\r
3223 Ext.dd.ScrollManager = function(){
\r
3224 var ddm = Ext.dd.DragDropMgr;
\r
3226 var dragEl = null;
\r
3229 var onStop = function(e){
\r
3234 var triggerRefresh = function(){
\r
3235 if(ddm.dragCurrent){
\r
3236 ddm.refreshCache(ddm.dragCurrent.groups);
\r
3240 var doScroll = function(){
\r
3241 if(ddm.dragCurrent){
\r
3242 var dds = Ext.dd.ScrollManager;
\r
3243 var inc = proc.el.ddScrollConfig ?
\r
3244 proc.el.ddScrollConfig.increment : dds.increment;
\r
3246 if(proc.el.scroll(proc.dir, inc)){
\r
3250 proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
\r
3255 var clearProc = function(){
\r
3257 clearInterval(proc.id);
\r
3264 var startProc = function(el, dir){
\r
3268 var freq = (el.ddScrollConfig && el.ddScrollConfig.frequency) ?
\r
3269 el.ddScrollConfig.frequency : Ext.dd.ScrollManager.frequency;
\r
3270 proc.id = setInterval(doScroll, freq);
\r
3273 var onFire = function(e, isDrop){
\r
3274 if(isDrop || !ddm.dragCurrent){ return; }
\r
3275 var dds = Ext.dd.ScrollManager;
\r
3276 if(!dragEl || dragEl != ddm.dragCurrent){
\r
3277 dragEl = ddm.dragCurrent;
\r
3278 // refresh regions on drag start
\r
3279 dds.refreshCache();
\r
3282 var xy = Ext.lib.Event.getXY(e);
\r
3283 var pt = new Ext.lib.Point(xy[0], xy[1]);
\r
3284 for(var id in els){
\r
3285 var el = els[id], r = el._region;
\r
3286 var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
\r
3287 if(r && r.contains(pt) && el.isScrollable()){
\r
3288 if(r.bottom - pt.y <= c.vthresh){
\r
3289 if(proc.el != el){
\r
3290 startProc(el, "down");
\r
3293 }else if(r.right - pt.x <= c.hthresh){
\r
3294 if(proc.el != el){
\r
3295 startProc(el, "left");
\r
3298 }else if(pt.y - r.top <= c.vthresh){
\r
3299 if(proc.el != el){
\r
3300 startProc(el, "up");
\r
3303 }else if(pt.x - r.left <= c.hthresh){
\r
3304 if(proc.el != el){
\r
3305 startProc(el, "right");
\r
3314 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
\r
3315 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
\r
3319 * Registers new overflow element(s) to auto scroll
\r
3320 * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
\r
3322 register : function(el){
\r
3323 if(Ext.isArray(el)){
\r
3324 for(var i = 0, len = el.length; i < len; i++) {
\r
3325 this.register(el[i]);
\r
3334 * Unregisters overflow element(s) so they are no longer scrolled
\r
3335 * @param {Mixed/Array} el The id of or the element to be removed or an array of either
\r
3337 unregister : function(el){
\r
3338 if(Ext.isArray(el)){
\r
3339 for(var i = 0, len = el.length; i < len; i++) {
\r
3340 this.unregister(el[i]);
\r
3344 delete els[el.id];
\r
3349 * The number of pixels from the top or bottom edge of a container the pointer needs to be to
\r
3350 * trigger scrolling (defaults to 25)
\r
3355 * The number of pixels from the right or left edge of a container the pointer needs to be to
\r
3356 * trigger scrolling (defaults to 25)
\r
3362 * The number of pixels to scroll in each scroll increment (defaults to 50)
\r
3368 * The frequency of scrolls in milliseconds (defaults to 500)
\r
3374 * True to animate the scroll (defaults to true)
\r
3380 * The animation duration in seconds -
\r
3381 * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
\r
3387 * Manually trigger a cache refresh.
\r
3389 refreshCache : function(){
\r
3390 for(var id in els){
\r
3391 if(typeof els[id] == 'object'){ // for people extending the object prototype
\r
3392 els[id]._region = els[id].getRegion();
\r
3398 * @class Ext.dd.Registry
\r
3399 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
\r
3400 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
\r
3403 Ext.dd.Registry = function(){
\r
3404 var elements = {};
\r
3405 var handles = {};
\r
3406 var autoIdSeed = 0;
\r
3408 var getId = function(el, autogen){
\r
3409 if(typeof el == "string"){
\r
3413 if(!id && autogen !== false){
\r
3414 id = "extdd-" + (++autoIdSeed);
\r
3422 * Resgister a drag drop element
\r
3423 * @param {String/HTMLElement) element The id or DOM node to register
\r
3424 * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
\r
3425 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
\r
3426 * knows how to interpret, plus there are some specific properties known to the Registry that should be
\r
3427 * populated in the data object (if applicable):
\r
3429 Value Description<br />
\r
3430 --------- ------------------------------------------<br />
\r
3431 handles Array of DOM nodes that trigger dragging<br />
\r
3432 for the element being registered<br />
\r
3433 isHandle True if the element passed in triggers<br />
\r
3434 dragging itself, else false
\r
3437 register : function(el, data){
\r
3438 data = data || {};
\r
3439 if(typeof el == "string"){
\r
3440 el = document.getElementById(el);
\r
3443 elements[getId(el)] = data;
\r
3444 if(data.isHandle !== false){
\r
3445 handles[data.ddel.id] = data;
\r
3448 var hs = data.handles;
\r
3449 for(var i = 0, len = hs.length; i < len; i++){
\r
3450 handles[getId(hs[i])] = data;
\r
3456 * Unregister a drag drop element
\r
3457 * @param {String/HTMLElement) element The id or DOM node to unregister
\r
3459 unregister : function(el){
\r
3460 var id = getId(el, false);
\r
3461 var data = elements[id];
\r
3463 delete elements[id];
\r
3465 var hs = data.handles;
\r
3466 for(var i = 0, len = hs.length; i < len; i++){
\r
3467 delete handles[getId(hs[i], false)];
\r
3474 * Returns the handle registered for a DOM Node by id
\r
3475 * @param {String/HTMLElement} id The DOM node or id to look up
\r
3476 * @return {Object} handle The custom handle data
\r
3478 getHandle : function(id){
\r
3479 if(typeof id != "string"){ // must be element?
\r
3482 return handles[id];
\r
3486 * Returns the handle that is registered for the DOM node that is the target of the event
\r
3487 * @param {Event} e The event
\r
3488 * @return {Object} handle The custom handle data
\r
3490 getHandleFromEvent : function(e){
\r
3491 var t = Ext.lib.Event.getTarget(e);
\r
3492 return t ? handles[t.id] : null;
\r
3496 * Returns a custom data object that is registered for a DOM node by id
\r
3497 * @param {String/HTMLElement} id The DOM node or id to look up
\r
3498 * @return {Object} data The custom data
\r
3500 getTarget : function(id){
\r
3501 if(typeof id != "string"){ // must be element?
\r
3504 return elements[id];
\r
3508 * Returns a custom data object that is registered for the DOM node that is the target of the event
\r
3509 * @param {Event} e The event
\r
3510 * @return {Object} data The custom data
\r
3512 getTargetFromEvent : function(e){
\r
3513 var t = Ext.lib.Event.getTarget(e);
\r
3514 return t ? elements[t.id] || handles[t.id] : null;
\r
3518 * @class Ext.dd.StatusProxy
\r
3519 * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair. This is the
\r
3520 * default drag proxy used by all Ext.dd components.
\r
3522 * @param {Object} config
\r
3524 Ext.dd.StatusProxy = function(config){
\r
3525 Ext.apply(this, config);
\r
3526 this.id = this.id || Ext.id();
\r
3527 this.el = new Ext.Layer({
\r
3529 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
\r
3530 {tag: "div", cls: "x-dd-drop-icon"},
\r
3531 {tag: "div", cls: "x-dd-drag-ghost"}
\r
3534 shadow: !config || config.shadow !== false
\r
3536 this.ghost = Ext.get(this.el.dom.childNodes[1]);
\r
3537 this.dropStatus = this.dropNotAllowed;
\r
3540 Ext.dd.StatusProxy.prototype = {
\r
3542 * @cfg {String} dropAllowed
\r
3543 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
\r
3545 dropAllowed : "x-dd-drop-ok",
\r
3547 * @cfg {String} dropNotAllowed
\r
3548 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
\r
3550 dropNotAllowed : "x-dd-drop-nodrop",
\r
3553 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
\r
3554 * over the current target element.
\r
3555 * @param {String} cssClass The css class for the new drop status indicator image
\r
3557 setStatus : function(cssClass){
\r
3558 cssClass = cssClass || this.dropNotAllowed;
\r
3559 if(this.dropStatus != cssClass){
\r
3560 this.el.replaceClass(this.dropStatus, cssClass);
\r
3561 this.dropStatus = cssClass;
\r
3566 * Resets the status indicator to the default dropNotAllowed value
\r
3567 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
\r
3569 reset : function(clearGhost){
\r
3570 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
\r
3571 this.dropStatus = this.dropNotAllowed;
\r
3573 this.ghost.update("");
\r
3578 * Updates the contents of the ghost element
\r
3579 * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a
\r
3580 * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).
\r
3582 update : function(html){
\r
3583 if(typeof html == "string"){
\r
3584 this.ghost.update(html);
\r
3586 this.ghost.update("");
\r
3587 html.style.margin = "0";
\r
3588 this.ghost.dom.appendChild(html);
\r
3590 var el = this.ghost.dom.firstChild;
\r
3592 Ext.fly(el).setStyle('float', 'none');
\r
3597 * Returns the underlying proxy {@link Ext.Layer}
\r
3598 * @return {Ext.Layer} el
\r
3600 getEl : function(){
\r
3605 * Returns the ghost element
\r
3606 * @return {Ext.Element} el
\r
3608 getGhost : function(){
\r
3609 return this.ghost;
\r
3614 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
\r
3616 hide : function(clear){
\r
3624 * Stops the repair animation if it's currently running
\r
3626 stop : function(){
\r
3627 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
\r
3633 * Displays this proxy
\r
3635 show : function(){
\r
3640 * Force the Layer to sync its shadow and shim positions to the element
\r
3642 sync : function(){
\r
3647 * Causes the proxy to return to its position of origin via an animation. Should be called after an
\r
3648 * invalid drop operation by the item being dragged.
\r
3649 * @param {Array} xy The XY position of the element ([x, y])
\r
3650 * @param {Function} callback The function to call after the repair is complete
\r
3651 * @param {Object} scope The scope in which to execute the callback
\r
3653 repair : function(xy, callback, scope){
\r
3654 this.callback = callback;
\r
3655 this.scope = scope;
\r
3656 if(xy && this.animRepair !== false){
\r
3657 this.el.addClass("x-dd-drag-repair");
\r
3658 this.el.hideUnders(true);
\r
3659 this.anim = this.el.shift({
\r
3660 duration: this.repairDuration || .5,
\r
3661 easing: 'easeOut',
\r
3664 callback: this.afterRepair,
\r
3668 this.afterRepair();
\r
3673 afterRepair : function(){
\r
3675 if(typeof this.callback == "function"){
\r
3676 this.callback.call(this.scope || this);
\r
3678 this.callback = null;
\r
3679 this.scope = null;
\r
3682 * @class Ext.dd.DragSource
\r
3683 * @extends Ext.dd.DDProxy
\r
3684 * A simple class that provides the basic implementation needed to make any element draggable.
\r
3686 * @param {Mixed} el The container element
\r
3687 * @param {Object} config
\r
3689 Ext.dd.DragSource = function(el, config){
\r
3690 this.el = Ext.get(el);
\r
3691 if(!this.dragData){
\r
3692 this.dragData = {};
\r
3695 Ext.apply(this, config);
\r
3698 this.proxy = new Ext.dd.StatusProxy();
\r
3700 Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
\r
3701 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
\r
3703 this.dragging = false;
\r
3706 Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
\r
3708 * @cfg {String} ddGroup
\r
3709 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
3710 * interact with other drag drop objects in the same group (defaults to undefined).
\r
3713 * @cfg {String} dropAllowed
\r
3714 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
\r
3716 dropAllowed : "x-dd-drop-ok",
\r
3718 * @cfg {String} dropNotAllowed
\r
3719 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
\r
3721 dropNotAllowed : "x-dd-drop-nodrop",
\r
3724 * Returns the data object associated with this drag source
\r
3725 * @return {Object} data An object containing arbitrary data
\r
3727 getDragData : function(e){
\r
3728 return this.dragData;
\r
3732 onDragEnter : function(e, id){
\r
3733 var target = Ext.dd.DragDropMgr.getDDById(id);
\r
3734 this.cachedTarget = target;
\r
3735 if(this.beforeDragEnter(target, e, id) !== false){
\r
3736 if(target.isNotifyTarget){
\r
3737 var status = target.notifyEnter(this, e, this.dragData);
\r
3738 this.proxy.setStatus(status);
\r
3740 this.proxy.setStatus(this.dropAllowed);
\r
3743 if(this.afterDragEnter){
\r
3745 * An empty function by default, but provided so that you can perform a custom action
\r
3746 * when the dragged item enters the drop target by providing an implementation.
\r
3747 * @param {Ext.dd.DragDrop} target The drop target
\r
3748 * @param {Event} e The event object
\r
3749 * @param {String} id The id of the dragged element
\r
3750 * @method afterDragEnter
\r
3752 this.afterDragEnter(target, e, id);
\r
3758 * An empty function by default, but provided so that you can perform a custom action
\r
3759 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
\r
3760 * @param {Ext.dd.DragDrop} target The drop target
\r
3761 * @param {Event} e The event object
\r
3762 * @param {String} id The id of the dragged element
\r
3763 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
\r
3765 beforeDragEnter : function(target, e, id){
\r
3770 alignElWithMouse: function() {
\r
3771 Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
\r
3772 this.proxy.sync();
\r
3776 onDragOver : function(e, id){
\r
3777 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
\r
3778 if(this.beforeDragOver(target, e, id) !== false){
\r
3779 if(target.isNotifyTarget){
\r
3780 var status = target.notifyOver(this, e, this.dragData);
\r
3781 this.proxy.setStatus(status);
\r
3784 if(this.afterDragOver){
\r
3786 * An empty function by default, but provided so that you can perform a custom action
\r
3787 * while the dragged item is over the drop target by providing an implementation.
\r
3788 * @param {Ext.dd.DragDrop} target The drop target
\r
3789 * @param {Event} e The event object
\r
3790 * @param {String} id The id of the dragged element
\r
3791 * @method afterDragOver
\r
3793 this.afterDragOver(target, e, id);
\r
3799 * An empty function by default, but provided so that you can perform a custom action
\r
3800 * while the dragged item is over the drop target and optionally cancel the onDragOver.
\r
3801 * @param {Ext.dd.DragDrop} target The drop target
\r
3802 * @param {Event} e The event object
\r
3803 * @param {String} id The id of the dragged element
\r
3804 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
\r
3806 beforeDragOver : function(target, e, id){
\r
3811 onDragOut : function(e, id){
\r
3812 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
\r
3813 if(this.beforeDragOut(target, e, id) !== false){
\r
3814 if(target.isNotifyTarget){
\r
3815 target.notifyOut(this, e, this.dragData);
\r
3817 this.proxy.reset();
\r
3818 if(this.afterDragOut){
\r
3820 * An empty function by default, but provided so that you can perform a custom action
\r
3821 * after the dragged item is dragged out of the target without dropping.
\r
3822 * @param {Ext.dd.DragDrop} target The drop target
\r
3823 * @param {Event} e The event object
\r
3824 * @param {String} id The id of the dragged element
\r
3825 * @method afterDragOut
\r
3827 this.afterDragOut(target, e, id);
\r
3830 this.cachedTarget = null;
\r
3834 * An empty function by default, but provided so that you can perform a custom action before the dragged
\r
3835 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
\r
3836 * @param {Ext.dd.DragDrop} target The drop target
\r
3837 * @param {Event} e The event object
\r
3838 * @param {String} id The id of the dragged element
\r
3839 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
\r
3841 beforeDragOut : function(target, e, id){
\r
3846 onDragDrop : function(e, id){
\r
3847 var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
\r
3848 if(this.beforeDragDrop(target, e, id) !== false){
\r
3849 if(target.isNotifyTarget){
\r
3850 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
\r
3851 this.onValidDrop(target, e, id);
\r
3853 this.onInvalidDrop(target, e, id);
\r
3856 this.onValidDrop(target, e, id);
\r
3859 if(this.afterDragDrop){
\r
3861 * An empty function by default, but provided so that you can perform a custom action
\r
3862 * after a valid drag drop has occurred by providing an implementation.
\r
3863 * @param {Ext.dd.DragDrop} target The drop target
\r
3864 * @param {Event} e The event object
\r
3865 * @param {String} id The id of the dropped element
\r
3866 * @method afterDragDrop
\r
3868 this.afterDragDrop(target, e, id);
\r
3871 delete this.cachedTarget;
\r
3875 * An empty function by default, but provided so that you can perform a custom action before the dragged
\r
3876 * item is dropped onto the target and optionally cancel the onDragDrop.
\r
3877 * @param {Ext.dd.DragDrop} target The drop target
\r
3878 * @param {Event} e The event object
\r
3879 * @param {String} id The id of the dragged element
\r
3880 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
\r
3882 beforeDragDrop : function(target, e, id){
\r
3887 onValidDrop : function(target, e, id){
\r
3889 if(this.afterValidDrop){
\r
3891 * An empty function by default, but provided so that you can perform a custom action
\r
3892 * after a valid drop has occurred by providing an implementation.
\r
3893 * @param {Object} target The target DD
\r
3894 * @param {Event} e The event object
\r
3895 * @param {String} id The id of the dropped element
\r
3896 * @method afterInvalidDrop
\r
3898 this.afterValidDrop(target, e, id);
\r
3903 getRepairXY : function(e, data){
\r
3904 return this.el.getXY();
\r
3908 onInvalidDrop : function(target, e, id){
\r
3909 this.beforeInvalidDrop(target, e, id);
\r
3910 if(this.cachedTarget){
\r
3911 if(this.cachedTarget.isNotifyTarget){
\r
3912 this.cachedTarget.notifyOut(this, e, this.dragData);
\r
3914 this.cacheTarget = null;
\r
3916 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
\r
3918 if(this.afterInvalidDrop){
\r
3920 * An empty function by default, but provided so that you can perform a custom action
\r
3921 * after an invalid drop has occurred by providing an implementation.
\r
3922 * @param {Event} e The event object
\r
3923 * @param {String} id The id of the dropped element
\r
3924 * @method afterInvalidDrop
\r
3926 this.afterInvalidDrop(e, id);
\r
3931 afterRepair : function(){
\r
3933 this.el.highlight(this.hlColor || "c3daf9");
\r
3935 this.dragging = false;
\r
3939 * An empty function by default, but provided so that you can perform a custom action after an invalid
\r
3940 * drop has occurred.
\r
3941 * @param {Ext.dd.DragDrop} target The drop target
\r
3942 * @param {Event} e The event object
\r
3943 * @param {String} id The id of the dragged element
\r
3944 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
\r
3946 beforeInvalidDrop : function(target, e, id){
\r
3951 handleMouseDown : function(e){
\r
3952 if(this.dragging) {
\r
3955 var data = this.getDragData(e);
\r
3956 if(data && this.onBeforeDrag(data, e) !== false){
\r
3957 this.dragData = data;
\r
3958 this.proxy.stop();
\r
3959 Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
\r
3964 * An empty function by default, but provided so that you can perform a custom action before the initial
\r
3965 * drag event begins and optionally cancel it.
\r
3966 * @param {Object} data An object containing arbitrary data to be shared with drop targets
\r
3967 * @param {Event} e The event object
\r
3968 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
\r
3970 onBeforeDrag : function(data, e){
\r
3975 * An empty function by default, but provided so that you can perform a custom action once the initial
\r
3976 * drag event has begun. The drag cannot be canceled from this function.
\r
3977 * @param {Number} x The x position of the click on the dragged object
\r
3978 * @param {Number} y The y position of the click on the dragged object
\r
3980 onStartDrag : Ext.emptyFn,
\r
3982 // private override
\r
3983 startDrag : function(x, y){
\r
3984 this.proxy.reset();
\r
3985 this.dragging = true;
\r
3986 this.proxy.update("");
\r
3987 this.onInitDrag(x, y);
\r
3988 this.proxy.show();
\r
3992 onInitDrag : function(x, y){
\r
3993 var clone = this.el.dom.cloneNode(true);
\r
3994 clone.id = Ext.id(); // prevent duplicate ids
\r
3995 this.proxy.update(clone);
\r
3996 this.onStartDrag(x, y);
\r
4001 * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
\r
4002 * @return {Ext.dd.StatusProxy} proxy The StatusProxy
\r
4004 getProxy : function(){
\r
4005 return this.proxy;
\r
4009 * Hides the drag source's {@link Ext.dd.StatusProxy}
\r
4011 hideProxy : function(){
\r
4012 this.proxy.hide();
\r
4013 this.proxy.reset(true);
\r
4014 this.dragging = false;
\r
4018 triggerCacheRefresh : function(){
\r
4019 Ext.dd.DDM.refreshCache(this.groups);
\r
4022 // private - override to prevent hiding
\r
4023 b4EndDrag: function(e) {
\r
4026 // private - override to prevent moving
\r
4027 endDrag : function(e){
\r
4028 this.onEndDrag(this.dragData, e);
\r
4032 onEndDrag : function(data, e){
\r
4035 // private - pin to cursor
\r
4036 autoOffset : function(x, y) {
\r
4037 this.setDelta(-12, -20);
\r
4040 * @class Ext.dd.DropTarget
\r
4041 * @extends Ext.dd.DDTarget
\r
4042 * A simple class that provides the basic implementation needed to make any element a drop target that can have
\r
4043 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
\r
4045 * @param {Mixed} el The container element
\r
4046 * @param {Object} config
\r
4048 Ext.dd.DropTarget = function(el, config){
\r
4049 this.el = Ext.get(el);
\r
4051 Ext.apply(this, config);
\r
4053 if(this.containerScroll){
\r
4054 Ext.dd.ScrollManager.register(this.el);
\r
4057 Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
\r
4058 {isTarget: true});
\r
4062 Ext.extend(Ext.dd.DropTarget, Ext.dd.DDTarget, {
\r
4064 * @cfg {String} ddGroup
\r
4065 * A named drag drop group to which this object belongs. If a group is specified, then this object will only
\r
4066 * interact with other drag drop objects in the same group (defaults to undefined).
\r
4069 * @cfg {String} overClass
\r
4070 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
\r
4073 * @cfg {String} dropAllowed
\r
4074 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
\r
4076 dropAllowed : "x-dd-drop-ok",
\r
4078 * @cfg {String} dropNotAllowed
\r
4079 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
\r
4081 dropNotAllowed : "x-dd-drop-nodrop",
\r
4087 isNotifyTarget : true,
\r
4090 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the
\r
4091 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
\r
4092 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
\r
4093 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
\r
4094 * @param {Event} e The event
\r
4095 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4096 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4097 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4099 notifyEnter : function(dd, e, data){
\r
4100 if(this.overClass){
\r
4101 this.el.addClass(this.overClass);
\r
4103 return this.dropAllowed;
\r
4107 * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.
\r
4108 * This method will be called on every mouse movement while the drag source is over the drop target.
\r
4109 * This default implementation simply returns the dropAllowed config value.
\r
4110 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
\r
4111 * @param {Event} e The event
\r
4112 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4113 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4114 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4116 notifyOver : function(dd, e, data){
\r
4117 return this.dropAllowed;
\r
4121 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged
\r
4122 * out of the target without dropping. This default implementation simply removes the CSS class specified by
\r
4123 * overClass (if any) from the drop element.
\r
4124 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
\r
4125 * @param {Event} e The event
\r
4126 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4128 notifyOut : function(dd, e, data){
\r
4129 if(this.overClass){
\r
4130 this.el.removeClass(this.overClass);
\r
4135 * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has
\r
4136 * been dropped on it. This method has no default implementation and returns false, so you must provide an
\r
4137 * implementation that does something to process the drop event and returns true so that the drag source's
\r
4138 * repair action does not run.
\r
4139 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
\r
4140 * @param {Event} e The event
\r
4141 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4142 * @return {Boolean} True if the drop was valid, else false
\r
4144 notifyDrop : function(dd, e, data){
\r
4148 * @class Ext.dd.DragZone
\r
4149 * @extends Ext.dd.DragSource
\r
4150 * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
\r
4151 * <p>This class does not move the drag target nodes, but a proxy element which may contain
\r
4152 * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
\r
4153 * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
\r
4154 * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
\r
4155 * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
\r
4156 * is the most efficient way to "activate" those nodes.</p>
\r
4157 * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
\r
4158 * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
\r
4159 * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
\r
4160 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
\r
4161 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
\r
4162 * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
\r
4163 * technique. Knowledge of the use of the DataView is required:</p><pre><code>
\r
4164 myDataView.on('render', function() {
\r
4165 myDataView.dragZone = new Ext.dd.DragZone(myDataView.getEl(), {
\r
4167 // On receipt of a mousedown event, see if it is within a DataView node.
\r
4168 // Return a drag data object if so.
\r
4169 getDragData: function(e) {
\r
4171 // Use the DataView's own itemSelector (a mandatory property) to
\r
4172 // test if the mousedown is within one of the DataView's nodes.
\r
4173 var sourceEl = e.getTarget(myDataView.itemSelector, 10);
\r
4175 // If the mousedown is within a DataView node, clone the node to produce
\r
4176 // a ddel element for use by the drag proxy. Also add application data
\r
4177 // to the returned data object.
\r
4179 d = sourceEl.cloneNode(true);
\r
4183 sourceEl: sourceEl,
\r
4184 repairXY: Ext.fly(sourceEl).getXY(),
\r
4185 sourceStore: myDataView.store,
\r
4186 draggedRecord: v.getRecord(sourceEl)
\r
4191 // Provide coordinates for the proxy to slide back to on failed drag.
\r
4192 // This is the original XY coordinates of the draggable element captured
\r
4193 // in the getDragData method.
\r
4194 getRepairXY: function() {
\r
4195 return this.dragData.repairXY;
\r
4199 * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
\r
4200 * cooperates with this DragZone.
\r
4202 * @param {Mixed} el The container element
\r
4203 * @param {Object} config
\r
4205 Ext.dd.DragZone = function(el, config){
\r
4206 Ext.dd.DragZone.superclass.constructor.call(this, el, config);
\r
4207 if(this.containerScroll){
\r
4208 Ext.dd.ScrollManager.register(this.el);
\r
4212 Ext.extend(Ext.dd.DragZone, Ext.dd.DragSource, {
\r
4214 * This property contains the data representing the dragged object. This data is set up by the implementation
\r
4215 * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
\r
4216 * any other data according to the application's needs.
\r
4218 * @property dragData
\r
4221 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
\r
4222 * for auto scrolling during drag operations.
\r
4225 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
\r
4226 * method after a failed drop (defaults to "c3daf9" - light blue)
\r
4230 * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
\r
4231 * for a valid target to drag based on the mouse down. Override this method
\r
4232 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
\r
4233 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
\r
4234 * @param {EventObject} e The mouse down event
\r
4235 * @return {Object} The dragData
\r
4237 getDragData : function(e){
\r
4238 return Ext.dd.Registry.getHandleFromEvent(e);
\r
4242 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
\r
4243 * this.dragData.ddel
\r
4244 * @param {Number} x The x position of the click on the dragged object
\r
4245 * @param {Number} y The y position of the click on the dragged object
\r
4246 * @return {Boolean} true to continue the drag, false to cancel
\r
4248 onInitDrag : function(x, y){
\r
4249 this.proxy.update(this.dragData.ddel.cloneNode(true));
\r
4250 this.onStartDrag(x, y);
\r
4255 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
\r
4257 afterRepair : function(){
\r
4259 Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
\r
4261 this.dragging = false;
\r
4265 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
\r
4266 * the XY of this.dragData.ddel
\r
4267 * @param {EventObject} e The mouse up event
\r
4268 * @return {Array} The xy location (e.g. [100, 200])
\r
4270 getRepairXY : function(e){
\r
4271 return Ext.Element.fly(this.dragData.ddel).getXY();
\r
4274 * @class Ext.dd.DropZone
\r
4275 * @extends Ext.dd.DropTarget
\r
4276 * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>
\r
4277 * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
\r
4278 * However a simpler way to allow a DropZone to manage any number of target elements is to configure the
\r
4279 * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
\r
4280 * mouse event to see if it has taken place within an element, or class of elements. This is easily done
\r
4281 * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
\r
4282 * {@link Ext.DomQuery} selector.</p>
\r
4283 * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
\r
4284 * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
\r
4285 * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
\r
4286 * of these methods to provide application-specific behaviour for these events to update both
\r
4287 * application state, and UI state.</p>
\r
4288 * <p>For example to make a GridPanel a cooperating target with the example illustrated in
\r
4289 * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>
\r
4290 myGridPanel.on('render', function() {
\r
4291 myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
\r
4293 // If the mouse is over a grid row, return that node. This is
\r
4294 // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
\r
4295 getTargetFromEvent: function(e) {
\r
4296 return e.getTarget(myGridPanel.getView().rowSelector);
\r
4299 // On entry into a target node, highlight that node.
\r
4300 onNodeEnter : function(target, dd, e, data){
\r
4301 Ext.fly(target).addClass('my-row-highlight-class');
\r
4304 // On exit from a target node, unhighlight that node.
\r
4305 onNodeOut : function(target, dd, e, data){
\r
4306 Ext.fly(target).removeClass('my-row-highlight-class');
\r
4309 // While over a target node, return the default drop allowed class which
\r
4310 // places a "tick" icon into the drag proxy.
\r
4311 onNodeOver : function(target, dd, e, data){
\r
4312 return Ext.dd.DropZone.prototype.dropAllowed;
\r
4315 // On node drop we can interrogate the target to find the underlying
\r
4316 // application object that is the real target of the dragged data.
\r
4317 // In this case, it is a Record in the GridPanel's Store.
\r
4318 // We can use the data set up by the DragZone's getDragData method to read
\r
4319 // any data we decided to attach in the DragZone's getDragData method.
\r
4320 onNodeDrop : function(target, dd, e, data){
\r
4321 var rowIndex = myGridPanel.getView().findRowIndex(target);
\r
4322 var r = myGridPanel.getStore().getAt(rowIndex);
\r
4323 Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
\r
4324 ' on Record id ' + r.id);
\r
4330 * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
\r
4331 * cooperates with this DropZone.
\r
4333 * @param {Mixed} el The container element
\r
4334 * @param {Object} config
\r
4336 Ext.dd.DropZone = function(el, config){
\r
4337 Ext.dd.DropZone.superclass.constructor.call(this, el, config);
\r
4340 Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {
\r
4342 * Returns a custom data object associated with the DOM node that is the target of the event. By default
\r
4343 * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
\r
4344 * provide your own custom lookup.
\r
4345 * @param {Event} e The event
\r
4346 * @return {Object} data The custom data
\r
4348 getTargetFromEvent : function(e){
\r
4349 return Ext.dd.Registry.getTargetFromEvent(e);
\r
4353 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
\r
4354 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
\r
4355 * This method has no default implementation and should be overridden to provide
\r
4356 * node-specific processing if necessary.
\r
4357 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
\r
4358 * {@link #getTargetFromEvent} for this node)
\r
4359 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4360 * @param {Event} e The event
\r
4361 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4363 onNodeEnter : function(n, dd, e, data){
\r
4368 * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
\r
4369 * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
\r
4370 * The default implementation returns this.dropNotAllowed, so it should be
\r
4371 * overridden to provide the proper feedback.
\r
4372 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
\r
4373 * {@link #getTargetFromEvent} for this node)
\r
4374 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4375 * @param {Event} e The event
\r
4376 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4377 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4378 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4380 onNodeOver : function(n, dd, e, data){
\r
4381 return this.dropAllowed;
\r
4385 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
\r
4386 * the drop node without dropping. This method has no default implementation and should be overridden to provide
\r
4387 * node-specific processing if necessary.
\r
4388 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
\r
4389 * {@link #getTargetFromEvent} for this node)
\r
4390 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4391 * @param {Event} e The event
\r
4392 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4394 onNodeOut : function(n, dd, e, data){
\r
4399 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
\r
4400 * the drop node. The default implementation returns false, so it should be overridden to provide the
\r
4401 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
\r
4402 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
\r
4403 * {@link #getTargetFromEvent} for this node)
\r
4404 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4405 * @param {Event} e The event
\r
4406 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4407 * @return {Boolean} True if the drop was valid, else false
\r
4409 onNodeDrop : function(n, dd, e, data){
\r
4414 * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
\r
4415 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
\r
4416 * it should be overridden to provide the proper feedback if necessary.
\r
4417 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4418 * @param {Event} e The event
\r
4419 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4420 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4421 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4423 onContainerOver : function(dd, e, data){
\r
4424 return this.dropNotAllowed;
\r
4428 * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
\r
4429 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
\r
4430 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
\r
4431 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
\r
4432 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4433 * @param {Event} e The event
\r
4434 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4435 * @return {Boolean} True if the drop was valid, else false
\r
4437 onContainerDrop : function(dd, e, data){
\r
4442 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
\r
4443 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
\r
4444 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
\r
4445 * you should override this method and provide a custom implementation.
\r
4446 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4447 * @param {Event} e The event
\r
4448 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4449 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4450 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4452 notifyEnter : function(dd, e, data){
\r
4453 return this.dropNotAllowed;
\r
4457 * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
\r
4458 * This method will be called on every mouse movement while the drag source is over the drop zone.
\r
4459 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
\r
4460 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
\r
4461 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
\r
4462 * registered node, it will call {@link #onContainerOver}.
\r
4463 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4464 * @param {Event} e The event
\r
4465 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4466 * @return {String} status The CSS class that communicates the drop status back to the source so that the
\r
4467 * underlying {@link Ext.dd.StatusProxy} can be updated
\r
4469 notifyOver : function(dd, e, data){
\r
4470 var n = this.getTargetFromEvent(e);
\r
4471 if(!n){ // not over valid drop target
\r
4472 if(this.lastOverNode){
\r
4473 this.onNodeOut(this.lastOverNode, dd, e, data);
\r
4474 this.lastOverNode = null;
\r
4476 return this.onContainerOver(dd, e, data);
\r
4478 if(this.lastOverNode != n){
\r
4479 if(this.lastOverNode){
\r
4480 this.onNodeOut(this.lastOverNode, dd, e, data);
\r
4482 this.onNodeEnter(n, dd, e, data);
\r
4483 this.lastOverNode = n;
\r
4485 return this.onNodeOver(n, dd, e, data);
\r
4489 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
\r
4490 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
\r
4491 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
\r
4492 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
\r
4493 * @param {Event} e The event
\r
4494 * @param {Object} data An object containing arbitrary data supplied by the drag zone
\r
4496 notifyOut : function(dd, e, data){
\r
4497 if(this.lastOverNode){
\r
4498 this.onNodeOut(this.lastOverNode, dd, e, data);
\r
4499 this.lastOverNode = null;
\r
4504 * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
\r
4505 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
\r
4506 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
\r
4507 * otherwise it will call {@link #onContainerDrop}.
\r
4508 * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
\r
4509 * @param {Event} e The event
\r
4510 * @param {Object} data An object containing arbitrary data supplied by the drag source
\r
4511 * @return {Boolean} True if the drop was valid, else false
\r
4513 notifyDrop : function(dd, e, data){
\r
4514 if(this.lastOverNode){
\r
4515 this.onNodeOut(this.lastOverNode, dd, e, data);
\r
4516 this.lastOverNode = null;
\r
4518 var n = this.getTargetFromEvent(e);
\r
4520 this.onNodeDrop(n, dd, e, data) :
\r
4521 this.onContainerDrop(dd, e, data);
\r
4525 triggerCacheRefresh : function(){
\r
4526 Ext.dd.DDM.refreshCache(this.groups);
\r
4529 * @class Ext.Element
\r
4531 Ext.Element.addMethods({
\r
4533 * Initializes a {@link Ext.dd.DD} drag drop object for this element.
\r
4534 * @param {String} group The group the DD object is member of
\r
4535 * @param {Object} config The DD config object
\r
4536 * @param {Object} overrides An object containing methods to override/implement on the DD object
\r
4537 * @return {Ext.dd.DD} The DD object
\r
4539 initDD : function(group, config, overrides){
\r
4540 var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
\r
4541 return Ext.apply(dd, overrides);
\r
4545 * Initializes a {@link Ext.dd.DDProxy} object for this element.
\r
4546 * @param {String} group The group the DDProxy object is member of
\r
4547 * @param {Object} config The DDProxy config object
\r
4548 * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
\r
4549 * @return {Ext.dd.DDProxy} The DDProxy object
\r
4551 initDDProxy : function(group, config, overrides){
\r
4552 var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
\r
4553 return Ext.apply(dd, overrides);
\r
4557 * Initializes a {@link Ext.dd.DDTarget} object for this element.
\r
4558 * @param {String} group The group the DDTarget object is member of
\r
4559 * @param {Object} config The DDTarget config object
\r
4560 * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
\r
4561 * @return {Ext.dd.DDTarget} The DDTarget object
\r
4563 initDDTarget : function(group, config, overrides){
\r
4564 var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
\r
4565 return Ext.apply(dd, overrides);
\r