Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlync/873963 to your computer and use it in GitHub Desktop.
Save tlync/873963 to your computer and use it in GitHub Desktop.
dojo.declare('dojo.dnd.move.parentConstrainedGridMoveable', dojo.dnd.move.parentConstrainedMoveable, {
gridSize: 10,
/*
* @param {HTMLElement} node
* @param {int} params.gridSize
*/
constructor: function(node, params){
if(!params) params = {};
this.gridSize = params && params.gridSize;
},
onMove: function(mover, leftTop){
var c = this.constraintBox;
var s = mover.node.style;
var gridSize = this.gridSize;
var left = (leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l);
var top = (leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t);
s.left = left - left % gridSize + 'px';
s.top = top - top % gridSize + 'px';
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment