dd-constrain.js revision b19f7c87923d53715816c31f48cd234f688ce3d6
4874N/A * 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.
4874N/A * Plugin for the dd-drag module to add the constraining methods to it. It supports constraining to a node or viewport. It supports tick based moves and XY axis constraints.
4874N/A this._lazyAddAttrs = false;
4874N/A * @description The Constrained instance will be placed on the Drag instance under the con namespace.
* @description The X tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
tickX: {
value: false
* @description The Y tick offset the drag node should snap to on each drag move. False for no ticks. Default: false
tickY: {
value: false
tickXArray: {
value: false
tickYArray: {
value: false
* @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)
gutter: {
* '{Region Object}': An Object Literal containing a valid region (top, right, bottom, left) of page positions
constrain: {
if (node) {
return con;
* @description An Object Literal containing a valid region (top, right, bottom, left) of page positions to constrain the drag node to.
setter: function(r) {
setter: function(n) {
setter: function(n) {
cacheRegion: {
value: true
proto = {
_lastTickXFired: null,
_lastTickYFired: null,
initializer: function() {
this._createEvents();
destructor: function() {
if (this._cacheHandle) {
this._cacheHandle = null;
* @description This method creates all the events for this Event Target and publishes them so we get Event Bubbling.
_createEvents: function() {
var instance = this;
var ev = [
this.publish(v, {
type: v,
emitFacade: true,
bubbles: true,
queuable: false,
_handleEnd: function() {
this._lastTickYFired = null;
this._lastTickXFired = null;
_handleStart: function() {
this.resetCache();
_regionCache: null,
_cacheHandle: null,
_cacheRegion: function() {
resetCache: function() {
this._regionCache = null;
_getConstraint: function() {
if (con) {
if (!this._regionCache) {
this._cacheRegion();
this.resetCache();
Y.each(g, function(i, n) {
region[n] -= i;
region[n] += i;
return region;
r = this._getConstraint();
if (inc) {
* @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;
* @description Modifies the Drag.actXY method from the after drag:align event. This is where the constraining happens.
align: function() {
r = this.getRegion(true);
this._tickAlignX();
this._tickAlignY();
return xy;
_tickAlignX: function() {
_tickAlignY: function() {
return pos;
return pos;
if (ticks[i]) {
return ret;