|
1 | 1 | /*!
|
2 | 2 | * ui-select
|
3 | 3 | * http://github.com/angular-ui/ui-select
|
4 |
| - * Version: 0.9.7 - 2015-02-13T15:09:21.834Z |
| 4 | + * Version: 0.9.8 - 2015-02-16T15:10:00.887Z |
5 | 5 | * License: MIT
|
6 | 6 | */
|
7 | 7 |
|
|
428 | 428 | }
|
429 | 429 | }
|
430 | 430 | // search ctrl.selected for dupes potentially caused by tagging and return early if found
|
431 |
| - if ( ctrl.selected && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { |
| 431 | + if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) { |
432 | 432 | ctrl.close(skipFocusser);
|
433 | 433 | return;
|
434 | 434 | }
|
|
464 | 464 | // Closes the dropdown
|
465 | 465 | ctrl.close = function(skipFocusser) {
|
466 | 466 | if (!ctrl.open) return;
|
| 467 | + if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched(); |
467 | 468 | _resetSearchInput();
|
468 | 469 | ctrl.open = false;
|
469 | 470 | if (!ctrl.multiple){
|
|
696 | 697 |
|
697 | 698 | });
|
698 | 699 |
|
| 700 | + // If tagging try to split by tokens and add items |
| 701 | + _searchInput.on('paste', function (e) { |
| 702 | + var data = e.originalEvent.clipboardData.getData('text/plain'); |
| 703 | + if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) { |
| 704 | + var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only |
| 705 | + if (items && items.length > 0) { |
| 706 | + angular.forEach(items, function (item) { |
| 707 | + var newItem = ctrl.tagging.fct(item); |
| 708 | + if (newItem) { |
| 709 | + ctrl.select(newItem, true); |
| 710 | + } |
| 711 | + }); |
| 712 | + e.preventDefault(); |
| 713 | + e.stopPropagation(); |
| 714 | + } |
| 715 | + } |
| 716 | + }); |
| 717 | + |
699 | 718 | _searchInput.on('keyup', function(e) {
|
700 | 719 | if ( ! KEY.isVerticalMovement(e.which) ) {
|
701 | 720 | $scope.$evalAsync( function () {
|
|
826 | 845 | }
|
827 | 846 |
|
828 | 847 | function _findApproxDupe(haystack, needle) {
|
829 |
| - var tempArr = angular.copy(haystack); |
830 | 848 | var dupeIndex = -1;
|
831 |
| - for (var i = 0; i <tempArr.length; i++) { |
832 |
| - // handle the simple string version of tagging |
833 |
| - if ( ctrl.tagging.fct === undefined ) { |
834 |
| - // search the array for the match |
835 |
| - if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) { |
836 |
| - dupeIndex = i; |
837 |
| - } |
838 |
| - // handle the object tagging implementation |
839 |
| - } else { |
840 |
| - var mockObj = tempArr[i]; |
841 |
| - mockObj.isTag = true; |
842 |
| - if ( angular.equals(mockObj, needle) ) { |
843 |
| - dupeIndex = i; |
844 |
| - } |
845 |
| - } |
846 |
| - } |
| 849 | + if(angular.isArray(haystack)) { |
| 850 | + var tempArr = angular.copy(haystack); |
| 851 | + for (var i = 0; i <tempArr.length; i++) { |
| 852 | + // handle the simple string version of tagging |
| 853 | + if ( ctrl.tagging.fct === undefined ) { |
| 854 | + // search the array for the match |
| 855 | + if ( tempArr[i]+' '+ctrl.taggingLabel === needle ) { |
| 856 | + dupeIndex = i; |
| 857 | + } |
| 858 | + // handle the object tagging implementation |
| 859 | + } else { |
| 860 | + var mockObj = tempArr[i]; |
| 861 | + mockObj.isTag = true; |
| 862 | + if ( angular.equals(mockObj, needle) ) { |
| 863 | + dupeIndex = i; |
| 864 | + } |
| 865 | + } |
| 866 | + } |
| 867 | + } |
847 | 868 | return dupeIndex;
|
848 | 869 | }
|
849 | 870 |
|
|
880 | 901 | }
|
881 | 902 |
|
882 | 903 | $scope.$on('$destroy', function() {
|
883 |
| - _searchInput.off('keyup keydown tagged blur'); |
| 904 | + _searchInput.off('keyup keydown tagged blur paste'); |
884 | 905 | });
|
885 | 906 | }])
|
886 | 907 |
|
|
960 | 981 | if ($select.multiple){
|
961 | 982 | var resultMultiple = [];
|
962 | 983 | var checkFnMultiple = function(list, value){
|
963 |
| - if (!list || !list.length) return; |
| 984 | + //if the list is empty add the value to the list |
| 985 | + if (!list || !list.length){ |
| 986 | + resultMultiple.unshift(value); |
| 987 | + return true; |
| 988 | + } |
964 | 989 | for (var p = list.length - 1; p >= 0; p--) {
|
965 | 990 | locals[$select.parserResult.itemName] = list[p];
|
966 | 991 | result = $select.parserResult.modelMapper(scope, locals);
|
|
1205 | 1230 |
|
1206 | 1231 | var transcludedMatch = transcluded.querySelectorAll('.ui-select-match');
|
1207 | 1232 | transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
|
| 1233 | + transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes |
1208 | 1234 | if (transcludedMatch.length !== 1) {
|
1209 | 1235 | throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
|
1210 | 1236 | }
|
1211 | 1237 | element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch);
|
1212 | 1238 |
|
1213 | 1239 | var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices');
|
1214 | 1240 | transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
|
| 1241 | + transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes |
1215 | 1242 | if (transcludedChoices.length !== 1) {
|
1216 | 1243 | throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
|
1217 | 1244 | }
|
|
1344 | 1371 |
|
1345 | 1372 | 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=\"listbox\" ng-show=\"$select.items.length > 0\"><li class=\"ui-select-choices-group\" id=\"ui-select-choices-{{ $select.generatedId }}\"><div class=\"divider\" ng-show=\"$select.isGrouped && $index > 0\"></div><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label dropdown-header\" ng-bind=\"$group.name\"></div><div id=\"ui-select-choices-row-{{ $select.generatedId }}-{{$index}}\" class=\"ui-select-choices-row\" ng-class=\"{active: $select.isActive(this), disabled: $select.isDisabled(this)}\" role=\"option\"><a href=\"javascript:void(0)\" class=\"ui-select-choices-row-inner\"></a></div></li></ul>");
|
1346 | 1373 | $templateCache.put("bootstrap/match-multiple.tpl.html","<span class=\"ui-select-match\"><span ng-repeat=\"$item in $select.selected\"><span 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, \'select-locked\':$select.isLocked(this, $index)}\"><span class=\"close ui-select-match-close\" ng-hide=\"$select.disabled\" ng-click=\"$select.removeChoice($index)\"> ×</span> <span uis-transclude-append=\"\"></span></span></span></span>");
|
1347 |
| -$templateCache.put("bootstrap/match.tpl.html","<div class=\"ui-select-match\" ng-hide=\"$select.open\" ng-disabled=\"$select.disabled\" ng-class=\"{\'btn-default-focus\':$select.focus}\"><button aria-label=\"{{ $select.baseTitle }} activate\" type=\"button\" class=\"btn btn-default btn-block ui-select-toggle\" tabindex=\"-1\" ;=\"\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activate()\"><span ng-show=\"$select.isEmpty()\" class=\"ui-select-placeholder text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"ui-select-match-text\" ng-class=\"{\'ui-select-allow-clear\': $select.allowClear && !$select.isEmpty()}\" ng-transclude=\"\"></span> <i class=\"caret pull-right\" ng-click=\"$select.toggle($event)\"></i></button><button aria-label=\"{{ $select.baseTitle }} clear\" type=\"button\" class=\"ui-select-clear\" ng-if=\"$select.allowClear && !$select.isEmpty()\" ng-click=\"$select.select(undefined)\"><i class=\"glyphicon glyphicon-remove\"></i></button></div>"); |
| 1374 | +$templateCache.put("bootstrap/match.tpl.html","<div class=\"ui-select-match\" ng-hide=\"$select.open\" ng-disabled=\"$select.disabled\" ng-class=\"{\'btn-default-focus\':$select.focus}\"><button aria-label=\"{{ $select.baseTitle }} activate\" type=\"button\" class=\"btn btn-default form-control ui-select-toggle\" tabindex=\"-1\" ;=\"\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activate()\"><span ng-show=\"$select.isEmpty()\" class=\"ui-select-placeholder text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"ui-select-match-text\" ng-class=\"{\'ui-select-allow-clear\': $select.allowClear && !$select.isEmpty()}\" ng-transclude=\"\"></span> <i class=\"caret pull-right\" ng-click=\"$select.toggle($event)\"></i></button><button aria-label=\"{{ $select.baseTitle }} clear\" type=\"button\" class=\"ui-select-clear\" ng-if=\"$select.allowClear && !$select.isEmpty()\" ng-click=\"$select.select(undefined)\"><i class=\"glyphicon glyphicon-remove\"></i></button></div>"); |
1348 | 1375 | $templateCache.put("bootstrap/select-multiple.tpl.html","<div class=\"ui-select-container 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\" role=\"combobox\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div></div>");
|
1349 | 1376 | $templateCache.put("bootstrap/select.tpl.html","<div class=\"ui-select-container ui-select-bootstrap dropdown\" ng-class=\"{open: $select.open}\"><div class=\"ui-select-match\"></div><input type=\"text\" autocomplete=\"off\" tabindex=\"-1\" aria-expanded=\"true\" aria-label=\"{{ $select.baseTitle }}\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" 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>");
|
1350 | 1377 | $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.choiceGrouped($group) }\"><div ng-show=\"$select.choiceGrouped($group)\" class=\"ui-select-choices-group-label select2-result-label\" ng-bind=\"$group.name\"></div><ul role=\"listbox\" id=\"ui-select-choices-{{ $select.generatedId }}\" ng-class=\"{\'select2-result-sub\': $select.choiceGrouped($group), \'select2-result-single\': !$select.choiceGrouped($group) }\"><li role=\"option\" id=\"ui-select-choices-row-{{ $select.generatedId }}-{{$index}}\" 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>");
|
|
0 commit comments