@@ -209,10 +209,10 @@ angular.module('ui.sortable', [])
209
209
// return the index of ui.item among the items
210
210
// we can't just do ui.item.index() because there it might have siblings
211
211
// which are not items
212
- function getItemIndex ( ui ) {
213
- return ui . item . parent ( )
212
+ function getItemIndex ( item ) {
213
+ return item . parent ( )
214
214
. find ( opts [ 'ui-model-items' ] )
215
- . index ( ui . item ) ;
215
+ . index ( item ) ;
216
216
}
217
217
218
218
var opts = { } ;
@@ -266,7 +266,7 @@ angular.module('ui.sortable', [])
266
266
}
267
267
268
268
// Save the starting position of dragged item
269
- var index = getItemIndex ( ui ) ;
269
+ var index = getItemIndex ( ui . item ) ;
270
270
ui . item . sortable = {
271
271
model : ngModel . $modelValue [ index ] ,
272
272
index : index ,
@@ -322,7 +322,7 @@ angular.module('ui.sortable', [])
322
322
// update that happens when moving between lists because then
323
323
// the value will be overwritten with the old value
324
324
if ( ! ui . item . sortable . received ) {
325
- ui . item . sortable . dropindex = getItemIndex ( ui ) ;
325
+ ui . item . sortable . dropindex = getItemIndex ( ui . item ) ;
326
326
var droptarget = ui . item . parent ( ) ;
327
327
ui . item . sortable . droptarget = droptarget ;
328
328
@@ -431,7 +431,24 @@ angular.module('ui.sortable', [])
431
431
wrappers . helper = function ( inner ) {
432
432
if ( inner && typeof inner === 'function' ) {
433
433
return function ( e , item ) {
434
+ var oldItemSortable = item . sortable ;
435
+ var index = getItemIndex ( item ) ;
436
+ item . sortable = {
437
+ model : ngModel . $modelValue [ index ] ,
438
+ index : index ,
439
+ source : item . parent ( ) ,
440
+ sourceModel : ngModel . $modelValue ,
441
+ _restore : function ( ) {
442
+ angular . forEach ( item . sortable , function ( value , key ) {
443
+ item . sortable [ key ] = undefined ;
444
+ } ) ;
445
+
446
+ item . sortable = oldItemSortable ;
447
+ }
448
+ } ;
449
+
434
450
var innerResult = inner . apply ( this , arguments ) ;
451
+ item . sortable . _restore ( ) ;
435
452
item . sortable . _isCustomHelperUsed = item !== innerResult ;
436
453
return innerResult ;
437
454
} ;
0 commit comments