I have some elements on a page which are draggable. These same elements have a click event which navigates to another page. I'm trying to determine the best way of preventing the click event from firing if the user is dragging but still allow the click event if not dragging. Anyone have any ideas of the best way to accomplish this?
4 Answers
1
votes
1
votes
0
votes
0
votes
You can also do this another way. On your startDrag you stop observing the object. Then you observe the click again which leads to an enddrag function which recreates the first eventhandler.
function onDragStart() {
Event.stopObserving(this.OBJECT,'click');
Event.observe(this.OBJECT,'click',this.onDragEnd.bindAsEventListener(this));
}
function onDragEnd() {
Event.stopObserving(this.OBJECT,'click');
Event.observe(this.OBJECT,'click',this.PREVIOUSFUNCTION.bindAsEventListener(this));
}
This will catch the leftover click event which is still active after the enddrag to just recreate the original handler. I hope this helps somebody out there :)