Hey Ken,
Thank you for your Idea! But I deside to Implement it on a nother way!
I just use the onEnd Event now to check if the activeDraggable is
overlapping with another Draggable. If so i just set the revert of the
Active one to true:
new Draggable(mComponent,{
snap: function(x,y,draggable) {
function constrain(n, lower, upper) {
if (n > upper) return upper;
else if (n < lower) return lower;
else return n;
}
x = (x/9).round()*9;
y = (y/25).round()*26;
element_dimensions = Element.getDimensions(
draggable.element);
parent_dimensions = Element.getDimensions(
draggable.element.parentNode);
return[
constrain(x, 0, parent_dimensions.width -
element_dimensions.width),
constrain(y, 0, parent_dimensions.height -
element_dimensions.height)];
},
revert: true,
onEnd: function(element, dropon, event) {
function isOverlapping(element1, element2) {
e1XY = { top: Element.cumulativeOffset
(element1)["top"],
bottom: Element.cumulativeOffset
(element1)["top"]+Element.getDimensions(element1)["height"],
left: Element.cumulativeOffset
(element1)["left"],
right: Element.cumulativeOffset
(element1)["left"]+Element.getDimensions(element1)["width"]
};
e2XY = { top: Element.cumulativeOffset
(element2)["top"],
bottom: Element.cumulativeOffset
(element2)["top"]+Element.getDimensions(element2)["height"],
left: Element.cumulativeOffset
(element2)["left"],
right: Element.cumulativeOffset
(element2)["left"]+Element.getDimensions(element2)["width"]
};
if(
(e2XY["top"]<=e1XY["top"]
&&
e1XY["top"]<=e2XY["bottom"] ||
e2XY["top"]<=e1XY["bottom"] &&
e1XY["bottom"]<=e2XY["bottom"]) &&
(e2XY["left"]<=e1XY["left"]
&&
e1XY["left"]<=e2XY["right"] ||
e2XY["left"]<=e1XY["right"] &&
e1XY["right"]<=e2XY["right"]) ||
(e1XY["top"]<=e2XY["top"]
&&
e2XY["top"]<=e1XY["bottom"] ||
e1XY["top"]<=e2XY["bottom"] &&
e2XY["bottom"]<=e1XY["bottom"]) &&
(e1XY["left"]<=e2XY["left"]
&&
e2XY["left"]<=e1XY["right"] ||
e1XY["left"]<=e2XY["right"] &&
e2XY["right"]<=e1XY["right"])
) return true;
return false;
}
function Overlaps(){
var overlapping = false
Draggables.drags.each(function(dragItem){
if(Draggables.activeDraggable != dragItem ){
if(isOverlapping(
Draggables.activeDraggable.element, dragItem.element)){
overlapping = true;
}
}
});
return overlapping;
}
Draggables.activeDraggable.options.revert = Overlaps();
}
});
2007/11/19, Ken Snyder
<kendsnyder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:>
>
> madOn wrote:
> > Hey Guy,
> > I need to implement a Area (Dropable Zone) that contains a dynamic
> > number of Dragables... Easy with Script.actulo.us But: I also want
> > that the dragables can''t get dragged over other Dragables in
the Area.
> > I think this may be possible with the Snap function?! Do any of you
> > Guys have an Idea or allready implemented something like that? It
> > would be nice if you would help me!
> >
> > Thanks!
> Yes, you should be able to do it with a snap function. You would need
> to test if the mouse x y was within the area of any other draggables by
> looping over all the other draggables with Position.within()
> http://prototypejs.org/api/position/within
>
> I''m interested to see the final result
>
> - Ken Snyder
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---