constrain.js revision bef5bd55cae040389070d8db272d07e4d896997c
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * The Drag & Drop Utility allows you to create a draggable interface efficiently, buffering you from browser-level abnormalities and enabling you to focus on the interesting logic surrounding your particular implementation. This component enables you to create a variety of standard draggable objects with just a few lines of code and then, using its extensive API, add your own specific implementation logic.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @module dd
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @submodule dd-constrain
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * This class extends the dd-drag module to add the constraining methods to it. It supports constraining to a region, node or viewport. It also
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * supports tick based moves and XY axis constraints.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @class DragConstrained
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @extends Drag
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @constructor
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass var C = function() {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @attribute stickX
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description Stick the drag movement to the X-Axis. Default: false
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Boolean
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @attribute stickY
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Stick the drag movement to the Y-Axis
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Boolean
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @attribute tickX
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description The X tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @attribute tickY
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description The Y tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @attribute tickXArray
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description An array of page coordinates to use as X ticks for drag movement.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Array
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @attribute tickYArray
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description An array of page coordinates to use as Y ticks for drag movement.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Array
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @attribute constrain2region
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description An Object Literal containing a valid region (top, right, bottom, left) of page positions to constrain the drag node to.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Object
0523d0a8daaa474f0214203f8cbb0bc4a88e2964Dav Glass getter: function(r) {
216633e2ad28e9568a902f3763c3bef052c5f908Dav Glass return false;
5432371fbb6d790a76159481f0dd16e806812153Dav Glass setter: function (r) {
5432371fbb6d790a76159481f0dd16e806812153Dav Glass if (Y.Lang.isNumber(r.top) && Y.Lang.isNumber(r.right) && Y.Lang.isNumber(r.left) && Y.Lang.isNumber(r.bottom)) {
5432371fbb6d790a76159481f0dd16e806812153Dav Glass return false;
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass } else if (r !== false) {
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass return false;
5432371fbb6d790a76159481f0dd16e806812153Dav Glass * @attribute gutter
5432371fbb6d790a76159481f0dd16e806812153Dav Glass * @description CSS style string for the gutter of a region (supports negative values): '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)
5432371fbb6d790a76159481f0dd16e806812153Dav Glass * @type String
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @attribute constrain2node
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @description Will attempt to constrain the drag node to the bounderies of this node.
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @type Object
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass setter: function(n) {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass } else if (this.get('constrain2region') !== false) {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass return false;
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @attribute constrain2view
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description Will attempt to constrain the drag node to the bounderies of the viewport region.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Object
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass start: function() {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @property _regionCache
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Store a cache of the region that we are constraining to
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Object
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _cacheRegion
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Get's the region and caches it, called from window.resize and when the cache is null
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass this._regionCache = this.get('constrain2node').get('region');
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method getRegion
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Get the active region: viewport, node, custom region
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @param {Boolean} inc Include the node's height and width
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @return {Object}
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass Y.on('resize', this._cacheRegion, this, true, window);
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass return false;
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass Y.each(g, function(i, n) {
* @param {Array} _xy The XY to check if it's in the current region, if it isn't inside the region, it will reset the xy array to be inside the region.
r = this.getRegion(),
return _xy;
inside = false;
inside = true;
return inside;
r = this.getRegion(true);
return _xy;
return pos;
return pos;
if (ticks[i]) {
return ret;
return xy;