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
12 changes: 12 additions & 0 deletions tests/unit/sortable/sortable.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@
</tbody>
</table>

<div id="sortable-with-text">
<div>Item 1</div>
text A
<div>Item 2</div>
text B
<div>Item 3</div>
text C
<div>Item 4</div>
text D
<div>Item 5</div>
</div>

<div id="sortable-images">
<img src="../../images/jqueryui_32x32.png" alt="">
<img src="../../images/jqueryui_32x32.png" alt="">
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/sortable/sortable_methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,32 @@ test( "refresh() should update the positions of initially empty lists (see #7498
equal( changeCount, 1 );
});

test("cancel", function() {
expect(5);

var element = $("#sortable-with-text"),
item = element.find("div").eq(3),
index = item.index(),
nextElement = item.next()[0],
prevElement = item.prev()[0],
nextNode = item[0].nextSibling,
prevNode = item[0].previousSibling;

element.sortable({
update: function() {
element.sortable("cancel");
}
});

item.simulate( "drag", {
dy: -50
});

equal(index, item.index());
equal(nextElement, item.next()[0]);
equal(prevElement, item.prev()[0]);
equal(nextNode, item[0].nextSibling);
equal(prevNode, item[0].previousSibling);
});

})(jQuery);
5 changes: 3 additions & 2 deletions ui/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ return $.widget("ui.sortable", $.ui.mouse, {
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));

//Cache the former DOM position
this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
this.domPosition = { prev: this.currentItem[0].previousSibling, parent: this.currentItem.parent()[0] };

//If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way
if(this.helper[0] !== this.currentItem[0]) {
Expand Down Expand Up @@ -1214,7 +1214,8 @@ return $.widget("ui.sortable", $.ui.mouse, {
if(this.fromOutside && !noPropagation) {
delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
}
if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
if((this.fromOutside || (this.domPosition.prev !== this.currentItem[0].previousSibling && !$(this.currentItem[0].previousSibling).is(".ui-sortable-helper")) ||
this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
}

Expand Down