Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I can disable, but can't enable a droppable function?

I need only 1 block in one drop-area and switch if needed. Why I can disable, but can't enable a droppable function?

  • $(this).droppable("option", "disabled", false); - doesn't work
  • $(this).droppable("enable"); - doesn't work
  • Enable a droppable after it has being disable - doesn't work

Here is my code:

$('.my_block').draggable({
    revert: "invalid",        
});

$('.free').droppable({         
    accept: ".my_block",
    drop: function(ev, ui) {             
        $(this).removeClass("free");    
        $(this).addClass("1");                
        ui.draggable.appendTo($(this)).removeAttr('style');
            $(this).droppable("disable");              
        },
        out:  function(ev, ui) {                     
            $(this).droppable("enable");    
            $(this).removeClass("1");    
            $(this).addClass("free");            
        },        
    });

jsfiddle http://jsfiddle.net/4ABCN/2/

And how can I back all red blocks to main positions by one button?

like image 490
Jack Bo Avatar asked Nov 03 '22 12:11

Jack Bo


1 Answers

Working demo Deleted old demo

New Demo Try this: http://jsfiddle.net/7EbKS/

Behaviour: Now when user moves the red box you are allowed to drop another one in empty position,

Hope it fits the cause :)

Code

  $(function() {
    foo();

    $('.my_block').draggable({
        revert: "invalid",
        stop: function() {
            $(this).draggable('option', 'revert', 'invalid');
        }

    });

    function foo() {
        $('.block').droppable({
            greedy: true,
            accept: ".my_block",
            // tolerance: "fit",
            drop: function(ev, ui) {
                ui.draggable.appendTo($(this)).removeAttr('style');
             }
        });
    }
    $('.my_block').droppable({
        greedy: true,
        tolerance: 'touch',
        drop: function(event, ui) {
            ui.draggable.draggable('option', 'revert', true);
        }
    });

});
like image 105
Tats_innit Avatar answered Nov 10 '22 18:11

Tats_innit