Skip to content

Commit 5afb802

Browse files
committed
#1954: Add useAnimation option to sort()
1 parent a0e160a commit 5afb802

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -565,12 +565,12 @@ For each element in the set, get the first element that matches the selector by
565565
Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string.
566566

567567

568-
##### sort(order:`String[]`)
568+
##### sort(order:`String[]`, useAnimation:`Boolean`)
569569
Sorts the elements according to the array.
570570

571571
```js
572572
var order = sortable.toArray();
573-
sortable.sort(order.reverse()); // apply
573+
sortable.sort(order.reverse(), true); // apply
574574
```
575575

576576

src/Sortable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
15691569
* Sorts the elements according to the array.
15701570
* @param {String[]} order order of the items
15711571
*/
1572-
sort: function (order) {
1572+
sort: function (order, useAnimation) {
15731573
let items = {}, rootEl = this.el;
15741574

15751575
this.toArray().forEach(function (id, i) {
@@ -1580,12 +1580,14 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
15801580
}
15811581
}, this);
15821582

1583+
useAnimation && this.captureAnimationState();
15831584
order.forEach(function (id) {
15841585
if (items[id]) {
15851586
rootEl.removeChild(items[id]);
15861587
rootEl.appendChild(items[id]);
15871588
}
15881589
});
1590+
useAnimation && this.animateAll();
15891591
},
15901592

15911593

0 commit comments

Comments
 (0)