Skip to content

Commit

Permalink
#1954: Add useAnimation option to sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-m1 committed Jan 8, 2021
1 parent a0e160a commit 5afb802
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,12 @@ For each element in the set, get the first element that matches the selector by
Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string.


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

```js
var order = sortable.toArray();
sortable.sort(order.reverse()); // apply
sortable.sort(order.reverse(), true); // apply
```


Expand Down
4 changes: 3 additions & 1 deletion src/Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ Sortable.prototype = /** @lends Sortable.prototype */ {
* Sorts the elements according to the array.
* @param {String[]} order order of the items
*/
sort: function (order) {
sort: function (order, useAnimation) {
let items = {}, rootEl = this.el;

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

useAnimation && this.captureAnimationState();
order.forEach(function (id) {
if (items[id]) {
rootEl.removeChild(items[id]);
rootEl.appendChild(items[id]);
}
});
useAnimation && this.animateAll();
},


Expand Down

0 comments on commit 5afb802

Please sign in to comment.