1
1
/*!
2
2
* ui-select
3
3
* http://github.com/angular-ui/ui-select
4
- * Version: 0.19.5 - 2016-10-24T23:13:59.434Z
4
+ * Version: 0.19.6 - 2016-11-08T10:09:40.868Z
5
5
* License: MIT
6
6
*/
7
7
@@ -118,7 +118,8 @@ var uis = angular.module('ui.select', [])
118
118
} ,
119
119
appendToBody : false ,
120
120
spinnerEnabled : false ,
121
- spinnerClass : 'glyphicon-refresh ui-select-spin'
121
+ spinnerClass : 'glyphicon-refresh ui-select-spin' ,
122
+ backspaceReset : true
122
123
} )
123
124
124
125
// See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
@@ -179,6 +180,31 @@ var uis = angular.module('ui.select', [])
179
180
} ;
180
181
} ] ) ;
181
182
183
+ /**
184
+ * Debounces functions
185
+ *
186
+ * Taken from UI Bootstrap $$debounce source code
187
+ * See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js
188
+ *
189
+ */
190
+ uis . factory ( '$$uisDebounce' , [ '$timeout' , function ( $timeout ) {
191
+ return function ( callback , debounceTime ) {
192
+ var timeoutPromise ;
193
+
194
+ return function ( ) {
195
+ var self = this ;
196
+ var args = Array . prototype . slice . call ( arguments ) ;
197
+ if ( timeoutPromise ) {
198
+ $timeout . cancel ( timeoutPromise ) ;
199
+ }
200
+
201
+ timeoutPromise = $timeout ( function ( ) {
202
+ callback . apply ( self , args ) ;
203
+ } , debounceTime ) ;
204
+ } ;
205
+ } ;
206
+ } ] ) ;
207
+
182
208
uis . directive ( 'uiSelectChoices' ,
183
209
[ 'uiSelectConfig' , 'uisRepeatParser' , 'uiSelectMinErr' , '$compile' , '$window' ,
184
210
function ( uiSelectConfig , RepeatParser , uiSelectMinErr , $compile , $window ) {
@@ -236,10 +262,8 @@ uis.directive('uiSelectChoices',
236
262
237
263
238
264
$select . parseRepeatAttr ( attrs . repeat , groupByExp , groupFilterExp ) ; //Result ready at $select.parserResult
239
-
240
265
$select . disableChoiceExpression = attrs . uiDisableChoice ;
241
266
$select . onHighlightCallback = attrs . onHighlight ;
242
-
243
267
$select . dropdownPosition = attrs . position ? attrs . position . toLowerCase ( ) : uiSelectConfig . dropdownPosition ;
244
268
245
269
scope . $on ( '$destroy' , function ( ) {
@@ -249,7 +273,7 @@ uis.directive('uiSelectChoices',
249
273
scope . $watch ( '$select.search' , function ( newValue ) {
250
274
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
251
275
$select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
252
- if ( ! attrs . minimumInputLength || $select . search . length >= attrs . minimumInputLength ) {
276
+ if ( ( ! attrs . minimumInputLength || $select . search . length >= attrs . minimumInputLength ) ) {
253
277
$select . refresh ( attrs . refresh ) ;
254
278
} else {
255
279
$select . items = [ ] ;
@@ -261,10 +285,11 @@ uis.directive('uiSelectChoices',
261
285
var refreshDelay = scope . $eval ( attrs . refreshDelay ) ;
262
286
$select . refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig . refreshDelay ;
263
287
} ) ;
264
-
288
+
265
289
scope . $watch ( '$select.open' , function ( open ) {
266
290
if ( open ) {
267
291
tElement . attr ( 'role' , 'listbox' ) ;
292
+ $select . refresh ( attrs . refresh ) ;
268
293
} else {
269
294
tElement . removeAttr ( 'role' ) ;
270
295
}
@@ -391,11 +416,8 @@ uis.controller('uiSelectCtrl',
391
416
if ( ! avoidReset ) _resetSearchInput ( ) ;
392
417
393
418
$scope . $broadcast ( 'uis:activate' ) ;
394
-
395
419
ctrl . open = true ;
396
-
397
420
ctrl . activeIndex = ctrl . activeIndex >= ctrl . items . length ? 0 : ctrl . activeIndex ;
398
-
399
421
// ensure that the index is set to zero for tagging variants
400
422
// that where first option is auto-selected
401
423
if ( ctrl . activeIndex === - 1 && ctrl . taggingLabel !== false ) {
@@ -533,7 +555,6 @@ uis.controller('uiSelectCtrl',
533
555
if ( ctrl . dropdownPosition === 'auto' || ctrl . dropdownPosition === 'up' ) {
534
556
$scope . calculateDropdownPos ( ) ;
535
557
}
536
-
537
558
$scope . $broadcast ( 'uis:refresh' ) ;
538
559
} ;
539
560
@@ -581,7 +602,7 @@ uis.controller('uiSelectCtrl',
581
602
var refreshPromise = $scope . $eval ( refreshAttr ) ;
582
603
if ( refreshPromise && angular . isFunction ( refreshPromise . then ) && ! ctrl . refreshing ) {
583
604
ctrl . refreshing = true ;
584
- refreshPromise . then ( function ( ) {
605
+ refreshPromise . finally ( function ( ) {
585
606
ctrl . refreshing = false ;
586
607
} ) ;
587
608
} } , ctrl . refreshDelay ) ;
@@ -706,7 +727,7 @@ uis.controller('uiSelectCtrl',
706
727
ctrl . close ( skipFocusser ) ;
707
728
return ;
708
729
}
709
- }
730
+ }
710
731
_resetSearchInput ( ) ;
711
732
$scope . $broadcast ( 'uis:select' , item ) ;
712
733
@@ -782,7 +803,7 @@ uis.controller('uiSelectCtrl',
782
803
}
783
804
784
805
if ( ! isLocked && lockedItemIndex > - 1 ) {
785
- lockedItems . splice ( lockedItemIndex , 0 ) ;
806
+ lockedItems . splice ( lockedItemIndex , 1 ) ;
786
807
}
787
808
}
788
809
@@ -1117,6 +1138,12 @@ uis.directive('uiSelect',
1117
1138
$select . sortable = sortable !== undefined ? sortable : uiSelectConfig . sortable ;
1118
1139
} ) ;
1119
1140
1141
+ attrs . $observe ( 'backspaceReset' , function ( ) {
1142
+ // $eval() is needed otherwise we get a string instead of a boolean
1143
+ var backspaceReset = scope . $eval ( attrs . backspaceReset ) ;
1144
+ $select . backspaceReset = backspaceReset !== undefined ? backspaceReset : true ;
1145
+ } ) ;
1146
+
1120
1147
attrs . $observe ( 'limit' , function ( ) {
1121
1148
//Limit the number of selections allowed
1122
1149
$select . limit = ( angular . isDefined ( attrs . limit ) ) ? parseInt ( attrs . limit , 10 ) : undefined ;
@@ -2056,7 +2083,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
2056
2083
} ) ;
2057
2084
focusser . bind ( "keydown" , function ( e ) {
2058
2085
2059
- if ( e . which === KEY . BACKSPACE ) {
2086
+ if ( e . which === KEY . BACKSPACE && $select . backspaceReset !== false ) {
2060
2087
e . preventDefault ( ) ;
2061
2088
e . stopPropagation ( ) ;
2062
2089
$select . select ( undefined ) ;
@@ -2243,31 +2270,6 @@ uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', f
2243
2270
} ;
2244
2271
} ] ) ;
2245
2272
2246
- /**
2247
- * Debounces functions
2248
- *
2249
- * Taken from UI Bootstrap $$debounce source code
2250
- * See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js
2251
- *
2252
- */
2253
- uis . factory ( '$$uisDebounce' , [ '$timeout' , function ( $timeout ) {
2254
- return function ( callback , debounceTime ) {
2255
- var timeoutPromise ;
2256
-
2257
- return function ( ) {
2258
- var self = this ;
2259
- var args = Array . prototype . slice . call ( arguments ) ;
2260
- if ( timeoutPromise ) {
2261
- $timeout . cancel ( timeoutPromise ) ;
2262
- }
2263
-
2264
- timeoutPromise = $timeout ( function ( ) {
2265
- callback . apply ( self , args ) ;
2266
- } , debounceTime ) ;
2267
- } ;
2268
- } ;
2269
- } ] ) ;
2270
-
2271
2273
uis . directive ( 'uisOpenClose' , [ '$parse' , '$timeout' , function ( $parse , $timeout ) {
2272
2274
return {
2273
2275
restrict : 'A' ,
0 commit comments