In the following code:
$(".drag").draggable({
snap: ".drop",
snapMode: "inner",
snapTolerance: 50,
revert: "invalid",
start: function(){
start_moves=moves;
},
stop: function(){
stop_moves=moves;
}
});
$(".drop").droppable({
tolerance: "fit",
drop: function (event, ui) {
$(this).droppable('option', 'accept', ui.draggable); //accepts only the current draggable
moves++;
$("#total_moves").text(moves);
},
out: function (event, ui) {
$(this).droppable('option', 'accept', ".drag"); //accepts all draggables
}
});
Here's the sequence of events that's giving me issues:
- Move Drag1 to Drop1 (fine)
- Move Drag2 to Drop2 (fine)
- Try to move Drag2 to Drop1 (Drag2 reverts back to Drop2, fine)
- The issue is that after 3), the "out" event is triggered, but when Drag2 reverts back to Drop2, the "over" event (which I deleted) is not being triggered. It seems the "over" event is only triggered when I manually drag Drag2 back to Drop2 (as opposed to when reverting automatically). The reason this is an issue is because
Moving Drag1 to Drop2 is now successful because after the line in the "out" event:
$(this).droppable('option', 'accept', ".drag"); //accepts all draggables
the "over" event (which I deleted) isn't triggered to again only accept the current draggable. Thus, multiple draggables are allowed into a single droppable, which is unwanted behavior.
So the question is, when a draggable, after being dragged out of a droppable, reverts back to the same droppable automatically because of the "revert: 'invalid'", how can I get that droppable to recognize that the draggable has re-entered (so that "out" isn't the only event triggered)? The "over" event isn't doing the trick.