Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/unit/sortable/sortable.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"ui/core.js",
"ui/widget.js",
"ui/mouse.js",
"ui/sortable.js"
"ui/sortable.js",
"ui/draggable.js"
]
});
</script>
Expand Down
101 changes: 101 additions & 0 deletions tests/unit/sortable/sortable_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $( "<div></div>" ).text( "6" ).insertAfter( "#sortable" );

item.draggable({
connectToSortable: "#sortable"
});
$( ".connectWith" ).sortable({
connectWith: ".connectWith",
over: function( e, ui ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e --> event

That change needs to happen a few times in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every test uses that notation, not only the ones I added. There should be a separate commit changing every occurence if needed.

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. What's the difference between this and the previous test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One is testing that the 'over' event fires when an outside item is brought over the list, the other tests that the event is fired when you pick up an element already present in the list.

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.");
});
Expand Down
4 changes: 4 additions & 0 deletions ui/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,10 @@ return $.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;
}

Expand Down