Search code examples
javascripteventsevent-handlingdrag-and-dropscriptaculous

Preventing JavaScript click event with Scriptaculous drag and drop


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?


Solution

  • I solved this by using something like the following:

    new Draggable('id', {
        onStart: function() {
            dPhoto = $('id');
            Event.stopObserving('id', 'click');
        },
        onEnd : function() {
            setTimeout("Event.observe('id', 'click', function() { location.href = 'url'; });", 500);
        },
        revert: true
    });