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 - 2017-03-08T04:21:53.759Z
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 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
@@ -236,16 +237,10 @@ uis.directive('uiSelectChoices',
236
237
237
238
238
239
$select . parseRepeatAttr ( attrs . repeat , groupByExp , groupFilterExp ) ; //Result ready at $select.parserResult
239
-
240
240
$select . disableChoiceExpression = attrs . uiDisableChoice ;
241
241
$select . onHighlightCallback = attrs . onHighlight ;
242
-
243
242
$select . dropdownPosition = attrs . position ? attrs . position . toLowerCase ( ) : uiSelectConfig . dropdownPosition ;
244
243
245
- scope . $on ( '$destroy' , function ( ) {
246
- choices . remove ( ) ;
247
- } ) ;
248
-
249
244
scope . $watch ( '$select.search' , function ( newValue ) {
250
245
if ( newValue && ! $select . open && $select . multiple ) $select . activate ( false , true ) ;
251
246
$select . activeIndex = $select . tagging . isActivated ? - 1 : 0 ;
@@ -265,8 +260,9 @@ uis.directive('uiSelectChoices',
265
260
scope . $watch ( '$select.open' , function ( open ) {
266
261
if ( open ) {
267
262
tElement . attr ( 'role' , 'listbox' ) ;
263
+ $select . refresh ( attrs . refresh ) ;
268
264
} else {
269
- tElement . removeAttr ( 'role' ) ;
265
+ element . removeAttr ( 'role' ) ;
270
266
}
271
267
} ) ;
272
268
} ;
@@ -297,7 +293,6 @@ uis.controller('uiSelectCtrl',
297
293
ctrl . refreshing = false ;
298
294
ctrl . spinnerEnabled = uiSelectConfig . spinnerEnabled ;
299
295
ctrl . spinnerClass = uiSelectConfig . spinnerClass ;
300
-
301
296
ctrl . removeSelected = uiSelectConfig . removeSelected ; //If selected item(s) should be removed from dropdown list
302
297
ctrl . closeOnSelect = true ; //Initialized inside uiSelect directive link function
303
298
ctrl . skipFocusser = false ; //Set to true to avoid returning focus to ctrl when item is selected
@@ -391,11 +386,8 @@ uis.controller('uiSelectCtrl',
391
386
if ( ! avoidReset ) _resetSearchInput ( ) ;
392
387
393
388
$scope . $broadcast ( 'uis:activate' ) ;
394
-
395
389
ctrl . open = true ;
396
-
397
390
ctrl . activeIndex = ctrl . activeIndex >= ctrl . items . length ? 0 : ctrl . activeIndex ;
398
-
399
391
// ensure that the index is set to zero for tagging variants
400
392
// that where first option is auto-selected
401
393
if ( ctrl . activeIndex === - 1 && ctrl . taggingLabel !== false ) {
@@ -533,7 +525,6 @@ uis.controller('uiSelectCtrl',
533
525
if ( ctrl . dropdownPosition === 'auto' || ctrl . dropdownPosition === 'up' ) {
534
526
$scope . calculateDropdownPos ( ) ;
535
527
}
536
-
537
528
$scope . $broadcast ( 'uis:refresh' ) ;
538
529
} ;
539
530
@@ -581,7 +572,7 @@ uis.controller('uiSelectCtrl',
581
572
var refreshPromise = $scope . $eval ( refreshAttr ) ;
582
573
if ( refreshPromise && angular . isFunction ( refreshPromise . then ) && ! ctrl . refreshing ) {
583
574
ctrl . refreshing = true ;
584
- refreshPromise . then ( function ( ) {
575
+ refreshPromise . finally ( function ( ) {
585
576
ctrl . refreshing = false ;
586
577
} ) ;
587
578
} } , ctrl . refreshDelay ) ;
@@ -706,20 +697,12 @@ uis.controller('uiSelectCtrl',
706
697
ctrl . close ( skipFocusser ) ;
707
698
return ;
708
699
}
709
- }
700
+ } else if ( typeof item === 'string' ) {
701
+ item = item . replace ( ctrl . taggingLabel , '' ) . trim ( ) ;
702
+ }
710
703
_resetSearchInput ( ) ;
711
704
$scope . $broadcast ( 'uis:select' , item ) ;
712
705
713
- var locals = { } ;
714
- locals [ ctrl . parserResult . itemName ] = item ;
715
-
716
- $timeout ( function ( ) {
717
- ctrl . onSelectCallback ( $scope , {
718
- $item : item ,
719
- $model : ctrl . parserResult . modelMapper ( $scope , locals )
720
- } ) ;
721
- } ) ;
722
-
723
706
if ( ctrl . closeOnSelect ) {
724
707
ctrl . close ( skipFocusser ) ;
725
708
}
@@ -782,7 +765,7 @@ uis.controller('uiSelectCtrl',
782
765
}
783
766
784
767
if ( ! isLocked && lockedItemIndex > - 1 ) {
785
- lockedItems . splice ( lockedItemIndex , 0 ) ;
768
+ lockedItems . splice ( lockedItemIndex , 1 ) ;
786
769
}
787
770
}
788
771
@@ -852,11 +835,22 @@ uis.controller('uiSelectCtrl',
852
835
switch ( key ) {
853
836
case KEY . DOWN :
854
837
if ( ! ctrl . open && ctrl . multiple ) ctrl . activate ( false , true ) ; //In case its the search input in 'multiple' mode
855
- else if ( ctrl . activeIndex < ctrl . items . length - 1 ) { ctrl . activeIndex ++ ; }
838
+ else if ( ctrl . activeIndex < ctrl . items . length - 1 ) {
839
+ var idx = ++ ctrl . activeIndex ;
840
+ while ( _isItemDisabled ( ctrl . items [ idx ] ) && idx < ctrl . items . length ) {
841
+ ctrl . activeIndex = ++ idx ;
842
+ }
843
+ }
856
844
break ;
857
845
case KEY . UP :
846
+ var minActiveIndex = ( ctrl . search . length === 0 && ctrl . tagging . isActivated ) ? - 1 : 0 ;
858
847
if ( ! ctrl . open && ctrl . multiple ) ctrl . activate ( false , true ) ; //In case its the search input in 'multiple' mode
859
- else if ( ctrl . activeIndex > 0 || ( ctrl . search . length === 0 && ctrl . tagging . isActivated && ctrl . activeIndex > - 1 ) ) { ctrl . activeIndex -- ; }
848
+ else if ( ctrl . activeIndex > minActiveIndex ) {
849
+ var idxmin = -- ctrl . activeIndex ;
850
+ while ( _isItemDisabled ( ctrl . items [ idxmin ] ) && idxmin > minActiveIndex ) {
851
+ ctrl . activeIndex = -- idxmin ;
852
+ }
853
+ }
860
854
break ;
861
855
case KEY . TAB :
862
856
if ( ! ctrl . multiple || ctrl . open ) ctrl . select ( ctrl . items [ ctrl . activeIndex ] , true ) ;
@@ -1117,6 +1111,12 @@ uis.directive('uiSelect',
1117
1111
$select . sortable = sortable !== undefined ? sortable : uiSelectConfig . sortable ;
1118
1112
} ) ;
1119
1113
1114
+ attrs . $observe ( 'backspaceReset' , function ( ) {
1115
+ // $eval() is needed otherwise we get a string instead of a boolean
1116
+ var backspaceReset = scope . $eval ( attrs . backspaceReset ) ;
1117
+ $select . backspaceReset = backspaceReset !== undefined ? backspaceReset : true ;
1118
+ } ) ;
1119
+
1120
1120
attrs . $observe ( 'limit' , function ( ) {
1121
1121
//Limit the number of selections allowed
1122
1122
$select . limit = ( angular . isDefined ( attrs . limit ) ) ? parseInt ( attrs . limit , 10 ) : undefined ;
@@ -1679,6 +1679,15 @@ uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelec
1679
1679
return ;
1680
1680
}
1681
1681
$select . selected . push ( item ) ;
1682
+ var locals = { } ;
1683
+ locals [ $select . parserResult . itemName ] = item ;
1684
+
1685
+ $timeout ( function ( ) {
1686
+ $select . onSelectCallback ( scope , {
1687
+ $item : item ,
1688
+ $model : $select . parserResult . modelMapper ( scope , locals )
1689
+ } ) ;
1690
+ } ) ;
1682
1691
$selectMultiple . updateModel ( ) ;
1683
1692
} ) ;
1684
1693
@@ -2022,6 +2031,15 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
2022
2031
2023
2032
scope . $on ( 'uis:select' , function ( event , item ) {
2024
2033
$select . selected = item ;
2034
+ var locals = { } ;
2035
+ locals [ $select . parserResult . itemName ] = item ;
2036
+
2037
+ $timeout ( function ( ) {
2038
+ $select . onSelectCallback ( scope , {
2039
+ $item : item ,
2040
+ $model : $select . parserResult . modelMapper ( scope , locals )
2041
+ } ) ;
2042
+ } ) ;
2025
2043
} ) ;
2026
2044
2027
2045
scope . $on ( 'uis:close' , function ( event , skipFocusser ) {
@@ -2056,7 +2074,7 @@ uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $comp
2056
2074
} ) ;
2057
2075
focusser . bind ( "keydown" , function ( e ) {
2058
2076
2059
- if ( e . which === KEY . BACKSPACE ) {
2077
+ if ( e . which === KEY . BACKSPACE && $select . backspaceReset !== false ) {
2060
2078
e . preventDefault ( ) ;
2061
2079
e . stopPropagation ( ) ;
2062
2080
$select . select ( undefined ) ;
0 commit comments