Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
components
todo.TODO
/*.sublime-*
4 changes: 2 additions & 2 deletions src/angular-dragdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
if (dragSettings.index > dropSettings.index) {
temp = dragModelValue[dragSettings.index];
for (var i = dragSettings.index; i > dropSettings.index; i--) {
dropModelValue[i] = angular.copy(dropModelValue[i - 1]);
dropModelValue[i] = dragSettings.deepCopy ? angular.copy(dropModelValue[i - 1]) : dropModelValue[i - 1];
dropModelValue[i - 1] = {};
dropModelValue[i][dragSettings.direction] = 'left';
}
dropModelValue[dropSettings.index] = temp;
} else {
temp = dragModelValue[dragSettings.index];
for (var i = dragSettings.index; i < dropSettings.index; i++) {
dropModelValue[i] = angular.copy(dropModelValue[i + 1]);
dropModelValue[i] = dragSettings.deepCopy ? angular.copy(dropModelValue[i + 1]) : dropModelValue[i + 1];
dropModelValue[i + 1] = {};
dropModelValue[i][dragSettings.direction] = 'right';
}
Expand Down
66 changes: 66 additions & 0 deletions test/spec/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,70 @@ describe('Service: ngDragDropService', function() {
timeout.flush();
expect(scope.list.map(function(item) { return item.title; }).join('')).toBe('NNLIIE');
});

it('should not deep copy dragged element by default', function(){
var itemA = { 'title': 'A' };
var itemB = { 'title': 'B' };
var itemC = { 'title': 'C' };
scope.list = [
itemA,
itemB,
itemC
];
var copy = scope.list.slice();
ngDragDropService.draggableScope = ngDragDropService.droppableScope = scope;
ngDragDropService.invokeDrop(
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 2}" jqyoui-draggable="{index: 2, insertInline: true, direction:\'jqyouiDirection\'}">' + scope.list[2].title + '</div>').data('$scope', scope),
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 0}" jqyoui-draggable="{index: 0, insertInline: true, direction:\'jqyouiDirection\'}">' + scope.list[0].title + '</div>').data('$scope', scope),
document.createEvent('Event'),
{}
);
timeout.flush();
expect(copy[0]).toBe(scope.list[1]);
});

it('should not deep copy dragged element when settings specify not to', function(){
var itemA = { 'title': 'A' };
var itemB = { 'title': 'B' };
var itemC = { 'title': 'C' };
scope.list = [
itemA,
itemB,
itemC
];
var copy = scope.list.slice();
ngDragDropService.draggableScope = ngDragDropService.droppableScope = scope;
ngDragDropService.invokeDrop(
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 2}" jqyoui-draggable="{index: 2, insertInline: true, direction:\'jqyouiDirection\', deepCopy:false}">' + scope.list[2].title + '</div>').data('$scope', scope),
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 0}" jqyoui-draggable="{index: 0, insertInline: true, direction:\'jqyouiDirection\', deepCopy:false}">' + scope.list[0].title + '</div>').data('$scope', scope),
document.createEvent('Event'),
{}
);
timeout.flush();
expect(copy[0]).toBe(scope.list[1]);
});

it('should deep copy dragged element when settings specify so', function(){
var itemA = { 'title': 'A' };
var itemB = { 'title': 'B' };
var itemC = { 'title': 'C' };
scope.list = [
itemA,
itemB,
itemC
];
var copy = scope.list.slice();
ngDragDropService.draggableScope = ngDragDropService.droppableScope = scope;
ngDragDropService.invokeDrop(
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 2}" jqyoui-draggable="{index: 2, insertInline: true, direction:\'jqyouiDirection\', deepCopy:true}">' + scope.list[2].title + '</div>').data('$scope', scope),
$('<div data-drop="true" data-drag="true" ng-model="list" jqyoui-droppable="{index: 0}" jqyoui-draggable="{index: 0, insertInline: true, direction:\'jqyouiDirection\', deepCopy:true}">' + scope.list[0].title + '</div>').data('$scope', scope),
document.createEvent('Event'),
{}
);
timeout.flush();
expect(copy[0]).not.toBe(scope.list[1]);
for(var prop in copy[0]){
expect(copy[0][prop]).toBe(scope.list[1][prop]);
}
});
});