From bdb96c3b673cb697462df03a9cf89695569ed72a Mon Sep 17 00:00:00 2001 From: Andrei Picus Date: Tue, 14 Jan 2014 11:10:27 +0200 Subject: [PATCH] Sortable: fixed a bug with triggering over events with connected lists Fix #9335: over & out events does not consistently fire. --- tests/unit/sortable/sortable.html | 3 +- tests/unit/sortable/sortable_events.js | 101 +++++++++++++++++++++++++ ui/jquery.ui.sortable.js | 4 + 3 files changed, 107 insertions(+), 1 deletion(-) diff --git a/tests/unit/sortable/sortable.html b/tests/unit/sortable/sortable.html index b03c786e1ad..d6fc24c4c30 100644 --- a/tests/unit/sortable/sortable.html +++ b/tests/unit/sortable/sortable.html @@ -16,7 +16,8 @@ "ui/jquery.ui.core.js", "ui/jquery.ui.widget.js", "ui/jquery.ui.mouse.js", - "ui/jquery.ui.sortable.js" + "ui/jquery.ui.sortable.js", + "ui/jquery.ui.draggable.js" ] }); diff --git a/tests/unit/sortable/sortable_events.js b/tests/unit/sortable/sortable_events.js index 2d745ac206c..68748da3543 100644 --- a/tests/unit/sortable/sortable_events.js +++ b/tests/unit/sortable/sortable_events.js @@ -258,11 +258,112 @@ test( "over", function() { equal( overCount, 1, "over fires only once" ); }); +test( "#9335: draggable over connected sortable fires over event", function() { + expect( 3 ); + + var hash, + overCount = 0, + item = $( "
" ).text( "6" ).insertAfter( "#sortable" ); + + item.draggable({ + connectToSortable: "#sortable" + }); + $( ".connectWith" ).sortable({ + connectWith: ".connectWith", + over: function( e, ui ) { + hash = ui; + overCount++; + } + }); + + item.simulate( "drag", { + dy: -20 + }); + + ok( hash, "over event triggered" ); + ok( !hash.sender, "UI should not include: sender" ); + equal( overCount, 1, "over fires only once" ); +}); + +test( "#9335: over fires with connected sortable", function() { + expect( 3 ); + + var hash, + overCount = 0; + + $( ".connectWith" ).sortable({ + connectWith: ".connectWith" + }); + $( "#sortable2" ).on("sortover", function(e, ui) { + hash = ui; + overCount++; + }); + $( "#sortable" ).find( "li:eq(0)" ).simulate( "drag", { + dy: 102 + }); + + ok( hash, "over event triggered" ); + equal( hash.sender[0], $(" #sortable" )[0], "UI includes: sender" ); + equal( overCount, 1, "over fires only once" ); +}); + /* test("out", function() { ok(false, "missing test - untested code is broken code."); }); +*/ + +test( "#9335: out fires with connected sortable", function() { + expect( 2 ); + + var hash, + outCount = 0; + + $( ".connectWith" ).sortable({ + connectWith: ".connectWith" + }); + $( "#sortable" ).on( "sortout", function( e, ui ) { + hash = ui; + outCount++; + }); + $( "#sortable" ).find( "li:last" ).simulate( "drag", { + dy: 40 + }); + + ok( hash, "out event triggered" ); + equal( outCount, 1, "out fires only once" ); +}); + +test( "#9335: out & over & out & over", function() { + expect( 2 ); + + var outCount = 0, + overCount = 0; + + $( ".connectWith" ).sortable({ + connectWith: ".connectWith", + over: function() { + overCount++; + }, + out: function( e, ui ) { + // We don't care about the events that trigger when an item has dropped. + // Thus, we check for the presence of the helper. + if ( !ui.helper ) { + outCount++; + } + } + }); + $( "#sortable" ).find( "li:last" ).simulate( "drag", { + dy: 40 + }).simulate( "drag", { + dy: -40 + }); + + equal( outCount, 2, "out fires twice" ); + equal( overCount, 4, "over fires four times" ); +}); +/* test("activate", function() { ok(false, "missing test - untested code is broken code."); }); diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index 01e644f44ec..582e632ba3c 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -901,6 +901,10 @@ $.widget("ui.sortable", $.ui.mouse, { } if(this.currentContainer === this.containers[innermostIndex]) { + if ( !this.currentContainer.containerCache.over ) { + this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash() ); + this.currentContainer.containerCache.over = 1; + } return; }