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

Commit 282613c

Browse files
using $watchCollection instead of $watch
undid demo.js changes. added unit test that uses document.body as the appendTo removed gitignore changes
1 parent 0ef26b6 commit 282613c

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ node_modules/
33
coverage/
44
junit/
55
dist/
6-
out/
6+
out/

src/sortable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ angular.module('ui.sortable', [])
294294
return inner;
295295
};
296296

297-
scope.$watch('uiSortable', function(newVal /*, oldVal*/) {
297+
scope.$watchCollection('uiSortable', function(newVal /*, oldVal*/) {
298298
// ensure that the jquery-ui-sortable widget instance
299299
// is still bound to the directive's element
300300
var sortableWidgetInstance = getSortableWidgetInstance(element);

test/sortable.e2e.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,36 @@ describe('uiSortable', function() {
446446
});
447447
});
448448

449+
it('should work when "helper: clone" and "appendTo" options are used together', function() {
450+
inject(function($compile, $rootScope) {
451+
var element;
452+
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);
453+
$rootScope.$apply(function() {
454+
$rootScope.opts = {
455+
helper: 'clone',
456+
appendTo: document.body
457+
};
458+
$rootScope.items = ['One', 'Two', 'Three'];
459+
});
460+
461+
host.append(element);
462+
463+
var li = element.find(':eq(1)');
464+
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
465+
li.simulate('drag', { dy: dy });
466+
expect($rootScope.items).toEqual(['One', 'Three', 'Two']);
467+
expect($rootScope.items).toEqual(listContent(element));
468+
469+
li = element.find(':eq(2)');
470+
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
471+
li.simulate('drag', { dy: dy });
472+
expect($rootScope.items).toEqual(['One', 'Two', 'Three']);
473+
expect($rootScope.items).toEqual(listContent(element));
474+
475+
$(element).remove();
476+
});
477+
});
478+
449479
it('should work when "helper: clone" and "placeholder" options are used together.', function() {
450480
inject(function($compile, $rootScope) {
451481
var element;

0 commit comments

Comments
 (0)