1
1
/*!
2
2
* ui-select
3
3
* http://github.com/angular-ui/ui-select
4
- * Version: 0.7 .0 - 2014-09-09T01:02:43.608Z
4
+ * Version: 0.8 .0 - 2014-10-06T23:55:23.047Z
5
5
* License: MIT
6
6
*/
7
7
164
164
ctrl . resetSearchInput = undefined ; // Initialized inside uiSelect directive link function
165
165
ctrl . refreshDelay = undefined ; // Initialized inside uiSelectChoices directive link function
166
166
ctrl . multiple = false ; // Initialized inside uiSelect directive link function
167
+ ctrl . disableChoiceExpression = undefined ; // Initialized inside uiSelect directive link function
167
168
168
169
ctrl . isEmpty = function ( ) {
169
170
return angular . isUndefined ( ctrl . selected ) || ctrl . selected === null || ctrl . selected === '' ;
268
269
if ( ctrl . multiple ) {
269
270
//Remove already selected items
270
271
$scope . $watchCollection ( '$select.selected' , function ( selectedItems ) {
271
- if ( ! selectedItems ) return ;
272
+ if ( ! selectedItems . length ) return ;
272
273
var data = ctrl . parserResult . source ( $scope ) ;
273
274
var filteredItems = data . filter ( function ( i ) { return selectedItems . indexOf ( i ) < 0 ; } ) ;
274
275
setItemsFn ( filteredItems ) ;
276
+ ctrl . sizeSearchInput ( ) ;
275
277
} ) ;
276
278
}
277
279
307
309
return ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) === ctrl . activeIndex ;
308
310
} ;
309
311
312
+ ctrl . isDisabled = function ( itemScope ) {
313
+ var itemIndex = ctrl . items . indexOf ( itemScope [ ctrl . itemProperty ] ) ;
314
+ var isDisabled = false ;
315
+ var item ;
316
+
317
+ if ( itemIndex >= 0 && ! angular . isUndefined ( ctrl . disableChoiceExpression ) ) {
318
+ item = ctrl . items [ itemIndex ] ;
319
+ isDisabled = ! ! ( itemScope . $eval ( ctrl . disableChoiceExpression ) ) ; // force the boolean value
320
+ item . _uiSelectChoiceDisabled = isDisabled ; // store this for later reference
321
+ }
322
+
323
+ return isDisabled ;
324
+ } ;
325
+
310
326
// When the user clicks on an item inside the dropdown
311
327
ctrl . select = function ( item ) {
312
328
313
- var locals = { } ;
314
- locals [ ctrl . parserResult . itemName ] = item ;
329
+ if ( ! item . _uiSelectChoiceDisabled ) {
330
+ var locals = { } ;
331
+ locals [ ctrl . parserResult . itemName ] = item ;
315
332
316
- ctrl . onSelectCallback ( $scope , {
317
- $item : item ,
318
- $model : ctrl . parserResult . modelMapper ( $scope , locals )
319
- } ) ;
333
+ ctrl . onSelectCallback ( $scope , {
334
+ $item : item ,
335
+ $model : ctrl . parserResult . modelMapper ( $scope , locals )
336
+ } ) ;
320
337
321
- if ( ctrl . multiple ) {
322
- ctrl . selected . push ( item ) ;
323
- ctrl . sizeSearchInput ( ) ;
324
- } else {
325
- ctrl . selected = item ;
338
+ if ( ctrl . multiple ) {
339
+ ctrl . selected . push ( item ) ;
340
+ ctrl . sizeSearchInput ( ) ;
341
+ } else {
342
+ ctrl . selected = item ;
343
+ }
344
+ ctrl . close ( ) ;
326
345
}
327
- ctrl . close ( ) ;
328
346
} ;
329
347
330
348
// Closes the dropdown
338
356
}
339
357
} ;
340
358
359
+ // Toggle dropdown
360
+ ctrl . toggle = function ( e ) {
361
+ if ( ctrl . open ) ctrl . close ( ) ; else ctrl . activate ( ) ;
362
+ e . preventDefault ( ) ;
363
+ e . stopPropagation ( ) ;
364
+ } ;
365
+
341
366
// Remove item from multiple select
342
367
ctrl . removeChoice = function ( index ) {
343
368
ctrl . selected . splice ( index , 1 ) ;
550
575
var $select = ctrls [ 0 ] ;
551
576
var ngModel = ctrls [ 1 ] ;
552
577
578
+ var searchInput = element . querySelectorAll ( 'input.ui-select-search' ) ;
579
+
553
580
$select . multiple = angular . isDefined ( attrs . multiple ) ;
554
581
555
582
$select . onSelectCallback = $parse ( attrs . onSelect ) ;
560
587
result ;
561
588
if ( $select . multiple ) {
562
589
var resultMultiple = [ ] ;
563
- for ( var j = inputValue . length - 1 ; j >= 0 ; j -- ) {
590
+ for ( var j = $select . selected . length - 1 ; j >= 0 ; j -- ) {
564
591
locals = { } ;
565
- locals [ $select . parserResult . itemName ] = inputValue [ j ] ;
592
+ locals [ $select . parserResult . itemName ] = $select . selected [ j ] ;
566
593
result = $select . parserResult . modelMapper ( scope , locals ) ;
567
594
resultMultiple . unshift ( result ) ;
568
595
}
625
652
626
653
//Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954
627
654
var focusser = angular . element ( "<input ng-disabled='$select.disabled' class='ui-select-focusser ui-select-offscreen' type='text' aria-haspopup='true' role='button' />" ) ;
655
+
656
+ if ( attrs . tabindex ) {
657
+ //tabindex might be an expression, wait until it contains the actual value before we set the focusser tabindex
658
+ attrs . $observe ( 'tabindex' , function ( value ) {
659
+ //If we are using multiple, add tabindex to the search input
660
+ if ( $select . multiple ) {
661
+ searchInput . attr ( "tabindex" , value ) ;
662
+ } else {
663
+ focusser . attr ( "tabindex" , value ) ;
664
+ }
665
+ //Remove the tabindex on the parent so that it is not focusable
666
+ element . removeAttr ( "tabindex" ) ;
667
+ } ) ;
668
+ }
669
+
628
670
$compile ( focusser ) ( scope ) ;
629
671
$select . focusser = focusser ;
630
672
696
738
} ) ;
697
739
698
740
if ( $select . multiple ) {
699
- scope . $watchCollection ( '$select.selected' , function ( newValue ) {
700
- //On v1.2.19 the 2nd and 3rd parameteres are ignored
701
- //On v1.3.0-beta+ 3rd parameter (revalidate) is true, to force $parsers to recreate model
702
- ngModel . $setViewValue ( newValue , null , true ) ;
741
+ scope . $watchCollection ( '$select.selected' , function ( ) {
742
+ ngModel . $setViewValue ( Date . now ( ) ) ; //Set timestamp as a unique string to force changes
703
743
} ) ;
704
744
focusser . prop ( 'disabled' , true ) ; //Focusser isn't needed if multiple
705
745
} else {
802
842
803
843
$select . parseRepeatAttr ( attrs . repeat , groupByExp ) ; //Result ready at $select.parserResult
804
844
845
+ $select . disableChoiceExpression = attrs . uiDisableChoice ;
846
+
805
847
if ( groupByExp ) {
806
848
var groups = element . querySelectorAll ( '.ui-select-choices-group' ) ;
807
849
if ( groups . length !== 1 ) throw uiSelectMinErr ( 'rows' , "Expected 1 .ui-select-choices-group but got '{0}'." , groups . length ) ;
890
932
} ) ;
891
933
} ( ) ) ;
892
934
893
- angular . module ( "ui.select" ) . run ( [ "$templateCache" , function ( $templateCache ) { $templateCache . put ( "bootstrap/choices.tpl.html" , "<ul class=\"ui-select-choices ui-select-choices-content dropdown-menu\" role=\"menu\" aria-labelledby=\"dLabel\" ng-show=\"$select.items.length > 0\"><li class=\"ui-select-choices-group\"><div class=\"divider\" ng-show=\"$select.isGrouped && $index > 0\"></div><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label dropdown-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this)}\"><a href=\"javascript:void(0)\" class=\"ui-select-choices-row-inner\"></a></div></li></ul>" ) ;
894
- $templateCache . put ( "bootstrap/match-multiple.tpl.html" , "<span class=\"ui-select-match\"><span ng-repeat=\"$item in $select.selected\"><button style=\"margin-right: 3px;\" class=\"ui-select-match-item btn btn-default btn-xs\" tabindex=\"-1\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activeMatchIndex = $index;\" ng-class=\"{\'btn-primary\':$select.activeMatchIndex === $index}\"><span class=\"close ui-select-match-close\" ng-hide=\"$select.disabled\" ng-click=\"$select.removeChoice($index)\"> ×</span> <span uis-transclude-append=\"\"></span></button></span></span>" ) ;
895
- $templateCache . put ( "bootstrap/match.tpl.html" , "<button type=\"button\" class=\"btn btn-default form-control ui-select-match\" tabindex=\"-1\" ng-hide=\"$select.open\" ng-disabled=\"$select.disabled\" ng-class=\"{\'btn-default-focus\':$select.focus}\" ;=\"\" ng-click=\"$select.activate()\"><span ng-show=\"$select.searchEnabled && $select.isEmpty()\" class=\"text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" ng-transclude=\"\"></span> <span class=\"caret\"></span></button>" ) ;
935
+ angular . module ( "ui.select" ) . run ( [ "$templateCache" , function ( $templateCache ) { $templateCache . put ( "bootstrap/choices.tpl.html" , "<ul class=\"ui-select-choices ui-select-choices-content dropdown-menu\" role=\"menu\" aria-labelledby=\"dLabel\" ng-show=\"$select.items.length > 0\"><li class=\"ui-select-choices-group\"><div class=\"divider\" ng-show=\"$select.isGrouped && $index > 0\"></div><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label dropdown-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this) }\"><a href=\"javascript:void(0)\" class=\"ui-select-choices-row-inner\"></a></div></li></ul>" ) ;
936
+ $templateCache . put ( "bootstrap/match-multiple.tpl.html" , "<span class=\"ui-select-match\"><span ng-repeat=\"$item in $select.selected\"><button style=\"margin-right: 3px;\" class=\"ui-select-match-item btn btn-default btn-xs\" tabindex=\"-1\" type=\"button\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activeMatchIndex = $index;\" ng-class=\"{\'btn-primary\':$select.activeMatchIndex === $index}\"><span class=\"close ui-select-match-close\" ng-hide=\"$select.disabled\" ng-click=\"$select.removeChoice($index)\"> ×</span> <span uis-transclude-append=\"\"></span></button></span></span>" ) ;
937
+ $templateCache . put ( "bootstrap/match.tpl.html" , "<button type=\"button\" class=\"btn btn-default form-control ui-select-match\" tabindex=\"-1\" ng-hide=\"$select.open\" ng-disabled=\"$select.disabled\" ng-class=\"{\'btn-default-focus\':$select.focus}\" ;=\"\" ng-click=\"$select.activate()\"><span ng-show=\"$select.searchEnabled && $select.isEmpty()\" class=\"text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" ng-transclude=\"\"></span> <span class=\"caret ui-select-toggle\" ng-click=\"$select.toggle($event) \"></span></button>" ) ;
896
938
$templateCache . put ( "bootstrap/select-multiple.tpl.html" , "<div class=\"ui-select-multiple ui-select-bootstrap dropdown form-control\" ng-class=\"{open: $select.open}\"><div><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search input-xs\" placeholder=\"{{$select.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-hide=\"$select.disabled\" ng-click=\"$select.activate()\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div>" ) ;
897
939
$templateCache . put ( "bootstrap/select.tpl.html" , "<div class=\"ui-select-bootstrap dropdown\" ng-class=\"{open: $select.open}\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"form-control ui-select-search\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-show=\"$select.searchEnabled && $select.open\"><div class=\"ui-select-choices\"></div></div>" ) ;
898
- $templateCache . put ( "select2/choices.tpl.html" , "<ul class=\"ui-select-choices ui-select-choices-content select2-results\"><li class=\"ui-select-choices-group\" ng-class=\"{\'select2-result-with-children\': $select.isGrouped}\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label select2-result-label\">{{$group.name}}</div><ul ng-class=\"{\'select2-result-sub\': $select.isGrouped, \'select2-result-single\': !$select.isGrouped}\"><li class=\"ui-select-choices-row\" ng-class=\"{\'select2-highlighted\': $select.isActive(this)}\"><div class=\"select2-result-label ui-select-choices-row-inner\"></div></li></ul></li></ul>" ) ;
899
- $templateCache . put ( "select2/match-multiple.tpl.html" , "<span class=\"ui-select-match\"><li class=\"ui-select-match-item select2-search-choice\" ng-repeat=\"$item in $select.selected\" ng-class=\"{\'select2-search-choice-focus\':$select.activeMatchIndex === $index}\"><span uis-transclude-append=\"\"></span> <a href=\"# \" class=\"ui-select-match-close select2-search-choice-close\" ng-click=\"$select.removeChoice($index)\" tabindex=\"-1\"></a></li></span>" ) ;
900
- $templateCache . put ( "select2/match.tpl.html" , "<a class=\"select2-choice ui-select-match\" ng-class=\"{\'select2-default\': $select.isEmpty()}\" ng-click=\"$select.activate()\"><span ng-show=\"$select.searchEnabled && $select.isEmpty()\" class=\"select2-chosen\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"select2-chosen\" ng-transclude=\"\"></span> <span class=\"select2-arrow\"><b></b></span></a>" ) ;
940
+ $templateCache . put ( "select2/choices.tpl.html" , "<ul class=\"ui-select-choices ui-select-choices-content select2-results\"><li class=\"ui-select-choices-group\" ng-class=\"{\'select2-result-with-children\': $select.isGrouped}\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label select2-result-label\">{{$group.name}}</div><ul ng-class=\"{\'select2-result-sub\': $select.isGrouped, \'select2-result-single\': !$select.isGrouped}\"><li class=\"ui-select-choices-row\" ng-class=\"{\'select2-highlighted\': $select.isActive(this), \'select2-disabled\': $select.isDisabled(this) }\"><div class=\"select2-result-label ui-select-choices-row-inner\"></div></li></ul></li></ul>" ) ;
941
+ $templateCache . put ( "select2/match-multiple.tpl.html" , "<span class=\"ui-select-match\"><li class=\"ui-select-match-item select2-search-choice\" ng-repeat=\"$item in $select.selected\" ng-class=\"{\'select2-search-choice-focus\':$select.activeMatchIndex === $index}\"><span uis-transclude-append=\"\"></span> <a href=\"javascript:; \" class=\"ui-select-match-close select2-search-choice-close\" ng-click=\"$select.removeChoice($index)\" tabindex=\"-1\"></a></li></span>" ) ;
942
+ $templateCache . put ( "select2/match.tpl.html" , "<a class=\"select2-choice ui-select-match\" ng-class=\"{\'select2-default\': $select.isEmpty()}\" ng-click=\"$select.activate()\"><span ng-show=\"$select.searchEnabled && $select.isEmpty()\" class=\"select2-chosen\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"select2-chosen\" ng-transclude=\"\"></span> <span class=\"select2-arrow ui-select-toggle\" ng-click=\"$select.toggle($event) \"><b></b></span></a>" ) ;
901
943
$templateCache . put ( "select2/select-multiple.tpl.html" , "<div class=\"ui-select-multiple select2 select2-container select2-container-multi\" ng-class=\"{\'select2-container-active select2-dropdown-open\': $select.open,\n \'select2-container-disabled\': $select.disabled}\"><ul class=\"select2-choices\"><span class=\"ui-select-match\"></span><li class=\"select2-search-field\"><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"select2-input ui-select-search\" placeholder=\"{{$select.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-hide=\"$select.disabled\" ng-model=\"$select.search\" ng-click=\"$select.activate()\" style=\"width: 34px;\"></li></ul><div class=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"ui-select-choices\"></div></div></div>" ) ;
902
944
$templateCache . put ( "select2/select.tpl.html" , "<div class=\"select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open\': $select.open,\n \'select2-container-disabled\': $select.disabled,\n \'select2-container-active\': $select.focus }\"><div class=\"ui-select-match\"></div><div class=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"select2-search\" ng-show=\"$select.searchEnabled\"><input type=\"text\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div></div></div>" ) ;
903
- $templateCache . put ( "selectize/choices.tpl.html" , "<div ng-show=\"$select.open\" class=\"ui-select-choices selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this)}\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>" ) ;
945
+ $templateCache . put ( "selectize/choices.tpl.html" , "<div ng-show=\"$select.open\" class=\"ui-select-choices selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\">{{$group.name}}</div><div class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this) }\"><div class=\"option ui-select-choices-row-inner\" data-selectable=\"\"></div></div></div></div></div>" ) ;
904
946
$templateCache . put ( "selectize/match.tpl.html" , "<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>" ) ;
905
- $templateCache . put ( "selectize/select.tpl.html" , "<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>" ) ; } ] ) ;
947
+ $templateCache . put ( "selectize/select.tpl.html" , "<div class=\"selectize-control single\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.activate()\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-click=\"$select.toggle($event) \" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.searchEnabled || ($select.selected && !$select.open)\" ng-disabled=\"$select.disabled\"></div><div class=\"ui-select-choices\"></div></div>" ) ; } ] ) ;
0 commit comments