Skip to content

Commit 4ba99eb

Browse files
committed
fix(*): Closes #143 - introduce deepCopy option to support deep copy on draggable/droppable
Deep Copy basically looses prototypical inheritence which is sometimes necessary and hence it is made optional via deepCopy option. More Info: https://egghead.io/lessons/angularjs-angular-copy-for-deep-copy
1 parent 0c1c472 commit 4ba99eb

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ angular.module('myApp', ['ngDragDrop'])
3535
* **onDrag** – string – callback method to be invoked while the mouse is moved during the dragging
3636
* **applyFilter** - string - applies AngularJS $filter on the list before swapping items. Only applicable, if ngRepeat has any filter (such as orderBy, limitTo) associated with it.
3737
* **containment** – string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
38+
* **deepCopy** - boolean (optional) – If true, makes a deep copy of draggable that looses prototypical inheritance.
3839
* **data-drag** – boolean – If true, element can be draggable. Disabled otherwise.
3940
* **data-jqyoui-options** – object – should hold all the valid options supported by [jQueryUI Draggable](http://api.jqueryui.com/draggable)
4041
* **ng-model** – string – An angular model defined in a controller. Should be a JS array or object
@@ -49,6 +50,7 @@ angular.module('myApp', ['ngDragDrop'])
4950
* **onOut** – string – callback method to be invoked when an accepted draggable is dragged out of the droppable
5051
* **applyFilter** - string - requires if both droppable as well as draggable share the same ngModel.
5152
* **containment** – string - position/offset. Offset by default. This forces to use jQuery.position() or jQuery.offset() to calculate proper position with respect to parent element or document respectively.
53+
* **deepCopy** – boolean (optional) – If true, makes a deep copy of droppable that looses prototypical inheritance.
5254
* **data-drop** – boolean – If true, element can be droppable. Disabled otherwise.
5355
* **data-jqyoui-options** – object – should hold all the valid options supported by [jQueryUI Droppable](http://api.jqueryui.com/droppable)
5456
* **ng-model** – string – An angular model defined in a controller. Should be a JS array or object.
@@ -63,6 +65,11 @@ angular.module('myApp', ['ngDragDrop'])
6365
##Demo
6466
Demo is [here](http://codef0rmer.github.io/angular-dragdrop/#/)
6567

68+
69+
###v1.0.9 - breaking change
70+
Draggable and Droppable will not be deep copied by default unlike previous versions. Use deepCopy option, if needed.
71+
72+
6673
###v1.0.5 - breaking change
6774
Do not pass evaluated expressions in callbacks. For example,
6875
####Before:

src/angular-dragdrop.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
8888
dropSettings.index = this.fixIndex(droppableScope, dropSettings, dropModelValue);
8989

9090
jqyoui_pos = angular.isArray(dragModelValue) ? dragSettings.index : null;
91-
dragItem = angular.copy(angular.isArray(dragModelValue) ? dragModelValue[jqyoui_pos] : dragModelValue);
91+
dragItem = angular.isArray(dragModelValue) ? dragModelValue[jqyoui_pos] : dragModelValue;
92+
93+
if (dragSettings.deepCopy) {
94+
dragItem = angular.copy(dragItem);
95+
}
9296

9397
if (angular.isArray(dropModelValue) && dropSettings && dropSettings.index !== undefined) {
9498
dropItem = dropModelValue[dropSettings.index];
@@ -97,7 +101,10 @@ var jqyoui = angular.module('ngDragDrop', []).service('ngDragDropService', ['$ti
97101
} else {
98102
dropItem = {};
99103
}
100-
dropItem = angular.copy(dropItem);
104+
105+
if (dropSettings.deepCopy) {
106+
dropItem = angular.copy(dropItem);
107+
}
101108

102109
if (dragSettings.animate === true) {
103110
this.move($draggable, $droppableDraggable.length > 0 ? $droppableDraggable : $droppable, null, 'fast', dropSettings, null);

src/angular-dragdrop.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)