I created a little proof of the jsfiddle concept ( http://jsfiddle.net/9M8gP/21/ ). Quick crash:
processDroppedElementSearches for a list of discarded items and selects the appropriate item. Obviously, you can customize your selection criteria. After processing the event, it resets state variables accordingly.
var processDroppedElement = function() {
$("p").html("");
var targetElement = null;
var targetZ = -1;
for (var i in droppedElements) {
var element = droppedElements[i];
var zOrder = $( element ).data("zOrder");
if (zOrder && zOrder > targetZ) {
targetElement = element;
}
}
if (targetElement) {
$( targetElement )
.addClass( "ui-state-highlight" )
.find( "p" )
.html( "Dropped!" );
droppedElement = null;
}
$("#draggable").css({
'left': $("#draggable").data('originalLeft'),
'top': $("#draggable").data('origionalTop')
});
droppedElements = [];
};
This section of code defines the main variables used to manage the discarded items and run the function processDroppedElement.
var droppedTimer;
var droppedElements = [];
var queueDroppedElement = function(element) {
droppedElements.push(element);
}
drop - . , , . ,
$( ".droppable" ).droppable({
drop: function( event, ui ) {
var myZorder = $( this ).data("zOrder");
console.log("zOrder: " + myZorder);
queueDroppedElement(this);
clearTimeout(droppedTimer);
droppedTimer = setTimeout(processDroppedElement, 50);
}
});