2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('dd-ddm-base', function(Y) {
10
* Provides the base Drag Drop Manger required for making a Node draggable.
12
* @submodule dd-ddm-base
15
* Provides the base Drag Drop Manger required for making a Node draggable.
21
var DDMBase = function() {
23
DDMBase.superclass.constructor.apply(this, arguments);
26
DDMBase.NAME = 'DragDropMgr';
30
* @attribute clickPixelThresh
31
* @description The number of pixels to move to start a drag operation, default is 3.
38
* @attribute clickTimeThresh
39
* @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
47
* @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.
53
this._setDragMode(mode);
59
Y.extend(DDMBase, Y.Base, {
62
* @method _setDragMode
63
* @description Handler for dragMode attribute setter.
64
* @param String/Number The Number value or the String for the DragMode to default all future drag instances to.
65
* @return Number The Mode to be set
67
_setDragMode: function(mode) {
69
mode = Y.DD.DDM.get('dragMode');
85
* @property CSS_PREFIX
86
* @description The PREFIX to attach to all DD CSS class names
90
_activateTargets: function() {},
94
* @description Holder for all registered drag elements.
99
* @property activeDrag
100
* @description A reference to the currently active draggable object.
107
* @description Adds a reference to the drag object to the DDM._drags array, called in the constructor of Drag.
108
* @param {Drag} d The Drag object
110
_regDrag: function(d) {
111
this._drags[this._drags.length] = d;
116
* @description Remove this drag object from the DDM._drags array.
117
* @param {Drag} d The drag object.
119
_unregDrag: function(d) {
121
Y.each(this._drags, function(n, i) {
131
* @description DDM's init method
133
initializer: function() {
134
Y.Node.get('document').on('mousemove', this._move, this, true);
135
Y.Node.get('document').on('mouseup', this._end, this, true);
136
//Y.Event.Target.apply(this);
141
* @description Internal method used by Drag to signal the start of a drag operation
142
* @param {Number} x The x position of the drag element
143
* @param {Number} y The y position of the drag element
144
* @param {Number} w The width of the drag element
145
* @param {Number} h The height of the drag element
147
_start: function(x, y, w, h) {
148
this._startDrag.apply(this, arguments);
153
* @description Factory method to be overwritten by other DDM's
154
* @param {Number} x The x position of the drag element
155
* @param {Number} y The y position of the drag element
156
* @param {Number} w The width of the drag element
157
* @param {Number} h The height of the drag element
159
_startDrag: function() {},
163
* @description Factory method to be overwritten by other DDM's
165
_endDrag: function() {},
166
_dropMove: function() {},
170
* @description Internal method used by Drag to signal the end of a drag operation
173
//@TODO - Here we can get a (click - drag - click - release) interaction instead of a (mousedown - drag - mouseup - release) interaction
174
//Add as a config option??
175
if (this.activeDrag) {
177
this.activeDrag.end.call(this.activeDrag);
178
this.activeDrag = null;
183
* @description Method will forcefully stop a drag operation. For example calling this from inside an ESC keypress handler will stop this drag.
187
stopDrag: function() {
188
if (this.activeDrag) {
196
* @description Internal listener for the mousemove DOM event to pass to the Drag's move method.
197
* @param {Event} ev The Dom mousemove Event
199
_move: function(ev) {
200
if (this.activeDrag) {
201
this.activeDrag._move.apply(this.activeDrag, arguments);
207
* @description A simple method to set the top and left position from offsets instead of page coordinates
208
* @param {Object} node The node to set the position of
209
* @param {Array} xy The Array of left/top position to be set.
211
setXY: function(node, xy) {
212
var t = parseInt(node.getStyle('top'), 10),
213
l = parseInt(node.getStyle('left'), 10),
214
pos = node.getStyle('position');
216
if (pos === 'static') {
217
node.setStyle('position', 'relative');
221
if (isNaN(t)) { t = 0; }
222
if (isNaN(l)) { l = 0; }
224
node.setStyle('top', (xy[1] + t) + 'px');
225
node.setStyle('left', (xy[0] + l) + 'px');
229
* //TODO Private, rename??...
231
* @method cssSizestoObject
232
* @description Helper method to use to set the gutter from the attribute setter.
233
* @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)
234
* @return {Object} The gutter Object Literal.
236
cssSizestoObject: function(gutter) {
237
var p = gutter.split(' '),
245
g.top = parseInt(p[0], 10);
247
g.right = parseInt(p[1], 10);
252
g.bottom = parseInt(p[2], 10);
257
g.left = parseInt(p[3], 10);
268
* @description Get a valid Drag instance back from a Node or a selector string, false otherwise
269
* @param {String/Object} node The Node instance or Selector string to check for a valid Drag Object
272
getDrag: function(node) {
274
n = Y.Node.get(node);
275
if (n instanceof Y.Node) {
276
Y.each(this._drags, function(v, k) {
277
if (n.compareTo(v.get('node'))) {
287
Y.DD.DDM = new DDMBase();
291
}, '3.0.0pr1' ,{requires:['node', 'base'], skinnable:false});