Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 34ed7bf

Browse files
committed
Merge pull request #263 from Intia/appendTo
fix(sortable): manage appendTo option
2 parents 5168154 + d5365e7 commit 34ed7bf

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/sortable.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ angular.module('ui.sortable', [])
133133
// the start and stop of repeat sections and sortable doesn't
134134
// respect their order (even if we cancel, the order of the
135135
// comments are still messed up).
136-
if (hasSortingHelper(element, ui) && !ui.item.sortable.received) {
136+
if (hasSortingHelper(element, ui) && !ui.item.sortable.received &&
137+
element.sortable( 'option', 'appendTo' ) === 'parent') {
137138
// restore all the savedNodes except .ui-sortable-helper element
138139
// (which is placed last). That way it will be garbage collected.
139140
savedNodes = savedNodes.not(savedNodes.last());

test/sortable.e2e.spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,30 @@ describe('uiSortable', function() {
381381
});
382382
});
383383

384+
it('should work when "helper: clone" and "appendTo" options are used together', function() {
385+
inject(function($compile, $rootScope) {
386+
var element;
387+
element = $compile('<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
388+
$rootScope.$apply(function() {
389+
$rootScope.opts = {
390+
helper: 'clone',
391+
appendTo: 'body'
392+
};
393+
$rootScope.items = ['One', 'Two', 'Three'];
394+
});
395+
396+
host.append(element);
397+
398+
var li = element.find(':eq(1)');
399+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
400+
li.simulate('drag', { dy: dy });
401+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
402+
expect($rootScope.items).toEqual(listContent(element));
403+
404+
$(element).remove();
405+
});
406+
});
407+
384408
it('should work when "helper: clone" and "placeholder" options are used together.', function() {
385409
inject(function($compile, $rootScope) {
386410
var element;
@@ -648,4 +672,4 @@ describe('uiSortable', function() {
648672

649673
});
650674

651-
});
675+
});

0 commit comments

Comments
 (0)