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

fix(sortable): manage appendTo option #263

Merged
merged 1 commit into from
Sep 7, 2014
Merged
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
3 changes: 2 additions & 1 deletion src/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ angular.module('ui.sortable', [])
// the start and stop of repeat sections and sortable doesn't
// respect their order (even if we cancel, the order of the
// comments are still messed up).
if (hasSortingHelper(element, ui) && !ui.item.sortable.received) {
if (hasSortingHelper(element, ui) && !ui.item.sortable.received &&
element.sortable( 'option', 'appendTo' ) === 'parent') {
// restore all the savedNodes except .ui-sortable-helper element
// (which is placed last). That way it will be garbage collected.
savedNodes = savedNodes.not(savedNodes.last());
Expand Down
26 changes: 25 additions & 1 deletion test/sortable.e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,30 @@ describe('uiSortable', function() {
});
});

it('should work when "helper: clone" and "appendTo" options are used together', function() {
inject(function($compile, $rootScope) {
var element;
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);
$rootScope.$apply(function() {
$rootScope.opts = {
helper: 'clone',
appendTo: 'body'
};
$rootScope.items = ['One', 'Two', 'Three'];
});

host.append(element);

var li = element.find(':eq(1)');
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
li.simulate('drag', { dy: dy });
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
expect($rootScope.items).toEqual(listContent(element));

$(element).remove();
});
});

it('should work when "helper: clone" and "placeholder" options are used together.', function() {
inject(function($compile, $rootScope) {
var element;
Expand Down Expand Up @@ -648,4 +672,4 @@ describe('uiSortable', function() {

});

});
});