/usr/share/javascript/yui3/dd-ddm-base/dd-ddm-base.js is in libjs-yui3-full 3.5.1-1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | /*
YUI 3.5.1 (build 22)
Copyright 2012 Yahoo! Inc. All rights reserved.
Licensed under the BSD License.
http://yuilibrary.com/license/
*/
YUI.add('dd-ddm-base', function(Y) {
/**
* 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() {
DDMBase.superclass.constructor.apply(this, arguments);
};
DDMBase.NAME = 'ddm';
DDMBase.ATTRS = {
/**
* @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
*/
clickPixelThresh: {
value: 3
},
/**
* @attribute clickTimeThresh
* @description The number of milliseconds a mousedown has to pass to start a drag operation, default is 1000.
* @type Number
*/
clickTimeThresh: {
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',
setter: function(mode) {
this._setDragMode(mode);
return mode;
}
}
};
Y.extend(DDMBase, Y.Base, {
_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) {
mode = Y.DD.DDM.get('dragMode');
}
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}
*/
CSS_PREFIX: Y.ClassNameManager.getClassName('dd'),
_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) {
if (this.getDrag(d.get('node'))) {
return false;
}
if (!this._active) {
this._setupListeners();
}
this._drags.push(d);
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 = [];
Y.each(this._drags, function(n, i) {
if (n !== d) {
tmp[tmp.length] = n;
}
});
this._drags = tmp;
},
/**
* @private
* @method _setupListeners
* @description Add the document listeners.
*/
_setupListeners: function() {
this._createPG();
this._active = true;
var doc = Y.one(Y.config.doc);
doc.on('mousemove', Y.throttle(Y.bind(this._move, this), this.get('throttleTime')));
doc.on('mouseup', Y.bind(this._end, this));
},
/**
* @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.end.call(this.activeDrag);
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
*/
_move: function(ev) {
if (this.activeDrag) {
this.activeDrag._move.call(this.activeDrag, ev);
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) {
var x = gutter.split(' ');
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 {
top : parseInt(x[0],10),
right : parseInt(x[1],10),
bottom: parseInt(x[2],10),
left : parseInt(x[3],10)
};
},
/**
* @method getDrag
* @description Get a valid Drag instance back from a Node or a selector string, false otherwise
* @param {String/Object} node The Node instance or Selector string to check for a valid Drag Object
* @return {Object}
*/
getDrag: function(node) {
var drag = false,
n = Y.one(node);
if (n instanceof Y.Node) {
Y.each(this._drags, function(v, k) {
if (n.compareTo(v.get('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}
*/
swapPosition: function(n1, n2) {
n1 = Y.DD.DDM.getNode(n1);
n2 = Y.DD.DDM.getNode(n2);
var xy1 = n1.getXY(),
xy2 = n2.getXY();
n1.setXY(xy2);
n2.setXY(xy1);
return n1;
},
/**
* @method getNode
* @description Return a node instance from the given node, selector string or Y.Base extended object.
* @param {Node/Object/String} n The node to resolve.
* @return {Node}
*/
getNode: function(n) {
if (n instanceof Y.Node) {
return n;
}
if (n && n.get) {
if (Y.Widget && (n instanceof Y.Widget)) {
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}
*/
swapNode: function(n1, n2) {
n1 = Y.DD.DDM.getNode(n1);
n2 = Y.DD.DDM.getNode(n2);
var p = n2.get('parentNode'),
s = n2.get('nextSibling');
if (s == n1) {
p.insertBefore(n1, n2);
} else if (n2 == n1.get('nextSibling')) {
p.insertBefore(n2, n1);
} else {
n1.get('parentNode').replaceChild(n2, n1);
p.insertBefore(n1, s);
}
return n1;
}
});
Y.namespace('DD');
Y.DD.DDM = new DDMBase();
/**
* @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}
*/
}, '3.5.1' ,{skinnable:false, requires:['node', 'base', 'yui-throttle', 'classnamemanager']});
|