dd-ddm-base-debug.js revision 489504a37b99aa0273fca2d41ae36da3356233cf
/**
* Provides the base Drag Drop Manger required for making a Node draggable.
* @module dd
* @submodule dd-ddm-base
*/
/**
* Provides the base Drag Drop Manger required for making a Node draggable.
* @class DDM
* @extends Base
* @constructor
* @namespace DD
*/
var DDMBase = function() {
};
/**
* @attribute dragCursor
* @description The cursor to apply when dragging, if shimmed the shim will get the cursor.
* @type String
*/
dragCursor: {
value: 'move'
},
/**
* @attribute clickPixelThresh
* @description The number of pixels to move to start a drag operation, default is 3.
* @type Number
*/
value: 3
},
/**
* @attribute clickTimeThresh
* @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
* @type Number
*/
value: 1000
},
/**
* @attribute throttleTime
* @description The number of milliseconds to throttle the mousemove event. Default: 150
* @type Number
*/
throttleTime: {
//value: 150
value: -1
},
/**
* @attribute dragMode
* @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.
* @type String
*/
dragMode: {
value: 'point',
this._setDragMode(mode);
return mode;
}
}
};
_createPG: function() {},
/**
* @property _active
* @description flag set when we activate our first drag, so DDM can start listening for events.
* @type {Boolean}
*/
_active: null,
/**
* @private
* @method _setDragMode
* @description Handler for dragMode attribute setter.
* @param String/Number The Number value or the String for the DragMode to default all future drag instances to.
* @return Number The Mode to be set
*/
_setDragMode: function(mode) {
if (mode === null) {
}
switch (mode) {
case 1:
case 'intersect':
return 1;
case 2:
case 'strict':
return 2;
case 0:
case 'point':
return 0;
}
return 0;
},
/**
* @property CSS_PREFIX
* @description The PREFIX to attach to all DD CSS class names
* @type {String}
*/
_activateTargets: function() {},
/**
* @private
* @property _drags
* @description Holder for all registered drag elements.
* @type {Array}
*/
_drags: [],
/**
* @property activeDrag
* @description A reference to the currently active draggable object.
* @type {Drag}
*/
activeDrag: false,
/**
* @private
* @method _regDrag
* @description Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
* @param {Drag} d The Drag object
*/
_regDrag: function(d) {
return false;
}
if (!this._active) {
this._setupListeners();
}
return true;
},
/**
* @private
* @method _unregDrag
* @description Remove this drag object from the DDM._drags array.
* @param {Drag} d The drag object.
*/
_unregDrag: function(d) {
var tmp = [];
if (n !== d) {
}
});
},
/**
* @private
* @method _setupListeners
* @description Add the document listeners.
*/
_setupListeners: function() {
this._createPG();
this._active = true;
},
/**
* @private
* @method _start
* @description Internal method used by Drag to signal the start of a drag operation
*/
_start: function() {
this.fire('ddm:start');
this._startDrag();
},
/**
* @private
* @method _startDrag
* @description Factory method to be overwritten by other DDM's
* @param {Number} x The x position of the drag element
* @param {Number} y The y position of the drag element
* @param {Number} w The width of the drag element
* @param {Number} h The height of the drag element
*/
_startDrag: function() {},
/**
* @private
* @method _endDrag
* @description Factory method to be overwritten by other DDM's
*/
_endDrag: function() {},
_dropMove: function() {},
/**
* @private
* @method _end
* @description Internal method used by Drag to signal the end of a drag operation
*/
_end: function() {
if (this.activeDrag) {
this._endDrag();
this.fire('ddm:end');
this.activeDrag = null;
}
},
/**
* @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.activeDrag) {
this._end();
}
return this;
},
/**
* @private
* @method _move
* @description Internal listener for the mousemove DOM event to pass to the Drag's move method.
* @param {Event.Facade} ev The Dom mousemove Event
*/
if (this.activeDrag) {
this._dropMove();
}
},
/**
* //TODO Private, rename??...
* @private
* @method cssSizestoObject
* @description Helper method to use to set the gutter from the attribute setter.
* @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)
* @return {Object} The gutter Object Literal.
*/
cssSizestoObject: function(gutter) {
switch (x.length) {
case 1: x[1] = x[2] = x[3] = x[0]; break;
case 2: x[2] = x[0]; x[3] = x[1]; break;
case 3: x[3] = x[1]; break;
}
return {
};
},
/**
* @method getDrag
* @description Get a valid Drag instance back from a Node or a selector string, false otherwise
* @return {Object}
*/
var drag = false,
if (n instanceof Y.Node) {
drag = v;
}
});
}
return drag;
},
/**
* @method swapPosition
* @description Swap the position of 2 nodes based on their CSS positioning.
* @param {Node} n1 The first node to swap
* @param {Node} n2 The first node to swap
* @return {Node}
*/
return n1;
},
/**
* @method getNode
* @description Return a node instance from the given node, selector string or Y.Base extended object.
* @return {Node}
*/
getNode: function(n) {
if (n && n.get) {
n = n.get('boundingBox');
} else {
n = n.get('node');
}
} else {
n = Y.one(n);
}
return n;
},
/**
* @method swapNode
* @description Swap the position of 2 nodes based on their DOM location.
* @param {Node} n1 The first node to swap
* @param {Node} n2 The first node to swap
* @return {Node}
*/
if (s == n1) {
} else {
p.insertBefore(n1, s);
}
return n1;
}
});
Y.namespace('DD');
/**
* @event ddm:start
* @description Fires from the DDM before all drag events fire.
* @type {CustomEvent}
*/
/**
* @event ddm:end
* @description Fires from the DDM after the DDM finishes, before the drag end events.
* @type {CustomEvent}
*/