8

I am working with the jQuery UI Sortable plugin and everything works as expected accept for one issue. After I am done dragging an item to reorder the list (a list of <A> tags) the click event fires after the drop is done.

Anyone run into this issue before? If so, how did you go about fixing it?

5
  • Can you build test case reproducing your problem in jsfiddle ? Commented Feb 28, 2012 at 19:33
  • Are you sure it's the click event? There are a few other events that fire after a drop is done (the most common might be the "change" event). Might be able to supply a better answer if you show us your code. Commented Feb 28, 2012 at 19:35
  • Perhaps this will help as it seems like this is what you are running into: stackoverflow.com/a/1771635/37140 Commented Feb 28, 2012 at 19:38
  • Here is a jsFiddle - jsfiddle.net/dennismonsewicz/5VgSq Commented Feb 28, 2012 at 20:28
  • I am also working with iviewer which might be causing the issue... @ChrisMitchell - I tried your suggestion, but no luck :( Commented Feb 28, 2012 at 20:29

3 Answers 3

10

Ok... I figured it out..

Here is my solution:

$(thumbOpts.container).sortable({
        items: '.page',
        revert: true,
        opacity: 0.5,
        start: function(evt, ui) {
            var link = ui.item.find('a');
            link.data('click-event', link.attr('onclick'));
            link.attr('onclick', '');
        },
        stop: function(evt, ui) {
            setTimeout(
                function(){
                    var link = ui.item.find('a');
                    link.attr('onclick', link.data('click-event'));
                },
                    200
            )
        }
    });
Sign up to request clarification or add additional context in comments.

2 Comments

Ok +1, but don't you think a cleaner solutions should exist?
is there event when sorting is in progress? Something like draggable (when dragging)?
2

Just add option for sortable:

helper : 'clone'

It will prevent click event for source element and don't change anyhow UX.

See doc for "helper".

Comments

0
$(thumbOpts.container).sortable({
        items: '.page',
        revert: true,
        opacity: 0.5,
        start: function(evt, ui) {
            ui.item.find('a').one('click', function(){return false;});
        },
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.