2
2
jQuery UI Sortable plugin wrapper
3
3
4
4
@param [ui-sortable] {object} Options to pass to $.fn.sortable() merged onto ui.config
5
- */
5
+ */
6
6
angular . module ( 'ui.sortable' , [ ] )
7
- . value ( 'uiSortableConfig' , { } )
7
+ . value ( 'uiSortableConfig' , { } )
8
8
. directive ( 'uiSortable' , [ 'uiSortableConfig' , '$log' ,
9
- function ( uiSortableConfig , log ) {
9
+ function ( uiSortableConfig , $ log) {
10
10
return {
11
11
require : '?ngModel' ,
12
12
link : function ( scope , element , attrs , ngModel ) {
13
13
14
- function combineCallbacks ( first , second ) {
15
- if ( second && ( typeof second === "function" ) ) {
14
+ function combineCallbacks ( first , second ) {
15
+ if ( second && ( typeof second === "function" ) ) {
16
16
return function ( e , ui ) {
17
17
first ( e , ui ) ;
18
18
second ( e , ui ) ;
@@ -25,16 +25,10 @@ angular.module('ui.sortable', [])
25
25
26
26
var callbacks = {
27
27
receive : null ,
28
- remove : null ,
29
- start : null ,
30
- stop : null ,
31
- update : null
32
- } ;
33
-
34
- var apply = function ( e , ui ) {
35
- if ( ui . item . sortable . resort || ui . item . sortable . relocate ) {
36
- scope . $apply ( ) ;
37
- }
28
+ remove :null ,
29
+ start :null ,
30
+ stop :null ,
31
+ update :null
38
32
} ;
39
33
40
34
angular . extend ( opts , uiSortableConfig ) ;
@@ -46,12 +40,11 @@ angular.module('ui.sortable', [])
46
40
} ;
47
41
48
42
callbacks . start = function ( e , ui ) {
49
- // Save position of dragged item
50
- ui . item . sortable = {
51
- index : ui . item . index ( )
52
- } ;
43
+ // Save the starting position of dragged item
44
+ ui . item . sortable = { index : ui . item . index ( ) } ;
53
45
} ;
54
46
47
+
55
48
callbacks . update = function ( e , ui ) {
56
49
// For some reason the reference to ngModel in stop() is wrong
57
50
ui . item . sortable . resort = ngModel ;
@@ -96,29 +89,28 @@ angular.module('ui.sortable', [])
96
89
97
90
if ( key === 'stop' ) {
98
91
// call apply after stop
99
- value = combineCallbacks ( value , apply ) ;
92
+ value = combineCallbacks (
93
+ value , function ( ) { scope . $apply ( ) ; } ) ;
100
94
}
101
95
}
102
-
103
96
element . sortable ( 'option' , key , value ) ;
104
97
} ) ;
105
98
} , true ) ;
106
99
107
100
angular . forEach ( callbacks , function ( value , key ) {
108
-
109
101
opts [ key ] = combineCallbacks ( value , opts [ key ] ) ;
110
102
} ) ;
111
103
112
104
// call apply after stop
113
- opts . stop = combineCallbacks ( opts . stop , apply ) ;
105
+ opts . stop = combineCallbacks ( opts . stop , function ( ) { scope . $ apply( ) ; } ) ;
114
106
115
107
} else {
116
- log . info ( 'ui.sortable: ngModel not provided!' , element ) ;
108
+ $ log. info ( 'ui.sortable: ngModel not provided!' , element ) ;
117
109
}
118
110
119
111
// Create sortable
120
112
element . sortable ( opts ) ;
121
113
}
122
114
} ;
123
115
}
124
- ] ) ;
116
+ ] ) ;
0 commit comments