Skip to content

Commit 1cfebf8

Browse files
NiGhTTraXmikesherov
authored andcommitted
Sortable: fire "over" and "out" even when a connectWith hasn't changed
Fixes #9335
1 parent 4dad6bb commit 1cfebf8

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

tests/unit/sortable/sortable.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"ui/core.js",
1717
"ui/widget.js",
1818
"ui/mouse.js",
19-
"ui/sortable.js"
19+
"ui/sortable.js",
20+
"ui/draggable.js"
2021
]
2122
});
2223
</script>

tests/unit/sortable/sortable_events.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,114 @@ test( "over", function() {
258258
equal( overCount, 1, "over fires only once" );
259259
});
260260

261+
// http://bugs.jqueryui.com/ticket/9335
262+
// Sortable: over & out events does not consistently fire
263+
test( "over, fires with draggable connected to sortable", function() {
264+
expect( 3 );
265+
266+
var hash,
267+
overCount = 0,
268+
item = $( "<div></div>" ).text( "6" ).insertAfter( "#sortable" );
269+
270+
item.draggable({
271+
connectToSortable: "#sortable"
272+
});
273+
$( ".connectWith" ).sortable({
274+
connectWith: ".connectWith",
275+
over: function( event, ui ) {
276+
hash = ui;
277+
overCount++;
278+
}
279+
});
280+
281+
item.simulate( "drag", {
282+
dy: -20
283+
});
284+
285+
ok( hash, "over event triggered" );
286+
ok( !hash.sender, "UI should not include: sender" );
287+
equal( overCount, 1, "over fires only once" );
288+
});
289+
290+
test( "over, with connected sortable", function() {
291+
expect( 3 );
292+
293+
var hash,
294+
overCount = 0;
295+
296+
$( ".connectWith" ).sortable({
297+
connectWith: ".connectWith"
298+
});
299+
$( "#sortable2" ).on( "sortover", function( event, ui ) {
300+
hash = ui;
301+
overCount++;
302+
});
303+
$( "#sortable" ).find( "li:eq(0)" ).simulate( "drag", {
304+
dy: 102
305+
});
306+
307+
ok( hash, "over event triggered" );
308+
equal( hash.sender[ 0 ], $(" #sortable" )[ 0 ], "UI includes: sender" );
309+
equal( overCount, 1, "over fires only once" );
310+
});
311+
261312
/*
262313
test("out", function() {
263314
ok(false, "missing test - untested code is broken code.");
264315
});
316+
*/
317+
318+
test( "out, with connected sortable", function() {
319+
expect( 2 );
320+
321+
var hash,
322+
outCount = 0;
323+
324+
$( ".connectWith" ).sortable({
325+
connectWith: ".connectWith"
326+
});
327+
$( "#sortable" ).on( "sortout", function( event, ui ) {
328+
hash = ui;
329+
outCount++;
330+
});
331+
$( "#sortable" ).find( "li:last" ).simulate( "drag", {
332+
dy: 40
333+
});
334+
335+
ok( hash, "out event triggered" );
336+
equal( outCount, 1, "out fires only once" );
337+
});
338+
339+
test( "repeated out & over between connected sortables", function() {
340+
expect( 2 );
265341

342+
var outCount = 0,
343+
overCount = 0;
344+
345+
$( ".connectWith" ).sortable({
346+
connectWith: ".connectWith",
347+
over: function() {
348+
overCount++;
349+
},
350+
out: function( event, ui ) {
351+
// Ignore events that trigger when an item has dropped
352+
// checking for the presence of the helper.
353+
if ( !ui.helper ) {
354+
outCount++;
355+
}
356+
}
357+
});
358+
$( "#sortable" ).find( "li:last" ).simulate( "drag", {
359+
dy: 40
360+
}).simulate( "drag", {
361+
dy: -40
362+
});
363+
364+
equal( outCount, 2, "out fires twice" );
365+
equal( overCount, 4, "over fires four times" );
366+
});
367+
368+
/*
266369
test("activate", function() {
267370
ok(false, "missing test - untested code is broken code.");
268371
});

ui/sortable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,10 @@ return $.widget("ui.sortable", $.ui.mouse, {
911911
}
912912

913913
if(this.currentContainer === this.containers[innermostIndex]) {
914+
if ( !this.currentContainer.containerCache.over ) {
915+
this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash() );
916+
this.currentContainer.containerCache.over = 1;
917+
}
914918
return;
915919
}
916920

0 commit comments

Comments
 (0)