Skip to content

Commit 1c80735

Browse files
voithosscottgonzalez
authored andcommitted
Droppable: Changed drop event to loop over a copied array instead of the droppables directly. Fixed #9116 - Droppable: Drop event can cause droppables to remain active if any droppable is created/destroyed in the event handler.
1 parent e9c04bf commit 1c80735

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

tests/unit/droppable/droppable.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ <h2 id="qunit-userAgent"></h2>
4242

4343
<div id="draggable1" style="width: 25px; height: 25px;">Draggable</div>
4444
<div id="droppable1" style="width: 100px; height: 100px;">Droppable</div>
45+
<div id="droppable2" style="width: 100px; height: 100px;">Droppable</div>
4546
<div style='width:1000px;height:1000px;'>&nbsp;</div>
4647

4748
</div>

tests/unit/droppable/droppable_events.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,39 @@
55

66
module("droppable: events");
77

8+
test( "droppable destruction/recreation on drop event", function() {
9+
expect( 1 );
10+
11+
var config = {
12+
activeClass: "active",
13+
drop: function() {
14+
var element = $( this ),
15+
newDroppable = $( "<div>" )
16+
.css({ width: 100, height: 100 })
17+
.text( "Droppable" );
18+
element.after( newDroppable );
19+
element.remove();
20+
newDroppable.droppable( config );
21+
}
22+
},
23+
24+
draggable = $( "#draggable1" ).draggable(),
25+
droppable1 = $( "#droppable1" ).droppable( config ),
26+
droppable2 = $( "#droppable2" ).droppable( config ),
27+
28+
droppableOffset = droppable1.offset(),
29+
draggableOffset = draggable.offset(),
30+
dx = droppableOffset.left - draggableOffset.left,
31+
dy = droppableOffset.top - draggableOffset.top;
32+
33+
draggable.simulate( "drag", {
34+
dx: dx,
35+
dy: dy
36+
});
37+
38+
ok( !droppable2.hasClass( "active" ), "subsequent droppable no longer active" );
39+
});
40+
841
// this is here to make JSHint pass "unused", and we don't want to
942
// remove the parameter for when we finally implement
1043
$.noop();

ui/jquery.ui.droppable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ $.ui.ddmanager = {
278278
drop: function(draggable, event) {
279279

280280
var dropped = false;
281-
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
281+
// Create a copy of the droppables in case the list changes during the drop (#9116)
282+
$.each(($.ui.ddmanager.droppables[draggable.options.scope] || []).slice(), function() {
282283

283284
if(!this.options) {
284285
return;

0 commit comments

Comments
 (0)