ddm-base.js revision 7ff273fc586a72254d17af146b2a6a32cc39e76b
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Provides the base Drag Drop Manger required for making a Node draggable.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @module dd
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @submodule dd-ddm-base
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * Provides the base Drag Drop Manger required for making a Node draggable.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @class DDM
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @extends Base
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @constructor
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @namespace DD
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng var DDMBase = function() {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng DDMBase.superclass.constructor.apply(this, arguments);
0591ddd0694c4d7ab3ad339419da215a732587f8Prakash Jalan * @attribute dragCursor
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description The cursor to apply when dragging, if shimmed the shim will get the cursor.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type String
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @attribute clickPixelThresh
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description The number of pixels to move to start a drag operation, default is 3.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type Number
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @attribute clickTimeThresh
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type Number
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @attribute dragMode
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description This attribute only works if the dd-drop module is active. It will set the dragMode (point, intersect, strict) of all future Drag instances.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type String
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _setDragMode
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Handler for dragMode attribute setter.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param String/Number The Number value or the String for the DragMode to default all future drag instances to.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @return Number The Mode to be set
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai if (mode === null) {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case 'intersect':
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai case 'strict':
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng case 'point':
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @property CSS_PREFIX
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description The PREFIX to attach to all DD CSS class names
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type {String}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _activateTargets: function() {},
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @property _drags
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Holder for all registered drag elements.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type {Array}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @property activeDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description A reference to the currently active draggable object.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @type {Drag}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _regDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Drag} d The Drag object
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _regDrag: function(d) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _unregDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Remove this drag object from the DDM._drags array.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Drag} d The drag object.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _unregDrag: function(d) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (n !== d) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _init
ee94b1c37a34b758315666dcd0bc7c46d1aea15cSebastien Roy * @description DDM's init method
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _start
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Internal method used by Drag to signal the start of a drag operation
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} x The x position of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} y The y position of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} w The width of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} h The height of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _start: function(x, y, w, h) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _startDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Factory method to be overwritten by other DDM's
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} x The x position of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} y The y position of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} w The width of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Number} h The height of the drag element
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _startDrag: function() {},
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _endDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Factory method to be overwritten by other DDM's
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _endDrag: function() {},
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _dropMove: function() {},
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method _end
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Internal method used by Drag to signal the end of a drag operation
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng _end: function() {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng //@TODO - Here we can get a (click - drag - click - release) interaction instead of a (mousedown - drag - mouseup - release) interaction
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng //Add as a config option??
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method stopDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @return {Self}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @chainable
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng stopDrag: function() {
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * @method _move
4eaa471005973e11a6110b69fe990530b3b95a38Rishi Srivatsavai * @description Internal listener for the mousemove DOM event to pass to the Drag's move method.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {Event.Facade} ev The Dom mousemove Event
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng this.activeDrag._move.apply(this.activeDrag, arguments);
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * //TODO Private, rename??...
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method cssSizestoObject
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Helper method to use to set the gutter from the attribute setter.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {String} gutter CSS style string for gutter: '5 0' (sets top and bottom to 5px, left and right to 0px), '1 2 3 4' (top 1px, right 2px, bottom 3px, left 4px)
1eee170a5f6cf875d905524fea524c7c5c870aa0Erik Nordmark * @return {Object} The gutter Object Literal.
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng switch (x.length) {
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @method getDrag
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @description Get a valid Drag instance back from a Node or a selector string, false otherwise
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @param {String/Object} node The Node instance or Selector string to check for a valid Drag Object
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * @return {Object}
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng var drag = false,
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng if (n instanceof Y.Node) {