$.ui.undroppable needed...
Hi Team,
I just startet playing around with UI yesterday and I'm really amazed
on how stable everything works after such a short time of development!
I've come over a problem with droppables: I use quite a lot AJAX in my
application so it happens, that basically the same droppable element
disappears from the DOM and the re-appears some time later without a
complete page-reload. That's the point where I need to remove the old
ddmanager-instance of the droppable and create a new one. If I just
call $('#el').droppable(); again, the droppable won't work and Firebug
spits out a "parent has no properties"-error, when I want to drop a
draggable, since the ddmanager seems to use the old instance of the
droppable which has already been removed from the DOM.
My workaround was to add some code to the undroppable-method and then
call $('#el').undroppable().droppable( { options... });
$.fn.undroppable = function() {
return this.each(function() {
new $.ui.undroppable(this);
});
}
$.ui.undroppable = function(el) {
var drops = $.ui.ddmanager.droppables;
var newDrops = [];
for (var i = 0; i<drops.length; i++) {
if (drops[i].item.element.id == el.id) {
continue;
}
newDrops.push(drops[i]);
}
$.ui.ddmanager.droppables = newDrops;
}
I cannot compare the elements directly, since the new element is
different from the old one, so I have to compare the element's id's.
This might be a problem, if a droppable does not necessaryly need an
id-attribute.
I'm sure there is a nicer way to implement this, I'm just not yet
completely into the code. However especially for applications that use
a lot of AJAX I think some way to remove/destroy old droppable-
instances is absolutely necessary. But most probably that feature was
planned for the final release anyways...
Thank's so far, I'm really looking forward to the final release!
Christoph