2 * This is a derivative of the similarly named class in the YUI Library.
3 * The original license:
4 * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
5 * Code licensed under the BSD License:
6 * http://developer.yahoo.net/yui/license.txt
11 * @class Ext.dd.DragDrop
12 * Defines the interface and base operation of items that that can be
13 * dragged or can be drop targets. It was designed to be extended, overriding
14 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
15 * Up to three html elements can be associated with a DragDrop instance:
17 * <li>linked element: the element that is passed into the constructor.
18 * This is the element which defines the boundaries for interaction with
19 * other DragDrop objects.</li>
20 * <li>handle element(s): The drag operation only occurs if the element that
21 * was clicked matches a handle element. By default this is the linked
22 * element, but there are times that you will want only a portion of the
23 * linked element to initiate the drag operation, and the setHandleElId()
24 * method provides a way to define this.</li>
25 * <li>drag element: this represents the element that would be moved along
26 * with the cursor during a drag operation. By default, this is the linked
27 * element itself as in {@link Ext.dd.DD}. setDragElId() lets you define
28 * a separate element that would be moved, as in {@link Ext.dd.DDProxy}.
31 * This class should not be instantiated until the onload event to ensure that
32 * the associated elements are available.
33 * The following would define a DragDrop obj that would interact with any
34 * other DragDrop obj in the "group1" group:
36 * dd = new Ext.dd.DragDrop("div1", "group1");
38 * Since none of the event handlers have been implemented, nothing would
39 * actually happen if you were to run the code above. Normally you would
40 * override this class or one of the default implementations, but you can
41 * also override the methods you want on an instance of the class...
43 * dd.onDragDrop = function(e, id) {
44 * alert("dd was dropped on " + id);
48 * @param {String} id of the element that is linked to this instance
49 * @param {String} sGroup the group of related DragDrop objects
50 * @param {object} config an object containing configurable attributes
51 * Valid properties for DragDrop:
52 * padding, isTarget, maintainOffset, primaryButtonOnly
55 Ext.define('Ext.dd.DragDrop', {
56 requires: ['Ext.dd.DragDropManager'],
57 constructor: function(id, sGroup, config) {
59 this.init(id, sGroup, config);
64 * Set to false to enable a DragDrop object to fire drag events while dragging
65 * over its own Element. Defaults to true - DragDrop objects do not by default
66 * fire drag events to themselves.
67 * @property ignoreSelf
72 * The id of the element associated with this object. This is what we
73 * refer to as the "linked element" because the size and position of
74 * this element is used to determine when the drag and drop objects have
82 * Configuration attributes passed into the constructor
89 * The id of the element that will be dragged. By default this is same
90 * as the linked element, but could be changed to another element. Ex:
99 * The ID of the element that initiates the drag operation. By default
100 * this is the linked element, but could be changed to be a child of this
101 * element. This lets us do things like only starting the drag when the
102 * header element within the linked html element is clicked.
103 * @property handleElId
110 * An object who's property names identify HTML tags to be considered invalid as drag handles.
111 * A non-null property value identifies the tag as invalid. Defaults to the
112 * following value which prevents drag operations from being initiated by <a> elements:<pre><code>
116 * @property invalidHandleTypes
119 invalidHandleTypes: null,
122 * An object who's property names identify the IDs of elements to be considered invalid as drag handles.
123 * A non-null property value identifies the ID as invalid. For example, to prevent
124 * dragging from being initiated on element ID "foo", use:<pre><code>
128 * @property invalidHandleIds
131 invalidHandleIds: null,
134 * An Array of CSS class names for elements to be considered in valid as drag handles.
135 * @property invalidHandleClasses
138 invalidHandleClasses: null,
141 * The linked element's absolute X position at the time the drag was
143 * @property startPageX
150 * The linked element's absolute X position at the time the drag was
152 * @property startPageY
159 * The group defines a logical collection of DragDrop objects that are
160 * related. Instances only get events when interacting with other
161 * DragDrop object in the same group. This lets us define multiple
162 * groups using a single DragDrop subclass if we want.
164 * @type object An object in the format {'group1':true, 'group2':true}
169 * Individual drag/drop instances can be locked. This will prevent
170 * onmousedown start drag.
186 * When set to true, other DD objects in cooperating DDGroups do not receive
187 * notification events when this DD object is dragged over them. Defaults to false.
194 * Unlock this instace
202 * By default, all instances can be a drop target. This can be disabled by
203 * setting isTarget to false.
210 * The padding configured for this drag and drop object for calculating
211 * the drop zone intersection with this object.
212 * An array containing the 4 padding values: [top, right, bottom, left]
213 * @property {[int]} padding
218 * Cached reference to the linked element
225 * Internal typeof flag
226 * @property __ygDragDrop
232 * Set to true when horizontal contraints are applied
233 * @property constrainX
240 * Set to true when vertical contraints are applied
241 * @property constrainY
248 * The left constraint
256 * The right constraint
272 * The down constraint
280 * Maintain offsets when we resetconstraints. Set to true when you want
281 * the position of the element relative to its parent to stay the same
282 * when the page changes
284 * @property maintainOffset
287 maintainOffset: false,
290 * Array of pixel locations the element will snap to if we specified a
291 * horizontal graduation/interval. This array is generated automatically
292 * when you define a tick interval.
293 * @property {[int]} xTicks
298 * Array of pixel locations the element will snap to if we specified a
299 * vertical graduation/interval. This array is generated automatically
300 * when you define a tick interval.
301 * @property {[int]} yTicks
306 * By default the drag and drop instance will only respond to the primary
307 * button click (left button for a right-handed mouse). Set to true to
308 * allow drag and drop to start with any mouse click that is propogated
310 * @property primaryButtonOnly
313 primaryButtonOnly: true,
316 * The available property is false until the linked dom element is accessible.
317 * @property available
323 * By default, drags can only be initiated if the mousedown occurs in the
324 * region the linked element is. This is done in part to work around a
325 * bug in some browsers that mis-report the mousedown if the previous
326 * mouseup happened outside of the window. This property is set to true
327 * if outer handles are defined.
329 * @property hasOuterHandles
333 hasOuterHandles: false,
336 * Code that executes immediately before the startDrag event
337 * @method b4StartDrag
340 b4StartDrag: function(x, y) { },
343 * Abstract method called after a drag/drop object is clicked
344 * and the drag or mousedown time thresholds have beeen met.
346 * @param {int} X click location
347 * @param {int} Y click location
349 startDrag: function(x, y) { /* override this */ },
352 * Code that executes immediately before the onDrag event
356 b4Drag: function(e) { },
359 * Abstract method called during the onMouseMove event while dragging an
362 * @param {Event} e the mousemove event
364 onDrag: function(e) { /* override this */ },
367 * Abstract method called when this element fist begins hovering over
368 * another DragDrop obj
369 * @method onDragEnter
370 * @param {Event} e the mousemove event
371 * @param {String|DragDrop[]} id In POINT mode, the element
372 * id this is hovering over. In INTERSECT mode, an array of one or more
373 * dragdrop items being hovered over.
375 onDragEnter: function(e, id) { /* override this */ },
378 * Code that executes immediately before the onDragOver event
382 b4DragOver: function(e) { },
385 * Abstract method called when this element is hovering over another
388 * @param {Event} e the mousemove event
389 * @param {String|DragDrop[]} id In POINT mode, the element
390 * id this is hovering over. In INTERSECT mode, an array of dd items
391 * being hovered over.
393 onDragOver: function(e, id) { /* override this */ },
396 * Code that executes immediately before the onDragOut event
400 b4DragOut: function(e) { },
403 * Abstract method called when we are no longer hovering over an element
405 * @param {Event} e the mousemove event
406 * @param {String|DragDrop[]} id In POINT mode, the element
407 * id this was hovering over. In INTERSECT mode, an array of dd items
408 * that the mouse is no longer over.
410 onDragOut: function(e, id) { /* override this */ },
413 * Code that executes immediately before the onDragDrop event
417 b4DragDrop: function(e) { },
420 * Abstract method called when this item is dropped on another DragDrop
423 * @param {Event} e the mouseup event
424 * @param {String|DragDrop[]} id In POINT mode, the element
425 * id this was dropped on. In INTERSECT mode, an array of dd items this
428 onDragDrop: function(e, id) { /* override this */ },
431 * Abstract method called when this item is dropped on an area with no
433 * @method onInvalidDrop
434 * @param {Event} e the mouseup event
436 onInvalidDrop: function(e) { /* override this */ },
439 * Code that executes immediately before the endDrag event
443 b4EndDrag: function(e) { },
446 * Fired when we are done dragging the object
448 * @param {Event} e the mouseup event
450 endDrag: function(e) { /* override this */ },
453 * Code executed immediately before the onMouseDown event
454 * @method b4MouseDown
455 * @param {Event} e the mousedown event
458 b4MouseDown: function(e) { },
461 * Event handler that fires when a drag/drop obj gets a mousedown
462 * @method onMouseDown
463 * @param {Event} e the mousedown event
465 onMouseDown: function(e) { /* override this */ },
468 * Event handler that fires when a drag/drop obj gets a mouseup
470 * @param {Event} e the mouseup event
472 onMouseUp: function(e) { /* override this */ },
475 * Override the onAvailable method to do what is needed after the initial
476 * position was determined.
477 * @method onAvailable
479 onAvailable: function () {
483 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
494 * Initializes the drag drop object's constraints to restrict movement to a certain element.
498 var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
499 { dragElId: "existingProxyDiv" });
500 dd.startDrag = function(){
501 this.constrainTo("parent-id");
504 * Or you can initalize it using the {@link Ext.core.Element} object:
506 Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
507 startDrag : function(){
508 this.constrainTo("parent-id");
512 * @param {Mixed} constrainTo The element to constrain to.
513 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
514 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
515 * an object containing the sides to pad. For example: {right:10, bottom:10}
516 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
518 constrainTo : function(constrainTo, pad, inContent){
519 if(Ext.isNumber(pad)){
520 pad = {left: pad, right:pad, top:pad, bottom:pad};
522 pad = pad || this.defaultPadding;
523 var b = Ext.get(this.getEl()).getBox(),
524 ce = Ext.get(constrainTo),
528 if(cd == document.body){
529 c = { x: s.left, y: s.top, width: Ext.core.Element.getViewWidth(), height: Ext.core.Element.getViewHeight()};
532 c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
536 var topSpace = b.y - c.y,
537 leftSpace = b.x - c.x;
539 this.resetConstraints();
540 this.setXConstraint(leftSpace - (pad.left||0), // left
541 c.width - leftSpace - b.width - (pad.right||0), //right
544 this.setYConstraint(topSpace - (pad.top||0), //top
545 c.height - topSpace - b.height - (pad.bottom||0), //bottom
551 * Returns a reference to the linked element
553 * @return {HTMLElement} the html element
557 this._domRef = Ext.getDom(this.id);
564 * Returns a reference to the actual element to drag. By default this is
565 * the same as the html element, but it can be assigned to another
566 * element. An example of this can be found in Ext.dd.DDProxy
568 * @return {HTMLElement} the html element
570 getDragEl: function() {
571 return Ext.getDom(this.dragElId);
575 * Sets up the DragDrop object. Must be called in the constructor of any
576 * Ext.dd.DragDrop subclass
578 * @param id the id of the linked element
579 * @param {String} sGroup the group of related items
580 * @param {object} config configuration attributes
582 init: function(id, sGroup, config) {
583 this.initTarget(id, sGroup, config);
584 Ext.EventManager.on(this.id, "mousedown", this.handleMouseDown, this);
585 // Ext.EventManager.on(this.id, "selectstart", Event.preventDefault);
589 * Initializes Targeting functionality only... the object does not
590 * get a mousedown handler.
592 * @param id the id of the linked element
593 * @param {String} sGroup the group of related items
594 * @param {object} config configuration attributes
596 initTarget: function(id, sGroup, config) {
598 // configuration attributes
599 this.config = config || {};
601 // create a local reference to the drag and drop manager
602 this.DDMInstance = Ext.dd.DragDropManager;
603 // initialize the groups array
606 // assume that we have an element reference instead of an id if the
607 // parameter is not a string
608 if (typeof id !== "string") {
615 // add to an interaction group
616 this.addToGroup((sGroup) ? sGroup : "default");
618 // We don't want to register this as the handle with the manager
619 // so we just set the id rather than calling the setter.
620 this.handleElId = id;
622 // the linked element is the element that gets dragged by default
623 this.setDragElId(id);
625 // by default, clicked anchors will not start drag operations.
626 this.invalidHandleTypes = { A: "A" };
627 this.invalidHandleIds = {};
628 this.invalidHandleClasses = [];
632 this.handleOnAvailable();
636 * Applies the configuration parameters that were passed into the constructor.
637 * This is supposed to happen at each level through the inheritance chain. So
638 * a DDProxy implentation will execute apply config on DDProxy, DD, and
639 * DragDrop in order to get all of the parameters that are available in
641 * @method applyConfig
643 applyConfig: function() {
645 // configurable properties:
646 // padding, isTarget, maintainOffset, primaryButtonOnly
647 this.padding = this.config.padding || [0, 0, 0, 0];
648 this.isTarget = (this.config.isTarget !== false);
649 this.maintainOffset = (this.config.maintainOffset);
650 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
655 * Executed when the linked element is available
656 * @method handleOnAvailable
659 handleOnAvailable: function() {
660 this.available = true;
661 this.resetConstraints();
666 * Configures the padding for the target zone in px. Effectively expands
667 * (or reduces) the virtual object size for targeting calculations.
668 * Supports css-style shorthand; if only one parameter is passed, all sides
669 * will have that padding, and if only two are passed, the top and bottom
670 * will have the first param, the left and right the second.
672 * @param {int} iTop Top pad
673 * @param {int} iRight Right pad
674 * @param {int} iBot Bot pad
675 * @param {int} iLeft Left pad
677 setPadding: function(iTop, iRight, iBot, iLeft) {
678 // this.padding = [iLeft, iRight, iTop, iBot];
679 if (!iRight && 0 !== iRight) {
680 this.padding = [iTop, iTop, iTop, iTop];
681 } else if (!iBot && 0 !== iBot) {
682 this.padding = [iTop, iRight, iTop, iRight];
684 this.padding = [iTop, iRight, iBot, iLeft];
689 * Stores the initial placement of the linked element.
690 * @method setInitPosition
691 * @param {int} diffX the X offset, default 0
692 * @param {int} diffY the Y offset, default 0
694 setInitPosition: function(diffX, diffY) {
695 var el = this.getEl();
697 if (!this.DDMInstance.verifyEl(el)) {
704 var p = Ext.core.Element.getXY( el );
706 this.initPageX = p[0] - dx;
707 this.initPageY = p[1] - dy;
709 this.lastPageX = p[0];
710 this.lastPageY = p[1];
712 this.setStartPosition(p);
716 * Sets the start position of the element. This is set when the obj
717 * is initialized, the reset when a drag is started.
718 * @method setStartPosition
719 * @param pos current position (from previous lookup)
722 setStartPosition: function(pos) {
723 var p = pos || Ext.core.Element.getXY( this.getEl() );
724 this.deltaSetXY = null;
726 this.startPageX = p[0];
727 this.startPageY = p[1];
731 * Add this instance to a group of related drag/drop objects. All
732 * instances belong to at least one group, and can belong to as many
735 * @param sGroup {string} the name of the group
737 addToGroup: function(sGroup) {
738 this.groups[sGroup] = true;
739 this.DDMInstance.regDragDrop(this, sGroup);
743 * Remove's this instance from the supplied interaction group
744 * @method removeFromGroup
745 * @param {string} sGroup The group to drop
747 removeFromGroup: function(sGroup) {
748 if (this.groups[sGroup]) {
749 delete this.groups[sGroup];
752 this.DDMInstance.removeDDFromGroup(this, sGroup);
756 * Allows you to specify that an element other than the linked element
757 * will be moved with the cursor during a drag
758 * @method setDragElId
759 * @param id {string} the id of the element that will be used to initiate the drag
761 setDragElId: function(id) {
766 * Allows you to specify a child of the linked element that should be
767 * used to initiate the drag operation. An example of this would be if
768 * you have a content div with text and links. Clicking anywhere in the
769 * content area would normally start the drag operation. Use this method
770 * to specify that an element inside of the content div is the element
771 * that starts the drag operation.
772 * @method setHandleElId
773 * @param id {string} the id of the element that will be used to
776 setHandleElId: function(id) {
777 if (typeof id !== "string") {
780 this.handleElId = id;
781 this.DDMInstance.regHandle(this.id, id);
785 * Allows you to set an element outside of the linked element as a drag
787 * @method setOuterHandleElId
788 * @param id the id of the element that will be used to initiate the drag
790 setOuterHandleElId: function(id) {
791 if (typeof id !== "string") {
794 Ext.EventManager.on(id, "mousedown", this.handleMouseDown, this);
795 this.setHandleElId(id);
797 this.hasOuterHandles = true;
801 * Remove all drag and drop hooks for this element
805 Ext.EventManager.un(this.id, "mousedown", this.handleMouseDown, this);
807 this.DDMInstance._remove(this);
810 destroy : function(){
815 * Returns true if this instance is locked, or the drag drop mgr is locked
816 * (meaning that all drag/drop is disabled on the page.)
818 * @return {boolean} true if this obj or all drag/drop is locked, else
821 isLocked: function() {
822 return (this.DDMInstance.isLocked() || this.locked);
826 * Fired when this object is clicked
827 * @method handleMouseDown
829 * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
832 handleMouseDown: function(e, oDD){
833 if (this.primaryButtonOnly && e.button != 0) {
837 if (this.isLocked()) {
841 this.DDMInstance.refreshCache(this.groups);
843 var pt = e.getPoint();
844 if (!this.hasOuterHandles && !this.DDMInstance.isOverTarget(pt, this) ) {
846 if (this.clickValidator(e)) {
847 // set the initial element position
848 this.setStartPosition();
852 this.DDMInstance.handleMouseDown(e, this);
854 this.DDMInstance.stopEvent(e);
862 clickValidator: function(e) {
863 var target = e.getTarget();
864 return ( this.isValidHandleChild(target) &&
865 (this.id == this.handleElId ||
866 this.DDMInstance.handleWasClicked(target, this.id)) );
870 * Allows you to specify a tag name that should not start a drag operation
871 * when clicked. This is designed to facilitate embedding links within a
872 * drag handle that do something other than start the drag.
873 * @method addInvalidHandleType
874 * @param {string} tagName the type of element to exclude
876 addInvalidHandleType: function(tagName) {
877 var type = tagName.toUpperCase();
878 this.invalidHandleTypes[type] = type;
882 * Lets you to specify an element id for a child of a drag handle
883 * that should not initiate a drag
884 * @method addInvalidHandleId
885 * @param {string} id the element id of the element you wish to ignore
887 addInvalidHandleId: function(id) {
888 if (typeof id !== "string") {
891 this.invalidHandleIds[id] = id;
895 * Lets you specify a css class of elements that will not initiate a drag
896 * @method addInvalidHandleClass
897 * @param {string} cssClass the class of the elements you wish to ignore
899 addInvalidHandleClass: function(cssClass) {
900 this.invalidHandleClasses.push(cssClass);
904 * Unsets an excluded tag name set by addInvalidHandleType
905 * @method removeInvalidHandleType
906 * @param {string} tagName the type of element to unexclude
908 removeInvalidHandleType: function(tagName) {
909 var type = tagName.toUpperCase();
910 // this.invalidHandleTypes[type] = null;
911 delete this.invalidHandleTypes[type];
915 * Unsets an invalid handle id
916 * @method removeInvalidHandleId
917 * @param {string} id the id of the element to re-enable
919 removeInvalidHandleId: function(id) {
920 if (typeof id !== "string") {
923 delete this.invalidHandleIds[id];
927 * Unsets an invalid css class
928 * @method removeInvalidHandleClass
929 * @param {string} cssClass the class of the element(s) you wish to
932 removeInvalidHandleClass: function(cssClass) {
933 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
934 if (this.invalidHandleClasses[i] == cssClass) {
935 delete this.invalidHandleClasses[i];
941 * Checks the tag exclusion list to see if this click should be ignored
942 * @method isValidHandleChild
943 * @param {HTMLElement} node the HTMLElement to evaluate
944 * @return {boolean} true if this is a valid tag type, false if not
946 isValidHandleChild: function(node) {
949 // var n = (node.nodeName == "#text") ? node.parentNode : node;
952 nodeName = node.nodeName.toUpperCase();
954 nodeName = node.nodeName;
956 valid = valid && !this.invalidHandleTypes[nodeName];
957 valid = valid && !this.invalidHandleIds[node.id];
959 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
960 valid = !Ext.fly(node).hasCls(this.invalidHandleClasses[i]);
969 * Create the array of horizontal tick marks if an interval was specified
970 * in setXConstraint().
974 setXTicks: function(iStartX, iTickSize) {
976 this.xTickSize = iTickSize;
980 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
982 this.xTicks[this.xTicks.length] = i;
987 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
989 this.xTicks[this.xTicks.length] = i;
994 Ext.Array.sort(this.xTicks, this.DDMInstance.numericSort);
998 * Create the array of vertical tick marks if an interval was specified in
1003 setYTicks: function(iStartY, iTickSize) {
1005 this.yTickSize = iTickSize;
1009 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1011 this.yTicks[this.yTicks.length] = i;
1016 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1018 this.yTicks[this.yTicks.length] = i;
1023 Ext.Array.sort(this.yTicks, this.DDMInstance.numericSort);
1027 * By default, the element can be dragged any place on the screen. Use
1028 * this method to limit the horizontal travel of the element. Pass in
1029 * 0,0 for the parameters if you want to lock the drag to the y axis.
1030 * @method setXConstraint
1031 * @param {int} iLeft the number of pixels the element can move to the left
1032 * @param {int} iRight the number of pixels the element can move to the
1034 * @param {int} iTickSize optional parameter for specifying that the
1036 * should move iTickSize pixels at a time.
1038 setXConstraint: function(iLeft, iRight, iTickSize) {
1039 this.leftConstraint = iLeft;
1040 this.rightConstraint = iRight;
1042 this.minX = this.initPageX - iLeft;
1043 this.maxX = this.initPageX + iRight;
1044 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1046 this.constrainX = true;
1050 * Clears any constraints applied to this instance. Also clears ticks
1051 * since they can't exist independent of a constraint at this time.
1052 * @method clearConstraints
1054 clearConstraints: function() {
1055 this.constrainX = false;
1056 this.constrainY = false;
1061 * Clears any tick interval defined for this instance
1062 * @method clearTicks
1064 clearTicks: function() {
1072 * By default, the element can be dragged any place on the screen. Set
1073 * this to limit the vertical travel of the element. Pass in 0,0 for the
1074 * parameters if you want to lock the drag to the x axis.
1075 * @method setYConstraint
1076 * @param {int} iUp the number of pixels the element can move up
1077 * @param {int} iDown the number of pixels the element can move down
1078 * @param {int} iTickSize optional parameter for specifying that the
1079 * element should move iTickSize pixels at a time.
1081 setYConstraint: function(iUp, iDown, iTickSize) {
1082 this.topConstraint = iUp;
1083 this.bottomConstraint = iDown;
1085 this.minY = this.initPageY - iUp;
1086 this.maxY = this.initPageY + iDown;
1087 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1089 this.constrainY = true;
1094 * resetConstraints must be called if you manually reposition a dd element.
1095 * @method resetConstraints
1096 * @param {boolean} maintainOffset
1098 resetConstraints: function() {
1099 // Maintain offsets if necessary
1100 if (this.initPageX || this.initPageX === 0) {
1101 // figure out how much this thing has moved
1102 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
1103 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
1105 this.setInitPosition(dx, dy);
1107 // This is the first time we have detected the element's position
1109 this.setInitPosition();
1112 if (this.constrainX) {
1113 this.setXConstraint( this.leftConstraint,
1114 this.rightConstraint,
1118 if (this.constrainY) {
1119 this.setYConstraint( this.topConstraint,
1120 this.bottomConstraint,
1126 * Normally the drag element is moved pixel by pixel, but we can specify
1127 * that it move a number of pixels at a time. This method resolves the
1128 * location when we have it set up like this.
1130 * @param {int} val where we want to place the object
1131 * @param {int[]} tickArray sorted array of valid points
1132 * @return {int} the closest tick
1135 getTick: function(val, tickArray) {
1137 // If tick interval is not defined, it is effectively 1 pixel,
1138 // so we return the value passed to us.
1140 } else if (tickArray[0] >= val) {
1141 // The value is lower than the first tick, so we return the first
1143 return tickArray[0];
1145 for (var i=0, len=tickArray.length; i<len; ++i) {
1147 if (tickArray[next] && tickArray[next] >= val) {
1148 var diff1 = val - tickArray[i];
1149 var diff2 = tickArray[next] - val;
1150 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1154 // The value is larger than the last tick, so we return the last
1156 return tickArray[tickArray.length - 1];
1163 * @return {string} string representation of the dd obj
1165 toString: function() {
1166 return ("DragDrop " + this.id);