Search code examples
mootoolssortables

Mootools sortables, disable events on the sortable elements when dragging and dropping


http://jsfiddle.net/4byth/

var mySortables = new Sortables('#sortable',
{
    clone:true,
    revert:true,
    opacity:1

});

I am using sortables to allow users to rearrange slides by dragging a span containing the thumbnail of the slide to a new position. These elements are inline.

There is an A tag surrounding the image which when clicked lets the user edit that slide.

In some cases the link is activated when you release the sortable element, I haven't quite been able to work out when this happens.

My question is, is it possible to disable the link until the drop is complete and then renable it, or should I just use a different approach to displaying them and perhaps add onclick events to the span elements which I can remove/readd more easily.

Thanks


Solution

  • You can use the start,complete events to set a flag and only if this flag is false when clicking on the anchor - enable the editing.

    var is_dragging;
    var mySortables = new Sortables('#sortable',
    {
        clone:true,
        revert:true,
        opacity:1,
        onStart: function(){
    
          is_dragging = true; 
        },
    
        onComplete: function(){
            is_dragging = false;   
        }
    
    });
        function onClickAnchor(){
           if(!is_dragging){
             //do stuff
           }
        }