1
1
/**
2
2
* angular-ui-sortable - This directive allows you to jQueryUI Sortable.
3
- * @version v0.17.2 - 2017-08-17
3
+ * @version v0.18.0 - 2017-11-26
4
4
* @link http://angular-ui.github.com
5
5
* @license MIT
6
6
*/
@@ -71,6 +71,19 @@ angular.module('ui.sortable', [])
71
71
return null ;
72
72
}
73
73
74
+ function setItemChildrenWidth ( item ) {
75
+ item . children ( ) . each ( function ( ) {
76
+ var $el = angular . element ( this ) ;
77
+
78
+ // Preserve the with of the element
79
+ $el . width ( $el . width ( ) ) ;
80
+ } ) ;
81
+ }
82
+
83
+ function dummyHelper ( e , item ) {
84
+ return item ;
85
+ }
86
+
74
87
function patchSortableOption ( key , value ) {
75
88
if ( callbacks [ key ] ) {
76
89
if ( key === 'stop' ) {
@@ -94,7 +107,8 @@ angular.module('ui.sortable', [])
94
107
return value ;
95
108
}
96
109
97
- function patchUISortableOptions ( newVal , oldVal , sortableWidgetInstance ) {
110
+ function patchUISortableOptions ( newOpts , oldOpts , sortableWidgetInstance ) {
111
+
98
112
function addDummyOptionKey ( value , key ) {
99
113
if ( ! ( key in opts ) ) {
100
114
// add the key in the opts object so that
@@ -109,11 +123,11 @@ angular.module('ui.sortable', [])
109
123
// update some options of the sortable
110
124
var optsDiff = null ;
111
125
112
- if ( oldVal ) {
126
+ if ( oldOpts ) {
113
127
// reset deleted options to default
114
128
var defaultOptions ;
115
- angular . forEach ( oldVal , function ( oldValue , key ) {
116
- if ( ! newVal || ! ( key in newVal ) ) {
129
+ angular . forEach ( oldOpts , function ( oldValue , key ) {
130
+ if ( ! newOpts || ! ( key in newOpts ) ) {
117
131
if ( key in directiveOpts ) {
118
132
if ( key === 'ui-floating' ) {
119
133
opts [ key ] = 'auto' ;
@@ -138,16 +152,33 @@ angular.module('ui.sortable', [])
138
152
} ) ;
139
153
}
140
154
155
+ newOpts = angular . extend ( { } , newOpts ) ;
141
156
// update changed options
142
- angular . forEach ( newVal , function ( value , key ) {
143
- // if it's a custom option of the directive,
144
- // handle it approprietly
157
+ // handle the custom option of the directive first
158
+ angular . forEach ( newOpts , function ( value , key ) {
145
159
if ( key in directiveOpts ) {
146
160
if ( key === 'ui-floating' && ( value === false || value === true ) && sortableWidgetInstance ) {
147
161
sortableWidgetInstance . floating = value ;
148
162
}
149
163
164
+ if ( key === 'ui-preserve-size' && ( value === false || value === true ) ) {
165
+ var userProvidedHelper = opts . helper ;
166
+ newOpts . helper = function ( e , item ) {
167
+ if ( opts [ 'ui-preserve-size' ] === true ) {
168
+ setItemChildrenWidth ( item ) ;
169
+ }
170
+ return ( userProvidedHelper || dummyHelper ) . apply ( this , arguments ) ;
171
+ } ;
172
+ }
173
+
150
174
opts [ key ] = patchSortableOption ( key , value ) ;
175
+ }
176
+ } ) ;
177
+
178
+ // handle the normal option of the directive
179
+ angular . forEach ( newOpts , function ( value , key ) {
180
+ if ( key in directiveOpts ) {
181
+ // the custom option of the directive are already handled
151
182
return ;
152
183
}
153
184
@@ -206,7 +237,7 @@ angular.module('ui.sortable', [])
206
237
}
207
238
208
239
// thanks jquery-ui
209
- function isFloating ( item ) {
240
+ function isFloating ( item ) {
210
241
return ( / l e f t | r i g h t / ) . test ( item . css ( 'float' ) ) || ( / i n l i n e | t a b l e - c e l l / ) . test ( item . css ( 'display' ) ) ;
211
242
}
212
243
@@ -237,7 +268,8 @@ angular.module('ui.sortable', [])
237
268
// directive specific options
238
269
var directiveOpts = {
239
270
'ui-floating' : undefined ,
240
- 'ui-model-items' : uiSortableConfig . items
271
+ 'ui-model-items' : uiSortableConfig . items ,
272
+ 'ui-preserve-size' : undefined
241
273
} ;
242
274
243
275
var callbacks = {
@@ -489,6 +521,7 @@ angular.module('ui.sortable', [])
489
521
return function ( e , item ) {
490
522
var oldItemSortable = item . sortable ;
491
523
var index = getItemIndex ( item ) ;
524
+
492
525
item . sortable = {
493
526
model : ngModel . $modelValue [ index ] ,
494
527
index : index ,
@@ -513,12 +546,12 @@ angular.module('ui.sortable', [])
513
546
return inner ;
514
547
} ;
515
548
516
- scope . $watchCollection ( 'uiSortable' , function ( newVal , oldVal ) {
549
+ scope . $watchCollection ( 'uiSortable' , function ( newOpts , oldOpts ) {
517
550
// ensure that the jquery-ui-sortable widget instance
518
551
// is still bound to the directive's element
519
552
var sortableWidgetInstance = getSortableWidgetInstance ( element ) ;
520
553
if ( ! ! sortableWidgetInstance ) {
521
- var optsDiff = patchUISortableOptions ( newVal , oldVal , sortableWidgetInstance ) ;
554
+ var optsDiff = patchUISortableOptions ( newOpts , oldOpts , sortableWidgetInstance ) ;
522
555
523
556
if ( optsDiff ) {
524
557
element . sortable ( 'option' , optsDiff ) ;
0 commit comments