@@ -20,6 +20,7 @@ angular.module('ui.sortable', [])
2020 uiSortable : '='
2121 } ,
2222 link : function ( scope , element , attrs , ngModel ) {
23+ 'use strict' ;
2324 var savedNodes ;
2425
2526 function combineCallbacks ( first , second ) {
@@ -35,6 +36,28 @@ angular.module('ui.sortable', [])
3536 return first ;
3637 }
3738
39+ function wrappersHelper ( inner ) {
40+ return function ( e , item ) {
41+ var oldItemSortable = item . sortable ;
42+ var index = getItemIndex ( item ) ;
43+ item . sortable = {
44+ model : ngModel . $modelValue [ index ] ,
45+ index : index ,
46+ source : item . parent ( ) ,
47+ sourceModel : ngModel . $modelValue ,
48+ _restore : function ( ) {
49+ delete item . sortable ;
50+ item . sortable = oldItemSortable ;
51+ }
52+ } ;
53+
54+ var innerResult = inner . apply ( this , arguments ) ;
55+ item . sortable . _restore ( ) ;
56+ item . sortable . _isCustomHelperUsed = item !== innerResult ;
57+ return innerResult ;
58+ } ;
59+ } ;
60+
3861 function getSortableWidgetInstance ( element ) {
3962 // this is a fix to support jquery-ui prior to v1.11.x
4063 // otherwise we should be using `element.sortable('instance')`
@@ -363,28 +386,6 @@ angular.module('ui.sortable', [])
363386 }
364387 } ;
365388
366- function wrappersHelper ( inner ) {
367- return function ( e , item ) {
368- var oldItemSortable = item . sortable ;
369- var index = getItemIndex ( item ) ;
370- item . sortable = {
371- model : ngModel . $modelValue [ index ] ,
372- index : index ,
373- source : item . parent ( ) ,
374- sourceModel : ngModel . $modelValue ,
375- _restore : function ( ) {
376- delete item . sortable ;
377- item . sortable = oldItemSortable ;
378- }
379- } ;
380-
381- var innerResult = inner . apply ( this , arguments ) ;
382- item . sortable . _restore ( ) ;
383- item . sortable . _isCustomHelperUsed = item !== innerResult ;
384- return innerResult ;
385- } ;
386- } ;
387-
388389 scope . $watchCollection ( 'uiSortable' , function ( newVal , oldVal ) {
389390 // ensure that the jquery-ui-sortable widget instance
390391 // is still bound to the directive's element
0 commit comments