|
1 | 1 | /**
|
2 | 2 | * angular-ui-sortable - This directive allows you to jQueryUI Sortable.
|
3 |
| - * @version v0.15.0 - 2016-10-15 |
| 3 | + * @version v0.15.1 - 2016-11-28 |
4 | 4 | * @link http://angular-ui.github.com
|
5 | 5 | * @license MIT
|
6 | 6 | */
|
@@ -378,29 +378,30 @@ angular.module('ui.sortable', [])
|
378 | 378 | // If the received flag hasn't be set on the item, this is a
|
379 | 379 | // normal sort, if dropindex is set, the item was moved, so move
|
380 | 380 | // the items in the list.
|
381 |
| - if(!ui.item.sortable.received && |
382 |
| - ('dropindex' in ui.item.sortable) && |
383 |
| - !ui.item.sortable.isCanceled()) { |
| 381 | + var wasMoved = ('dropindex' in ui.item.sortable) && |
| 382 | + !ui.item.sortable.isCanceled(); |
| 383 | + |
| 384 | + if (wasMoved && !ui.item.sortable.received) { |
384 | 385 |
|
385 | 386 | scope.$apply(function () {
|
386 | 387 | ngModel.$modelValue.splice(
|
387 | 388 | ui.item.sortable.dropindex, 0,
|
388 | 389 | ngModel.$modelValue.splice(ui.item.sortable.index, 1)[0]);
|
389 | 390 | });
|
390 |
| - } else { |
391 |
| - // if the item was not moved, then restore the elements |
| 391 | + } else if (!wasMoved && |
| 392 | + !angular.equals(element.contents().toArray(), savedNodes.toArray())) { |
| 393 | + // if the item was not moved |
| 394 | + // and the DOM element order has changed, |
| 395 | + // then restore the elements |
392 | 396 | // so that the ngRepeat's comment are correct.
|
393 |
| - if ((!('dropindex' in ui.item.sortable) || ui.item.sortable.isCanceled()) && |
394 |
| - !angular.equals(element.contents(), savedNodes)) { |
395 |
| - |
396 |
| - var sortingHelper = getSortingHelper(element, ui, savedNodes); |
397 |
| - if (sortingHelper && sortingHelper.length) { |
398 |
| - // Restore all the savedNodes except from the sorting helper element. |
399 |
| - // That way it will be garbage collected. |
400 |
| - savedNodes = savedNodes.not(sortingHelper); |
401 |
| - } |
402 |
| - savedNodes.appendTo(element); |
| 397 | + |
| 398 | + var sortingHelper = getSortingHelper(element, ui, savedNodes); |
| 399 | + if (sortingHelper && sortingHelper.length) { |
| 400 | + // Restore all the savedNodes except from the sorting helper element. |
| 401 | + // That way it will be garbage collected. |
| 402 | + savedNodes = savedNodes.not(sortingHelper); |
403 | 403 | }
|
| 404 | + savedNodes.appendTo(element); |
404 | 405 | }
|
405 | 406 |
|
406 | 407 | // It's now safe to clear the savedNodes
|
|
0 commit comments