sven.hecht-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org
2007-Jan-11 11:17 UTC
Rectangle Constraint for dragdrop.js (Script.aculo.us )
use like this:
var dragable = new Draggable($(''dragme''), {constraintrect:
[100,40,
500, 500]});
now "dragme" can only be moved between 100 and 500 px realtive to his
parent in each direction.
extended draw-function:
draw: function(point) {
var pos = Position.cumulativeOffset(this.element);
if(this.options.ghosting) {
var r = Position.realOffset(this.element);
pos[0] += r[0] - Position.deltaX; pos[1] += r[1] -
Position.deltaY;
}
var d = this.currentDelta();
pos[0] -= d[0]; pos[1] -= d[1];
if(this.options.scroll && (this.options.scroll != window &&
this._isScrollChild)) {
pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
}
var p = [0,1].map(function(i){
return (point[i]-pos[i]-this.offset[i])
}.bind(this));
if(this.options.snap) {
if(typeof this.options.snap == ''function'') {
p = this.options.snap(p[0],p[1],this);
} else {
if(this.options.snap instanceof Array) {
p = p.map( function(v, i) {
return
Math.round(v/this.options.snap[i])*this.options.snap[i] }.bind(this))
} else {
p = p.map( function(v) {
return Math.round(v/this.options.snap)*this.options.snap
}.bind(this))
}
}}
var doHorizontal = true, doVertical = true;
doHorizontal = (!this.options.constraint) ||
(this.options.constraint==''horizontal'');
doVertical = (!this.options.constraint) ||
(this.options.constraint==''vertical'');
var xMin, yMin, xMax, yMax;
if(this.options.constraintrect) {
xMin = this.options.constraintrect[0];
yMin = this.options.constraintrect[1];
xMax = this.options.constraintrect[2];
yMax = this.options.constraintrect[3];
}
if (xMin != null && this.options.constraintrect && p[0] -
xMin < 0)
{
p[0] = xMin;
}
if (yMin != null && this.options.constraintrect && p[1] -
yMin < 0)
{
p[1] = yMin;
}
if (xMax != null && this.options.constraintrect && p[0] -
xMax > 0)
{
p[0] = xMax;
}
if (yMax != null && this.options.constraintrect && p[1] -
yMax > 0)
{
p[1] = yMax;
}
var style = this.element.style;
if(doHorizontal) {
style.left = p[0] + "px";
}
if(doVertical) {
style.top = p[1] + "px";
}
if(style.visibility=="hidden") style.visibility = ""; //
fix gecko
rendering
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---