@@ -58,10 +58,12 @@ angular.module('ui.sortable', [])
58
58
} ;
59
59
60
60
callbacks . update = function ( e , ui ) {
61
- // Fetch saved and current position of dropped element
62
- var end , start ;
63
- start = ui . item . sortable . index ;
64
- end = ui . item . index ( ) ;
61
+ // Save current drop position but only if this is not a second
62
+ // update that happens when moving between lists because then
63
+ // the value will be overwritten with the old value
64
+ if ( ! ui . item . sortable . relocate ) {
65
+ ui . item . sortable . dropindex = ui . item . index ( ) ;
66
+ }
65
67
66
68
// Cancel the sort (let ng-repeat do the sort for us)
67
69
element . sortable ( 'cancel' ) ;
@@ -73,9 +75,32 @@ angular.module('ui.sortable', [])
73
75
// comments are still messed up).
74
76
savedNodes . detach ( ) . appendTo ( element ) ;
75
77
76
- // Reorder array and apply change to scope
77
- scope . $apply ( function ( ) {
78
- ngModel . $modelValue . splice ( end , 0 , ngModel . $modelValue . splice ( start , 1 ) [ 0 ] ) ;
78
+ // If relocate is true (an item was dropped in from another list)
79
+ // then we add the new item to this list otherwise we move the
80
+ // item to it's new location
81
+ scope . $apply ( function ( ) {
82
+ if ( ui . item . sortable . relocate ) {
83
+ ngModel . $modelValue . splice ( ui . item . sortable . dropindex , 0 ,
84
+ ui . item . sortable . moved ) ;
85
+ } else {
86
+ ngModel . $modelValue . splice (
87
+ ui . item . sortable . dropindex , 0 ,
88
+ ngModel . $modelValue . splice ( ui . item . sortable . index , 1 ) [ 0 ] ) ;
89
+ }
90
+ } ) ;
91
+ } ;
92
+
93
+ callbacks . receive = function ( e , ui ) {
94
+ // An item was dropped here from another list, set a flag
95
+ ui . item . sortable . relocate = true ;
96
+ } ;
97
+
98
+ callbacks . remove = function ( e , ui ) {
99
+ // Remove the item from this list's model and copy data into item,
100
+ // so the next list can retrive it
101
+ scope . $apply ( function ( ) {
102
+ ui . item . sortable . moved = ngModel . $modelValue . splice (
103
+ ui . item . sortable . index , 1 ) [ 0 ] ;
79
104
} ) ;
80
105
} ;
81
106
0 commit comments