I ran into a problem where my dragged-item would be offset from the
cursor whenever I tried to drag an item from a fixed position Sortable
to a relative position one, by the same amount that the page is
scrolled. I came up with a solution that I thought I''d share.
I''m
also curious if there''s a better way to do this, as I''m pretty
new to
scriptaculous and prototype.
The problem I found is that the offset field in the Draggable isn''t
being reset after initialization, so the display problem crops up when
the element''s parent node is swapped in either Sortable.onHover or
onEmptyHover. The first half of my fix was adding a "resetDrag":
_checkParentFixedPosition: function(element) {
do {
if ( Element.getStyle(element, ''position'') ==
''fixed'' ) {
return true;
}
element = element.parentNode;
if(element.tagName==''BODY'') break;
} while (element);
return false;
},
// Reset the drag offset when the parent changes
resetDrag: function(oldParentNode, newParentNode) {
if ( this._checkParentFixedPosition(oldParentNode)
!this._checkParentFixedPosition(newParentNode) ) {
this.offset[0] -= document.body.scrollLeft;
this.offset[1] -= document.body.scrollTop;
}
}
The other half was adding:
var drags = Sortable.options(oldParentNode).draggables;
for ( var i = 0 ; i < drags.length ; i++ ) {
if ( drags[i].element.id == element.id ) {
drags[i].resetDrag(oldParentNode,
dropon.parentNode);
}
}
To the "oldParentNode != dropon.parentNode" tests in onHover, and a
similar check to onEmptyHover.
Does this seem like a good way to fix this?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---