Skip to content

Commit f9b7631

Browse files
committed
initial commit
1 parent 57c5332 commit f9b7631

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/sortable.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,12 @@ angular.module('ui.sortable', [])
207207
// so the next list can retrive it
208208
if (!ui.item.sortable.isCanceled()) {
209209
scope.$apply(function () {
210-
ui.item.sortable.moved = ngModel.$modelValue.splice(
211-
ui.item.sortable.index, 1)[0];
210+
if (element.sortable('option', 'helper') === 'clone') {
211+
ui.item.sortable.moved = angular.copy(ngModel.$modelValue[ui.item.sortable.index]);
212+
} else {
213+
ui.item.sortable.moved = ngModel.$modelValue.splice(
214+
ui.item.sortable.index, 1)[0];
215+
}
212216
});
213217
}
214218
};

test/sortable.e2e.multi.spec.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ describe('uiSortable', function() {
181181
it('should work when "helper: clone" option is used', function() {
182182
inject(function($compile, $rootScope) {
183183
var elementTop, elementBottom;
184-
elementTop = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
185-
elementBottom = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
184+
elementTop = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop track by $index" id="s-top-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
185+
elementBottom = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom track by $index" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
186186
$rootScope.$apply(function() {
187187
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
188188
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
@@ -197,16 +197,16 @@ describe('uiSortable', function() {
197197
var li1 = elementTop.find(':eq(0)');
198198
var li2 = elementBottom.find(':eq(0)');
199199
simulateElementDrag(li1, li2, 'below');
200-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
200+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
201201
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
202202
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
203203
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
204204

205205
li1 = elementBottom.find(':eq(1)');
206206
li2 = elementTop.find(':eq(1)');
207207
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
208-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
209-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
208+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top One', 'Top Two', 'Top Three']);
209+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
210210
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
211211
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
212212

@@ -218,8 +218,8 @@ describe('uiSortable', function() {
218218
it('should work when "placeholder" and "helper: clone" options are used', function() {
219219
inject(function($compile, $rootScope) {
220220
var elementTop, elementBottom;
221-
elementTop = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop" id="s-top-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
222-
elementBottom = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
221+
elementTop = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsTop"><li ng-repeat="item in itemsTop track by $index" id="s-top-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
222+
elementBottom = $compile('<ul ui-sortable="opts" class="cross-sortable" ng-model="itemsBottom"><li ng-repeat="item in itemsBottom track by $index" id="s-bottom-{{$index}}" class="sortable-item">{{ item }}</li></ul>')($rootScope);
223223
$rootScope.$apply(function() {
224224
$rootScope.itemsTop = ['Top One', 'Top Two', 'Top Three'];
225225
$rootScope.itemsBottom = ['Bottom One', 'Bottom Two', 'Bottom Three'];
@@ -235,16 +235,16 @@ describe('uiSortable', function() {
235235
var li1 = elementTop.find(':eq(0)');
236236
var li2 = elementBottom.find(':eq(0)');
237237
simulateElementDrag(li1, li2, 'below');
238-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top Three']);
238+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top Two', 'Top Three']);
239239
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
240240
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
241241
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
242242

243243
li1 = elementBottom.find(':eq(1)');
244244
li2 = elementTop.find(':eq(1)');
245245
simulateElementDrag(li1, li2, { place: 'above', extradx: -20, extrady: -10 });
246-
expect($rootScope.itemsTop).toEqual(['Top Two', 'Top One', 'Top Three']);
247-
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Bottom Two', 'Bottom Three']);
246+
expect($rootScope.itemsTop).toEqual(['Top One', 'Top One', 'Top Two', 'Top Three']);
247+
expect($rootScope.itemsBottom).toEqual(['Bottom One', 'Top One', 'Bottom Two', 'Bottom Three']);
248248
expect($rootScope.itemsTop).toEqual(listContent(elementTop));
249249
expect($rootScope.itemsBottom).toEqual(listContent(elementBottom));
250250

0 commit comments

Comments
 (0)