[BUG+PATCH] ui.droppables: calc position creates undroppables on elements not yet added to DOM

[BUG+PATCH] ui.droppables: calc position creates undroppables on elements not yet added to DOM


Hi there,
I've been trying to create DOM elements, make them droppable, and add
them in one fell swoop... pretty much ala:
    var $li1 = $('<li class="one">foo</li>');
    $li1.draggable({opacity: 0.5, helper: 'clone'});
    var $li2 = $('<li>bar</li>');
    $li.droppable({
        accept: '.one',
        tolerance: 'pointer',
        activeClass: 'droppable-active',
        hoverClass: 'droppable-hover',
        refreshPositions: true,
        drop: function(ev, ui) {
         alert('dropped '+ui.draggable+' onto '+this+'!');
        },
    });
I couldn't figure out why the droppables I was creating were getting
'droppable-active' set but never 'droppable-hover'. And it worked for
other droppables I had on the page.
When I looked through ui.droppable.js, I found out that
'refreshPositions' doesn't quite do what it says on the tin - it
refreshes the offsets, but not the proportions.
I've uploaded a patch that does just that (though I can't figure out
how to link to it from here? it's called ui.droppable.js-recalc-
position.patch). Note that I opted to do a recalcProportions() on
droppable.activate() instead of in the drag() method like
prepareOffsets() because I wanted to reduce the time spent
calculating... others may have different opinions. I also made the
mouse pointer calcs a bit less repetitive (and prolly 1x10e-100 s
faster ;-)
Hope this helps,
-Steve