dd-drag-debug.js revision 9eb94626cedb24875edf2f541cdceb32c6a96046
5cd4555ad444fd391002ae32450572054369fd42Rob AusteinYUI.add('dd-drag', function(Y) {
5cd4555ad444fd391002ae32450572054369fd42Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews /**
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews * Provides the ability to drag a Node.
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @module dd
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @submodule dd-drag
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews */
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews /**
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * Provides the ability to drag a Node.
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @class Drag
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @extends Base
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @constructor
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @namespace DD
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews */
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews var DDM = Y.DD.DDM,
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews NODE = 'node',
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews DRAGGING = 'dragging',
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews DRAG_NODE = 'dragNode',
26440aaebba1acb5c8810f7faa26ad3b7553762eMark Andrews OFFSET_HEIGHT = 'offsetHeight',
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews OFFSET_WIDTH = 'offsetWidth',
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:mouseup
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @description Handles the mouseup DOM event, does nothing internally just fires.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @bubbles DDM
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @type {CustomEvent}
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews */
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews /**
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @event drag:mouseDown
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @description Handles the mousedown DOM event, checks to see if you have a valid handle then starts the drag timers.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @preventable _defMouseDownFn
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @param {EventFacade} event An Event Facade object with the following specific property added:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <dl><dt>ev</dt><dd>The original mousedown event.</dd></dl>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @bubbles DDM
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @type {CustomEvent}
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews */
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews EV_MOUSE_DOWN = 'drag:mouseDown',
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:afterMouseDown
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @description Fires after the mousedown event has been cleared.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @param {EventFacade} event An Event Facade object with the following specific property added:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <dl><dt>ev</dt><dd>The original mousedown event.</dd></dl>
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @bubbles DDM
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @type {CustomEvent}
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews */
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews EV_AFTER_MOUSE_DOWN = 'drag:afterMouseDown',
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews /**
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @event drag:removeHandle
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @description Fires after a handle is removed.
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * @param {EventFacade} event An Event Facade object with the following specific property added:
33d96fbbc8aa221508f3c780539bf44810fd2c9cMark Andrews * <dl><dt>handle</dt><dd>The handle that was removed.</dd></dl>
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @bubbles DDM
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_REMOVE_HANDLE = 'drag:removeHandle',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:addHandle
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires after a handle is added.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl><dt>handle</dt><dd>The handle that was added.</dd></dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_ADD_HANDLE = 'drag:addHandle',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:removeInvalid
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires after an invalid selector is removed.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl><dt>handle</dt><dd>The handle that was removed.</dd></dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
f5d30e2864e048a42c4dc1134993ae7efdb5d6c3Mark Andrews */
1b06367c345e972a0c719a6e821db3e875f20c3bMark Andrews EV_REMOVE_INVALID = 'drag:removeInvalid',
c1a883f2e04d94e99c433b1f6cfd0c0338f4ed85Mark Andrews /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:addInvalid
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires after an invalid selector is added.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl><dt>handle</dt><dd>The handle that was added.</dd></dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_ADD_INVALID = 'drag:addInvalid',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:start
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires at the start of a drag operation.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageX</dt><dd>The original node position X.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageY</dt><dd>The original node position Y.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>startTime</dt><dd>The startTime of the event. getTime on the current Date object.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_START = 'drag:start',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:end
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires at the end of a drag operation.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageX</dt><dd>The current node position X.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageY</dt><dd>The current node position Y.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>startTime</dt><dd>The startTime of the event, from the start event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>endTime</dt><dd>The endTime of the event. getTime on the current Date object.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_END = 'drag:end',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:drag
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires every mousemove during a drag operation.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageX</dt><dd>The current node position X.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageY</dt><dd>The current node position Y.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>scroll</dt><dd>Should a scroll action occur.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>info</dt><dd>Object hash containing calculated XY arrays: start, xy, delta, offset</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_DRAG = 'drag:drag',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:align
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @preventable _defAlignFn
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node is aligned.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageX</dt><dd>The current node position X.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageY</dt><dd>The current node position Y.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
819fe493f97078521bb6b9a7b97583bef89f5abcMark Andrews * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein EV_ALIGN = 'drag:align',
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:over
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node is over a Drop Target. (Fired from dd-drop)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
8d709e3ee443222cd35e44eadc9a4c0a8d92fec2Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:enter
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node enters a Drop Target. (Fired from dd-drop)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:exit
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node exits a Drop Target. (Fired from dd-drop)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drop</dt><dd>The drop object at the time of the event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:drophit
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node is dropped on a valid Drop Target. (Fired from dd-ddm-drop)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drop</dt><dd>The best guess on what was dropped on.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>drag</dt><dd>The drag object at the time of the event.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>others</dt><dd>An array of all the other drop targets that was dropped on.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @event drag:dropmiss
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Fires when this node is dropped on an invalid Drop Target. (Fired from dd-ddm-drop)
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {EventFacade} event An Event Facade object with the following specific property added:
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageX</dt><dd>The current node position X.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * <dt>pageY</dt><dd>The current node position Y.</dd>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * </dl>
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @bubbles DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {CustomEvent}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Drag = function(o) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._lazyAddAttrs = false;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Drag.superclass.constructor.apply(this, arguments);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein var valid = DDM._regDrag(this);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!valid) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.error('Failed to register node, already in use: ' + o.node);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein };
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Drag.NAME = 'drag';
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * This property defaults to "mousedown", but when drag-gestures is loaded, it is changed to "gesturemovestart"
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @static
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @property START_EVENT
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Drag.START_EVENT = 'mousedown';
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Drag.ATTRS = {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute node
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Y.Node instance to use as the element to initiate a drag operation
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Node
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein node: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(node) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (this._canDrag(node)) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return node;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein var n = Y.one(node);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!n) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.error('DD.Drag: Invalid Node Given: ' + node);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return n;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute dragNode
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Y.Node instance to use as the draggable element, defaults to node
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Node
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dragNode: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(node) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (this._canDrag(node)) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return node;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein var n = Y.one(node);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!n) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.error('DD.Drag: Invalid dragNode Given: ' + node);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return n;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute offsetNode
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Offset the drag element by the difference in cursor position: default true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein offsetNode: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute startCentered
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Center the dragNode to the mouse position on drag:start: default false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein startCentered: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute clickPixelThresh
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description The number of pixels to move to start a drag operation, default is 3.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Number
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein clickPixelThresh: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: DDM.get('clickPixelThresh')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute clickTimeThresh
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Number
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein clickTimeThresh: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: DDM.get('clickTimeThresh')
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute lock
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Set to lock this drag element so that it can't be dragged: default false.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein lock: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(lock) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (lock) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this.get(NODE).addClass(DDM.CSS_PREFIX + '-locked');
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein } else {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this.get(NODE).removeClass(DDM.CSS_PREFIX + '-locked');
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return lock;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute data
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description A payload holder to store arbitrary data about this drag object, can be used to store any value.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Mixed
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein data: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute move
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description If this is false, the drag element will not move with the cursor: default true. Can be used to "resize" the element.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein move: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute useShim
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Use the protective shim on all drag operations: default true. Only works with dd-ddm, not dd-ddm-base.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews useShim: {
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews value: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute activeHandle
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description This config option is set by Drag to inform you of which handle fired the drag event (in the case that there are several handles): default false.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Node
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein activeHandle: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute primaryButtonOnly
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description By default a drag operation will only begin if the mousedown occurred with the primary mouse button. Setting this to false will allow for all mousedown events to trigger a drag.
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews * @type Boolean
561a29af8c54a216e7d30b5b4f6e0d21661654ecMark Andrews */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein primaryButtonOnly: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute dragging
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description This attribute is not meant to be used by the implementor, it is meant to be used as an Event tracker so you can listen for it to change.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dragging: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein parent: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute target
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description This attribute only works if the dd-drop module has been loaded. It will make this node a drop target as well as draggable.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein target: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: false,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(config) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._handleTarget(config);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return config;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute dragMode
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of this Drag instance.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type String
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein dragMode: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: null,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(mode) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return DDM._setDragMode(mode);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute groups
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Array of groups to add this drag into.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Array
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein groups: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: ['default'],
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein getter: function() {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (!this._groups) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._groups = {};
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein var ret = [];
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.each(this._groups, function(v, k) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein ret[ret.length] = k;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein });
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return ret;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(g) {
7ba5dc6485e54258101da72455974dde38d04289Mark Andrews this._groups = {};
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.each(g, function(v, k) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._groups[v] = true;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }, this);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return g;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute handles
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Array of valid handles to add. Adding something here will set all handles, even if previously added with addHandle
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Array
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein handles: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: null,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(g) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (g) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._handles = {};
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.each(g, function(v, k) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein var key = v;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein if (v instanceof Y.Node || v instanceof Y.NodeList) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein key = v._yuid;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._handles[key] = v;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }, this);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein } else {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._handles = null;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return g;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @deprecated
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute bubbles
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Controls the default bubble parent for this Drag instance. Default: Y.DD.DDM. Set to false to disable bubbling. Use bubbleTargets in config
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Object
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein bubbles: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein setter: function(t) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.log('bubbles is deprecated use bubbleTargets: HOST', 'warn', 'dd');
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this.addTarget(t);
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return t;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @attribute haltDown
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Should the mousedown event be halted. Default: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type Boolean
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein haltDown: {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein value: true
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein }
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein };
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein Y.extend(Drag, Y.Base, {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * Checks the object for the methods needed to drag the object around.
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * Normally this would be a node instance, but in the case of Graphics, it
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * may be an SVG node or something similar.
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * @method _canDrag
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * @private
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * @param {Object} n The object to check
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * @return {Boolean} True or false if the Object contains the methods needed to Drag
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews */
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews _canDrag: function(n) {
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews if (n && n.setXY && n.getXY && n.test && n.contains) {
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews return true;
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews }
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews return false;
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews },
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews /**
3d711f2f75cb9a9ddcbf1fca9b2de192e75340e6Mark Andrews * @private
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @property _bubbleTargets
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description The default bubbleTarget for this object. Default: Y.DD.DDM
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein _bubbleTargets: Y.DD.DDM,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @method addToGroup
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Add this Drag instance to a group, this should be used for on-the-fly group additions.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {String} g The group to add this Drag Instance to.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @return {Self}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @chainable
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein addToGroup: function(g) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein this._groups[g] = true;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein DDM._activateTargets();
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return this;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @method removeFromGroup
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Remove this Drag instance from a group, this should be used for on-the-fly group removals.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @param {String} g The group to remove this Drag Instance from.
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @return {Self}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @chainable
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein removeFromGroup: function(g) {
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein delete this._groups[g];
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein DDM._activateTargets();
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein return this;
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein },
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @property target
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description This will be a reference to the Drop instance associated with this drag if the target: true config attribute is set..
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @type {Object}
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein */
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein target: null,
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein /**
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @private
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @method _handleTarget
268a4475065fe6a8cd7cc707820982cf5e98f430Rob Austein * @description Attribute handler for the target config attribute.
* @param {Boolean/Object} config The Config
*/
_handleTarget: function(config) {
if (Y.DD.Drop) {
if (config === false) {
if (this.target) {
DDM._unregTarget(this.target);
this.target = null;
}
return false;
} else {
if (!Y.Lang.isObject(config)) {
config = {};
}
config.bubbleTargets = ('bubbleTargets' in config) ? config.bubbleTargets : Y.Object.values(this._yuievt.targets);
config.node = this.get(NODE);
config.groups = config.groups || this.get('groups');
this.target = new Y.DD.Drop(config);
}
} else {
return false;
}
},
/**
* @private
* @property _groups
* @description Storage Array for the groups this drag belongs to.
* @type {Array}
*/
_groups: null,
/**
* @private
* @method _createEvents
* @description This method creates all the events for this Event Target and publishes them so we get Event Bubbling.
*/
_createEvents: function() {
this.publish(EV_MOUSE_DOWN, {
defaultFn: this._defMouseDownFn,
queuable: false,
emitFacade: true,
bubbles: true,
prefix: 'drag'
});
this.publish(EV_ALIGN, {
defaultFn: this._defAlignFn,
queuable: false,
emitFacade: true,
bubbles: true,
prefix: 'drag'
});
this.publish(EV_DRAG, {
defaultFn: this._defDragFn,
queuable: false,
emitFacade: true,
bubbles: true,
prefix: 'drag'
});
this.publish(EV_END, {
defaultFn: this._defEndFn,
preventedFn: this._prevEndFn,
queuable: false,
emitFacade: true,
bubbles: true,
prefix: 'drag'
});
var ev = [
EV_AFTER_MOUSE_DOWN,
EV_REMOVE_HANDLE,
EV_ADD_HANDLE,
EV_REMOVE_INVALID,
EV_ADD_INVALID,
EV_START,
'drag:drophit',
'drag:dropmiss',
'drag:over',
'drag:enter',
'drag:exit'
];
Y.each(ev, function(v, k) {
this.publish(v, {
type: v,
emitFacade: true,
bubbles: true,
preventable: false,
queuable: false,
prefix: 'drag'
});
}, this);
},
/**
* @private
* @property _ev_md
* @description A private reference to the mousedown DOM event
* @type {EventFacade}
*/
_ev_md: null,
/**
* @private
* @property _startTime
* @description The getTime of the mousedown event. Not used, just here in case someone wants/needs to use it.
* @type Date
*/
_startTime: null,
/**
* @private
* @property _endTime
* @description The getTime of the mouseup event. Not used, just here in case someone wants/needs to use it.
* @type Date
*/
_endTime: null,
/**
* @private
* @property _handles
* @description A private hash of the valid drag handles
* @type {Object}
*/
_handles: null,
/**
* @private
* @property _invalids
* @description A private hash of the invalid selector strings
* @type {Object}
*/
_invalids: null,
/**
* @private
* @property _invalidsDefault
* @description A private hash of the default invalid selector strings: {'textarea': true, 'input': true, 'a': true, 'button': true, 'select': true}
* @type {Object}
*/
_invalidsDefault: {'textarea': true, 'input': true, 'a': true, 'button': true, 'select': true },
/**
* @private
* @property _dragThreshMet
* @description Private flag to see if the drag threshhold was met
* @type {Boolean}
*/
_dragThreshMet: null,
/**
* @private
* @property _fromTimeout
* @description Flag to determine if the drag operation came from a timeout
* @type {Boolean}
*/
_fromTimeout: null,
/**
* @private
* @property _clickTimeout
* @description Holder for the setTimeout call
* @type {Boolean}
*/
_clickTimeout: null,
/**
* @property deltaXY
* @description The offset of the mouse position to the element's position
* @type {Array}
*/
deltaXY: null,
/**
* @property startXY
* @description The initial mouse position
* @type {Array}
*/
startXY: null,
/**
* @property nodeXY
* @description The initial element position
* @type {Array}
*/
nodeXY: null,
/**
* @property lastXY
* @description The position of the element as it's moving (for offset calculations)
* @type {Array}
*/
lastXY: null,
/**
* @property actXY
* @description The xy that the node will be set to. Changing this will alter the position as it's dragged.
* @type {Array}
*/
actXY: null,
/**
* @property realXY
* @description The real xy position of the node.
* @type {Array}
*/
realXY: null,
/**
* @property mouseXY
* @description The XY coords of the mousemove
* @type {Array}
*/
mouseXY: null,
/**
* @property region
* @description A region object associated with this drag, used for checking regions while dragging.
* @type Object
*/
region: null,
/**
* @private
* @method _handleMouseUp
* @description Handler for the mouseup DOM event
* @param {EventFacade} ev The Event
*/
_handleMouseUp: function(ev) {
this.fire('drag:mouseup');
this._fixIEMouseUp();
if (DDM.activeDrag) {
DDM._end();
}
},
/**
* @private
* @method _fixDragStart
* @description The function we use as the ondragstart handler when we start a drag in Internet Explorer. This keeps IE from blowing up on images as drag handles.
* @param {Event} e The Event
*/
_fixDragStart: function(e) {
e.preventDefault();
},
/**
* @private
* @method _ieSelectFix
* @description The function we use as the onselectstart handler when we start a drag in Internet Explorer
*/
_ieSelectFix: function() {
return false;
},
/**
* @private
* @property _ieSelectBack
* @description We will hold a copy of the current "onselectstart" method on this property, and reset it after we are done using it.
*/
_ieSelectBack: null,
/**
* @private
* @method _fixIEMouseDown
* @description This method copies the onselectstart listner on the document to the _ieSelectFix property
*/
_fixIEMouseDown: function(e) {
if (Y.UA.ie) {
this._ieSelectBack = Y.config.doc.body.onselectstart;
Y.config.doc.body.onselectstart = this._ieSelectFix;
}
},
/**
* @private
* @method _fixIEMouseUp
* @description This method copies the _ieSelectFix property back to the onselectstart listner on the document.
*/
_fixIEMouseUp: function() {
if (Y.UA.ie) {
Y.config.doc.body.onselectstart = this._ieSelectBack;
}
},
/**
* @private
* @method _handleMouseDownEvent
* @description Handler for the mousedown DOM event
* @param {EventFacade} ev The Event
*/
_handleMouseDownEvent: function(ev) {
this.fire(EV_MOUSE_DOWN, { ev: ev });
},
/**
* @private
* @method _defMouseDownFn
* @description Handler for the mousedown DOM event
* @param {EventFacade} e The Event
*/
_defMouseDownFn: function(e) {
var ev = e.ev;
this._dragThreshMet = false;
this._ev_md = ev;
if (this.get('primaryButtonOnly') && ev.button > 1) {
return false;
}
if (this.validClick(ev)) {
this._fixIEMouseDown(ev);
if (this.get('haltDown')) {
Y.log('Halting MouseDown', 'info', 'drag');
ev.halt();
} else {
Y.log('Preventing Default on MouseDown', 'info', 'drag');
ev.preventDefault();
}
this._setStartPosition([ev.pageX, ev.pageY]);
DDM.activeDrag = this;
this._clickTimeout = Y.later(this.get('clickTimeThresh'), this, this._timeoutCheck);
}
this.fire(EV_AFTER_MOUSE_DOWN, { ev: ev });
},
/**
* @method validClick
* @description Method first checks to see if we have handles, if so it validates the click against the handle. Then if it finds a valid handle, it checks it against the invalid handles list. Returns true if a good handle was used, false otherwise.
* @param {EventFacade} ev The Event
* @return {Boolean}
*/
validClick: function(ev) {
var r = false, n = false,
tar = ev.target,
hTest = null,
els = null,
nlist = null,
set = false;
if (this._handles) {
Y.each(this._handles, function(i, n) {
if (i instanceof Y.Node || i instanceof Y.NodeList) {
if (!r) {
nlist = i;
if (nlist instanceof Y.Node) {
nlist = new Y.NodeList(i._node);
}
nlist.each(function(nl) {
if (nl.contains(tar)) {
r = true;
}
});
}
} else if (Y.Lang.isString(n)) {
//Am I this or am I inside this
if (tar.test(n + ', ' + n + ' *') && !hTest) {
hTest = n;
r = true;
}
}
});
} else {
n = this.get(NODE);
if (n.contains(tar) || n.compareTo(tar)) {
r = true;
}
}
if (r) {
if (this._invalids) {
Y.each(this._invalids, function(i, n) {
if (Y.Lang.isString(n)) {
//Am I this or am I inside this
if (tar.test(n + ', ' + n + ' *')) {
r = false;
}
}
});
}
}
if (r) {
if (hTest) {
els = ev.currentTarget.all(hTest);
set = false;
els.each(function(n, i) {
if ((n.contains(tar) || n.compareTo(tar)) && !set) {
set = true;
this.set('activeHandle', n);
}
}, this);
} else {
this.set('activeHandle', this.get(NODE));
}
}
return r;
},
/**
* @private
* @method _setStartPosition
* @description Sets the current position of the Element and calculates the offset
* @param {Array} xy The XY coords to set the position to.
*/
_setStartPosition: function(xy) {
this.startXY = xy;
this.nodeXY = this.lastXY = this.realXY = this.get(NODE).getXY();
if (this.get('offsetNode')) {
this.deltaXY = [(this.startXY[0] - this.nodeXY[0]), (this.startXY[1] - this.nodeXY[1])];
} else {
this.deltaXY = [0, 0];
}
},
/**
* @private
* @method _timeoutCheck
* @description The method passed to setTimeout to determine if the clickTimeThreshold was met.
*/
_timeoutCheck: function() {
if (!this.get('lock') && !this._dragThreshMet && this._ev_md) {
this._fromTimeout = this._dragThreshMet = true;
this.start();
this._alignNode([this._ev_md.pageX, this._ev_md.pageY], true);
}
},
/**
* @method removeHandle
* @description Remove a Selector added by addHandle
* @param {String} str The selector for the handle to be removed.
* @return {Self}
* @chainable
*/
removeHandle: function(str) {
var key = str;
if (str instanceof Y.Node || str instanceof Y.NodeList) {
key = str._yuid;
}
if (this._handles[key]) {
delete this._handles[key];
this.fire(EV_REMOVE_HANDLE, { handle: str });
}
return this;
},
/**
* @method addHandle
* @description Add a handle to a drag element. Drag only initiates when a mousedown happens on this element.
* @param {String} str The selector to test for a valid handle. Must be a child of the element.
* @return {Self}
* @chainable
*/
addHandle: function(str) {
if (!this._handles) {
this._handles = {};
}
var key = str;
if (str instanceof Y.Node || str instanceof Y.NodeList) {
key = str._yuid;
}
this._handles[key] = str;
this.fire(EV_ADD_HANDLE, { handle: str });
return this;
},
/**
* @method removeInvalid
* @description Remove an invalid handle added by addInvalid
* @param {String} str The invalid handle to remove from the internal list.
* @return {Self}
* @chainable
*/
removeInvalid: function(str) {
if (this._invalids[str]) {
this._invalids[str] = null;
delete this._invalids[str];
this.fire(EV_REMOVE_INVALID, { handle: str });
}
return this;
},
/**
* @method addInvalid
* @description Add a selector string to test the handle against. If the test passes the drag operation will not continue.
* @param {String} str The selector to test against to determine if this is an invalid drag handle.
* @return {Self}
* @chainable
*/
addInvalid: function(str) {
if (Y.Lang.isString(str)) {
this._invalids[str] = true;
this.fire(EV_ADD_INVALID, { handle: str });
}
return this;
},
/**
* @private
* @method initializer
* @description Internal init handler
*/
initializer: function(cfg) {
this.get(NODE).dd = this;
if (!this.get(NODE).get('id')) {
var id = Y.stamp(this.get(NODE));
this.get(NODE).set('id', id);
}
this.actXY = [];
this._invalids = Y.clone(this._invalidsDefault, true);
this._createEvents();
if (!this.get(DRAG_NODE)) {
this.set(DRAG_NODE, this.get(NODE));
}
//Fix for #2528096
//Don't prep the DD instance until all plugins are loaded.
this.on('initializedChange', Y.bind(this._prep, this));
//Shouldn't have to do this..
this.set('groups', this.get('groups'));
},
/**
* @private
* @method _prep
* @description Attach event listners and add classname
*/
_prep: function() {
this._dragThreshMet = false;
var node = this.get(NODE);
node.addClass(DDM.CSS_PREFIX + '-draggable');
node.on(Drag.START_EVENT, Y.bind(this._handleMouseDownEvent, this));
node.on('mouseup', Y.bind(this._handleMouseUp, this));
node.on('dragstart', Y.bind(this._fixDragStart, this));
},
/**
* @private
* @method _unprep
* @description Detach event listeners and remove classname
*/
_unprep: function() {
var node = this.get(NODE);
node.removeClass(DDM.CSS_PREFIX + '-draggable');
node.detachAll('mouseup');
node.detachAll('dragstart');
node.detachAll(Drag.START_EVENT);
},
/**
* @method start
* @description Starts the drag operation
* @return {Self}
* @chainable
*/
start: function() {
if (!this.get('lock') && !this.get(DRAGGING)) {
var node = this.get(NODE), ow, oh, xy;
this._startTime = (new Date()).getTime();
DDM._start();
node.addClass(DDM.CSS_PREFIX + '-dragging');
this.fire(EV_START, {
pageX: this.nodeXY[0],
pageY: this.nodeXY[1],
startTime: this._startTime
});
node = this.get(DRAG_NODE);
xy = this.nodeXY;
ow = node.get(OFFSET_WIDTH);
oh = node.get(OFFSET_HEIGHT);
if (this.get('startCentered')) {
this._setStartPosition([xy[0] + (ow / 2), xy[1] + (oh / 2)]);
}
this.region = {
'0': xy[0],
'1': xy[1],
area: 0,
top: xy[1],
right: xy[0] + ow,
bottom: xy[1] + oh,
left: xy[0]
};
this.set(DRAGGING, true);
}
return this;
},
/**
* @method end
* @description Ends the drag operation
* @return {Self}
* @chainable
*/
end: function() {
this._endTime = (new Date()).getTime();
if (this._clickTimeout) {
this._clickTimeout.cancel();
}
this._dragThreshMet = this._fromTimeout = false;
if (!this.get('lock') && this.get(DRAGGING)) {
this.fire(EV_END, {
pageX: this.lastXY[0],
pageY: this.lastXY[1],
startTime: this._startTime,
endTime: this._endTime
});
}
this.get(NODE).removeClass(DDM.CSS_PREFIX + '-dragging');
this.set(DRAGGING, false);
this.deltaXY = [0, 0];
return this;
},
/**
* @private
* @method _defEndFn
* @description Handler for fixing the selection in IE
*/
_defEndFn: function(e) {
this._fixIEMouseUp();
this._ev_md = null;
},
/**
* @private
* @method _prevEndFn
* @description Handler for preventing the drag:end event. It will reset the node back to it's start position
*/
_prevEndFn: function(e) {
this._fixIEMouseUp();
//Bug #1852577
this.get(DRAG_NODE).setXY(this.nodeXY);
this._ev_md = null;
this.region = null;
},
/**
* @private
* @method _align
* @description Calculates the offsets and set's the XY that the element will move to.
* @param {Array} xy The xy coords to align with.
*/
_align: function(xy) {
this.fire(EV_ALIGN, {pageX: xy[0], pageY: xy[1] });
},
/**
* @private
* @method _defAlignFn
* @description Calculates the offsets and set's the XY that the element will move to.
* @param {EventFacade} e The drag:align event.
*/
_defAlignFn: function(e) {
this.actXY = [e.pageX - this.deltaXY[0], e.pageY - this.deltaXY[1]];
},
/**
* @private
* @method _alignNode
* @description This method performs the alignment before the element move.
* @param {Array} eXY The XY to move the element to, usually comes from the mousemove DOM event.
*/
_alignNode: function(eXY) {
this._align(eXY);
this._moveNode();
},
/**
* @private
* @method _moveNode
* @description This method performs the actual element move.
*/
_moveNode: function(scroll) {
//if (!this.get(DRAGGING)) {
// return;
//}
var diffXY = [], diffXY2 = [], startXY = this.nodeXY, xy = this.actXY;
diffXY[0] = (xy[0] - this.lastXY[0]);
diffXY[1] = (xy[1] - this.lastXY[1]);
diffXY2[0] = (xy[0] - this.nodeXY[0]);
diffXY2[1] = (xy[1] - this.nodeXY[1]);
this.region = {
'0': xy[0],
'1': xy[1],
area: 0,
top: xy[1],
right: xy[0] + this.get(DRAG_NODE).get(OFFSET_WIDTH),
bottom: xy[1] + this.get(DRAG_NODE).get(OFFSET_HEIGHT),
left: xy[0]
};
this.fire(EV_DRAG, {
pageX: xy[0],
pageY: xy[1],
scroll: scroll,
info: {
start: startXY,
xy: xy,
delta: diffXY,
offset: diffXY2
}
});
this.lastXY = xy;
},
/**
* @private
* @method _defDragFn
* @description Default function for drag:drag. Fired from _moveNode.
* @param {EventFacade} ev The drag:drag event
*/
_defDragFn: function(e) {
if (this.get('move')) {
if (e.scroll) {
e.scroll.node.set('scrollTop', e.scroll.top);
e.scroll.node.set('scrollLeft', e.scroll.left);
}
this.get(DRAG_NODE).setXY([e.pageX, e.pageY]);
this.realXY = [e.pageX, e.pageY];
}
},
/**
* @private
* @method _move
* @description Fired from DragDropMgr (DDM) on mousemove.
* @param {EventFacade} ev The mousemove DOM event
*/
_move: function(ev) {
if (this.get('lock')) {
return false;
} else {
this.mouseXY = [ev.pageX, ev.pageY];
if (!this._dragThreshMet) {
var diffX = Math.abs(this.startXY[0] - ev.pageX),
diffY = Math.abs(this.startXY[1] - ev.pageY);
if (diffX > this.get('clickPixelThresh') || diffY > this.get('clickPixelThresh')) {
this._dragThreshMet = true;
this.start();
this._alignNode([ev.pageX, ev.pageY]);
}
} else {
if (this._clickTimeout) {
this._clickTimeout.cancel();
}
this._alignNode([ev.pageX, ev.pageY]);
}
}
},
/**
* @method stopDrag
* @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
* @return {Self}
* @chainable
*/
stopDrag: function() {
if (this.get(DRAGGING)) {
DDM._end();
}
return this;
},
/**
* @private
* @method destructor
* @description Lifecycle destructor, unreg the drag from the DDM and remove listeners
*/
destructor: function() {
this._unprep();
if (this.target) {
this.target.destroy();
}
DDM._unregDrag(this);
}
});
Y.namespace('DD');
Y.DD.Drag = Drag;
}, '@VERSION@' ,{skinnable:false, requires:['dd-ddm-base']});