Heya,
Following an idea from Saimon (http://dev.rubyonrails.org/ticket/
2826) and
Borlum (http://dev.rubyonrails.org/ticket/2583) and possibly others,
script.aculo.us Draggables now sport a new "snap" option that works
like this:
snap:25
snap to a 25x25 grid (0,0 is at the elements 0,0 coordinate)
snap:[10,25]
same as above but with different x/y grid size
snap:function(x,y) { return [x,y] }
do-it-yourself grid implementation
The latter can also be used for stuff like constraints, for example:
snap: function(x,y) {
return[
x<100 ? (x > 0 ? x : 0 ) : 100,
y<50 ? (y > 0 ? y : 0) : 50];
}
will constraint the dragging of the element to a 100 by 50 box
(not calculating in the element''s width or height).
With some more tinkering you can implement some pretty advanced
stuff, like basing the snapping/constraint on the current position of
other elements.
Hope you find that useful! Comments are welcome!
Cheers
Thomas