3 * http://github.com/angular-ui/ui-select
4 * Version: 0.19.3 - 2016-08-17T06:16:41.345Z
31 MAP: { 91 : "COMMAND", 8 : "BACKSPACE" , 9 : "TAB" , 13 : "ENTER" , 16 : "SHIFT" , 17 : "CTRL" , 18 : "ALT" , 19 : "PAUSEBREAK" , 20 : "CAPSLOCK" , 27 : "ESC" , 32 : "SPACE" , 33 : "PAGE_UP", 34 : "PAGE_DOWN" , 35 : "END" , 36 : "HOME" , 37 : "LEFT" , 38 : "UP" , 39 : "RIGHT" , 40 : "DOWN" , 43 : "+" , 44 : "PRINTSCREEN" , 45 : "INSERT" , 46 : "DELETE", 48 : "0" , 49 : "1" , 50 : "2" , 51 : "3" , 52 : "4" , 53 : "5" , 54 : "6" , 55 : "7" , 56 : "8" , 57 : "9" , 59 : ";", 61 : "=" , 65 : "A" , 66 : "B" , 67 : "C" , 68 : "D" , 69 : "E" , 70 : "F" , 71 : "G" , 72 : "H" , 73 : "I" , 74 : "J" , 75 : "K" , 76 : "L", 77 : "M" , 78 : "N" , 79 : "O" , 80 : "P" , 81 : "Q" , 82 : "R" , 83 : "S" , 84 : "T" , 85 : "U" , 86 : "V" , 87 : "W" , 88 : "X" , 89 : "Y" , 90 : "Z", 96 : "0" , 97 : "1" , 98 : "2" , 99 : "3" , 100 : "4" , 101 : "5" , 102 : "6" , 103 : "7" , 104 : "8" , 105 : "9", 106 : "*" , 107 : "+" , 109 : "-" , 110 : "." , 111 : "/", 112 : "F1" , 113 : "F2" , 114 : "F3" , 115 : "F4" , 116 : "F5" , 117 : "F6" , 118 : "F7" , 119 : "F8" , 120 : "F9" , 121 : "F10" , 122 : "F11" , 123 : "F12", 144 : "NUMLOCK" , 145 : "SCROLLLOCK" , 186 : ";" , 187 : "=" , 188 : "," , 189 : "-" , 190 : "." , 191 : "/" , 192 : "`" , 219 : "[" , 220 : "\\" , 221 : "]" , 222 : "'"
34 isControl: function (e) {
44 if (e.metaKey || e.ctrlKey || e.altKey) return true;
48 isFunctionKey: function (k) {
49 k = k.which ? k.which : k;
50 return k >= 112 && k <= 123;
52 isVerticalMovement: function (k){
53 return ~[KEY.UP, KEY.DOWN].indexOf(k);
55 isHorizontalMovement: function (k){
56 return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k);
58 toSeparator: function (k) {
59 var sep = {ENTER:"\n",TAB:"\t",SPACE:" "}[k];
61 // return undefined for special keys other than enter, tab or space.
62 // no way to use them to cut strings.
63 return KEY[k] ? undefined : k;
68 * Add querySelectorAll() to jqLite.
70 * jqLite find() is limited to lookups by tag name.
71 * TODO This will change with future versions of AngularJS, to be removed when this happens
73 * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586
74 * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598
76 if (angular.element.prototype.querySelectorAll === undefined) {
77 angular.element.prototype.querySelectorAll = function(selector) {
78 return angular.element(this[0].querySelectorAll(selector));
83 * Add closest() to jqLite.
85 if (angular.element.prototype.closest === undefined) {
86 angular.element.prototype.closest = function( selector) {
88 var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector;
91 if (matchesSelector.bind(elem)(selector)) {
94 elem = elem.parentElement;
103 var uis = angular.module('ui.select', [])
105 .constant('uiSelectConfig', {
109 placeholder: '', // Empty by default, like HTML tag <select>
110 refreshDelay: 1000, // In milliseconds
113 dropdownPosition: 'auto',
114 removeSelected: true,
115 resetSearchInput: true,
116 generateId: function() {
122 // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
123 .service('uiSelectMinErr', function() {
124 var minErr = angular.$$minErr('ui.select');
126 var error = minErr.apply(this, arguments);
127 var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), '');
128 return new Error(message);
132 // Recreates old behavior of ng-transclude. Used internally.
133 .directive('uisTranscludeAppend', function () {
135 link: function (scope, element, attrs, ctrl, transclude) {
136 transclude(scope, function (clone) {
137 element.append(clone);
144 * Highlights text that matches $select.search.
146 * Taken from AngularUI Bootstrap Typeahead
147 * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340
149 .filter('highlight', function() {
150 function escapeRegexp(queryToEscape) {
151 return ('' + queryToEscape).replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
154 return function(matchItem, query) {
155 return query && matchItem ? ('' + matchItem).replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
160 * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/
162 * Taken from AngularUI Bootstrap Position:
163 * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70
165 .factory('uisOffset',
166 ['$document', '$window',
167 function ($document, $window) {
169 return function(element) {
170 var boundingClientRect = element[0].getBoundingClientRect();
172 width: boundingClientRect.width || element.prop('offsetWidth'),
173 height: boundingClientRect.height || element.prop('offsetHeight'),
174 top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop),
175 left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft)
180 uis.directive('uiSelectChoices',
181 ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile', '$window',
182 function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile, $window) {
186 require: '^uiSelect',
189 templateUrl: function(tElement) {
190 // Needed so the uiSelect can detect the transcluded content
191 tElement.addClass('ui-select-choices');
193 // Gets theme attribute from parent (ui-select)
194 var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
195 return theme + '/choices.tpl.html';
198 compile: function(tElement, tAttrs) {
200 if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
202 // var repeat = RepeatParser.parse(attrs.repeat);
203 var groupByExp = tAttrs.groupBy;
204 var groupFilterExp = tAttrs.groupFilter;
207 var groups = tElement.querySelectorAll('.ui-select-choices-group');
208 if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length);
209 groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression());
212 var parserResult = RepeatParser.parse(tAttrs.repeat);
214 var choices = tElement.querySelectorAll('.ui-select-choices-row');
215 if (choices.length !== 1) {
216 throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length);
219 choices.attr('ng-repeat', parserResult.repeatExpression(groupByExp))
220 .attr('ng-if', '$select.open'); //Prevent unnecessary watches when dropdown is closed
223 var rowsInner = tElement.querySelectorAll('.ui-select-choices-row-inner');
224 if (rowsInner.length !== 1) {
225 throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length);
227 rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat
229 // If IE8 then need to target rowsInner to apply the ng-click attr as choices will not capture the event.
230 var clickTarget = $window.document.addEventListener ? choices : rowsInner;
231 clickTarget.attr('ng-click', '$select.select(' + parserResult.itemName + ',$select.skipFocusser,$event)');
233 return function link(scope, element, attrs, $select) {
236 $select.parseRepeatAttr(attrs.repeat, groupByExp, groupFilterExp); //Result ready at $select.parserResult
238 $select.disableChoiceExpression = attrs.uiDisableChoice;
239 $select.onHighlightCallback = attrs.onHighlight;
241 $select.dropdownPosition = attrs.position ? attrs.position.toLowerCase() : uiSelectConfig.dropdownPosition;
243 scope.$on('$destroy', function() {
247 scope.$watch('$select.search', function(newValue) {
248 if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
249 $select.activeIndex = $select.tagging.isActivated ? -1 : 0;
250 if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) {
251 $select.refresh(attrs.refresh);
257 attrs.$observe('refreshDelay', function() {
258 // $eval() is needed otherwise we get a string instead of a number
259 var refreshDelay = scope.$eval(attrs.refreshDelay);
260 $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay;
268 * Contains ui-select "intelligence".
270 * The goal is to limit dependency on the DOM whenever possible and
271 * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
273 uis.controller('uiSelectCtrl',
274 ['$scope', '$element', '$timeout', '$filter', '$$uisDebounce', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig', '$parse', '$injector', '$window',
275 function($scope, $element, $timeout, $filter, $$uisDebounce, RepeatParser, uiSelectMinErr, uiSelectConfig, $parse, $injector, $window) {
279 var EMPTY_SEARCH = '';
281 ctrl.placeholder = uiSelectConfig.placeholder;
282 ctrl.searchEnabled = uiSelectConfig.searchEnabled;
283 ctrl.sortable = uiSelectConfig.sortable;
284 ctrl.refreshDelay = uiSelectConfig.refreshDelay;
285 ctrl.paste = uiSelectConfig.paste;
286 ctrl.resetSearchInput = uiSelectConfig.resetSearchInput;
288 ctrl.removeSelected = uiSelectConfig.removeSelected; //If selected item(s) should be removed from dropdown list
289 ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function
290 ctrl.skipFocusser = false; //Set to true to avoid returning focus to ctrl when item is selected
291 ctrl.search = EMPTY_SEARCH;
293 ctrl.activeIndex = 0; //Dropdown of choices
294 ctrl.items = []; //All available choices
298 ctrl.disabled = false;
299 ctrl.selected = undefined;
301 ctrl.dropdownPosition = 'auto';
303 ctrl.focusser = undefined; //Reference to input element used to handle focus events
304 ctrl.multiple = undefined; // Initialized inside uiSelect directive link function
305 ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function
306 ctrl.tagging = {isActivated: false, fct: undefined};
307 ctrl.taggingTokens = {isActivated: false, tokens: undefined};
308 ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function
309 ctrl.clickTriggeredSelect = false;
310 ctrl.$filter = $filter;
311 ctrl.$element = $element;
313 // Use $injector to check for $animate and store a reference to it
314 ctrl.$animate = (function () {
316 return $injector.get('$animate');
318 // $animate does not exist
323 ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
324 if (ctrl.searchInput.length !== 1) {
325 throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
328 ctrl.isEmpty = function() {
329 return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '' || (ctrl.multiple && ctrl.selected.length === 0);
332 function _findIndex(collection, predicate, thisArg){
333 if (collection.findIndex){
334 return collection.findIndex(predicate, thisArg);
336 var list = Object(collection);
337 var length = list.length >>> 0;
340 for (var i = 0; i < length; i++) {
342 if (predicate.call(thisArg, value, i, list)) {
350 // Most of the time the user does not want to empty the search input when in typeahead mode
351 function _resetSearchInput() {
352 if (ctrl.resetSearchInput) {
353 ctrl.search = EMPTY_SEARCH;
355 if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
356 ctrl.activeIndex = _findIndex(ctrl.items, function(item){
357 return angular.equals(this, item);
363 function _groupsFilter(groups, groupNames) {
364 var i, j, result = [];
365 for(i = 0; i < groupNames.length ;i++){
366 for(j = 0; j < groups.length ;j++){
367 if(groups[j].name == [groupNames[i]]){
368 result.push(groups[j]);
375 // When the user clicks on ui-select, displays the dropdown list
376 ctrl.activate = function(initSearchValue, avoidReset) {
377 if (!ctrl.disabled && !ctrl.open) {
378 if(!avoidReset) _resetSearchInput();
380 $scope.$broadcast('uis:activate');
384 ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
386 // ensure that the index is set to zero for tagging variants
387 // that where first option is auto-selected
388 if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
389 ctrl.activeIndex = 0;
392 var container = $element.querySelectorAll('.ui-select-choices-content');
393 var searchInput = $element.querySelectorAll('.ui-select-search');
394 if (ctrl.$animate && ctrl.$animate.on && ctrl.$animate.enabled(container[0])) {
395 var animateHandler = function(elem, phase) {
396 if (phase === 'start' && ctrl.items.length === 0) {
397 // Only focus input after the animation has finished
398 ctrl.$animate.off('removeClass', searchInput[0], animateHandler);
399 $timeout(function () {
400 ctrl.focusSearchInput(initSearchValue);
402 } else if (phase === 'close') {
403 // Only focus input after the animation has finished
404 ctrl.$animate.off('enter', container[0], animateHandler);
405 $timeout(function () {
406 ctrl.focusSearchInput(initSearchValue);
411 if (ctrl.items.length > 0) {
412 ctrl.$animate.on('enter', container[0], animateHandler);
414 ctrl.$animate.on('removeClass', searchInput[0], animateHandler);
417 $timeout(function () {
418 ctrl.focusSearchInput(initSearchValue);
419 if(!ctrl.tagging.isActivated && ctrl.items.length > 1) {
420 _ensureHighlightVisible();
425 else if (ctrl.open && !ctrl.searchEnabled) {
426 // Close the selection if we don't have search enabled, and we click on the select again
431 ctrl.focusSearchInput = function (initSearchValue) {
432 ctrl.search = initSearchValue || ctrl.search;
433 ctrl.searchInput[0].focus();
436 ctrl.findGroupByName = function(name) {
437 return ctrl.groups && ctrl.groups.filter(function(group) {
438 return group.name === name;
442 ctrl.parseRepeatAttr = function(repeatAttr, groupByExp, groupFilterExp) {
443 function updateGroups(items) {
444 var groupFn = $scope.$eval(groupByExp);
446 angular.forEach(items, function(item) {
447 var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn];
448 var group = ctrl.findGroupByName(groupName);
450 group.items.push(item);
453 ctrl.groups.push({name: groupName, items: [item]});
457 var groupFilterFn = $scope.$eval(groupFilterExp);
458 if( angular.isFunction(groupFilterFn)){
459 ctrl.groups = groupFilterFn(ctrl.groups);
460 } else if(angular.isArray(groupFilterFn)){
461 ctrl.groups = _groupsFilter(ctrl.groups, groupFilterFn);
465 ctrl.groups.forEach(function(group) {
466 ctrl.items = ctrl.items.concat(group.items);
470 function setPlainItems(items) {
474 ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems;
476 ctrl.parserResult = RepeatParser.parse(repeatAttr);
478 ctrl.isGrouped = !!groupByExp;
479 ctrl.itemProperty = ctrl.parserResult.itemName;
481 //If collection is an Object, convert it to Array
483 var originalSource = ctrl.parserResult.source;
485 //When an object is used as source, we better create an array and use it as 'source'
486 var createArrayFromObject = function(){
487 var origSrc = originalSource($scope);
488 $scope.$uisSource = Object.keys(origSrc).map(function(v){
490 result[ctrl.parserResult.keyName] = v;
491 result.value = origSrc[v];
496 if (ctrl.parserResult.keyName){ // Check for (key,value) syntax
497 createArrayFromObject();
498 ctrl.parserResult.source = $parse('$uisSource' + ctrl.parserResult.filters);
499 $scope.$watch(originalSource, function(newVal, oldVal){
500 if (newVal !== oldVal) createArrayFromObject();
504 ctrl.refreshItems = function (data){
505 data = data || ctrl.parserResult.source($scope);
506 var selectedItems = ctrl.selected;
507 //TODO should implement for single mode removeSelected
508 if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.multiple || !ctrl.removeSelected) {
509 ctrl.setItemsFn(data);
511 if ( data !== undefined && data !== null ) {
512 var filteredItems = data.filter(function(i) {
513 return angular.isArray(selectedItems) ? selectedItems.every(function(selectedItem) {
514 return !angular.equals(i, selectedItem);
515 }) : !angular.equals(i, selectedItems);
517 ctrl.setItemsFn(filteredItems);
520 if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){
521 $scope.calculateDropdownPos();
524 $scope.$broadcast('uis:refresh');
527 // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259
528 $scope.$watchCollection(ctrl.parserResult.source, function(items) {
529 if (items === undefined || items === null) {
530 // If the user specifies undefined or null => reset the collection
531 // Special case: items can be undefined if the user did not initialized the collection on the scope
532 // i.e $scope.addresses = [] is missing
535 if (!angular.isArray(items)) {
536 throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
538 //Remove already selected items (ex: while searching)
539 //TODO Should add a test
540 ctrl.refreshItems(items);
542 //update the view value with fresh data from items, if there is a valid model value
543 if(angular.isDefined(ctrl.ngModel.$modelValue)) {
544 ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
552 var _refreshDelayPromise;
555 * Typeahead mode: lets the user refresh the collection using his own function.
557 * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31
559 ctrl.refresh = function(refreshAttr) {
560 if (refreshAttr !== undefined) {
563 // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155
564 // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177
565 if (_refreshDelayPromise) {
566 $timeout.cancel(_refreshDelayPromise);
568 _refreshDelayPromise = $timeout(function() {
569 $scope.$eval(refreshAttr);
570 }, ctrl.refreshDelay);
574 ctrl.isActive = function(itemScope) {
578 var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
579 var isActive = itemIndex == ctrl.activeIndex;
581 if ( !isActive || itemIndex < 0 ) {
585 if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) {
586 itemScope.$eval(ctrl.onHighlightCallback);
592 var _isItemSelected = function (item) {
593 return (ctrl.selected && angular.isArray(ctrl.selected) &&
594 ctrl.selected.filter(function (selection) { return angular.equals(selection, item); }).length > 0);
597 var disabledItems = [];
599 function _updateItemDisabled(item, isDisabled) {
600 var disabledItemIndex = disabledItems.indexOf(item);
601 if (isDisabled && disabledItemIndex === -1) {
602 disabledItems.push(item);
605 if (!isDisabled && disabledItemIndex > -1) {
606 disabledItems.splice(disabledItemIndex, 1);
610 function _isItemDisabled(item) {
611 return disabledItems.indexOf(item) > -1;
614 ctrl.isDisabled = function(itemScope) {
616 if (!ctrl.open) return;
618 var item = itemScope[ctrl.itemProperty];
619 var itemIndex = ctrl.items.indexOf(item);
620 var isDisabled = false;
622 if (itemIndex >= 0 && (angular.isDefined(ctrl.disableChoiceExpression) || ctrl.multiple)) {
624 if (item.isTag) return false;
627 isDisabled = _isItemSelected(item);
630 if (!isDisabled && angular.isDefined(ctrl.disableChoiceExpression)) {
631 isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression));
634 _updateItemDisabled(item, isDisabled);
641 // When the user selects an item with ENTER or clicks the dropdown
642 ctrl.select = function(item, skipFocusser, $event) {
643 if (item === undefined || !_isItemDisabled(item)) {
645 if ( ! ctrl.items && ! ctrl.search && ! ctrl.tagging.isActivated) return;
647 if (!item || !_isItemDisabled(item)) {
648 // if click is made on existing item, prevent from tagging, ctrl.search does not matter
649 ctrl.clickTriggeredSelect = false;
650 if($event && $event.type === 'click' && item)
651 ctrl.clickTriggeredSelect = true;
653 if(ctrl.tagging.isActivated && ctrl.clickTriggeredSelect === false) {
654 // if taggingLabel is disabled and item is undefined we pull from ctrl.search
655 if ( ctrl.taggingLabel === false ) {
656 if ( ctrl.activeIndex < 0 ) {
657 if (item === undefined) {
658 item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
660 if (!item || angular.equals( ctrl.items[0], item ) ) {
664 // keyboard nav happened first, user selected from dropdown
665 item = ctrl.items[ctrl.activeIndex];
668 // tagging always operates at index zero, taggingLabel === false pushes
669 // the ctrl.search value without having it injected
670 if ( ctrl.activeIndex === 0 ) {
671 // ctrl.tagging pushes items to ctrl.items, so we only have empty val
672 // for `item` if it is a detected duplicate
673 if ( item === undefined ) return;
675 // create new item on the fly if we don't already have one;
676 // use tagging function if we have one
677 if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) {
678 item = ctrl.tagging.fct(item);
680 // if item type is 'string', apply the tagging label
681 } else if ( typeof item === 'string' ) {
682 // trim the trailing space
683 item = item.replace(ctrl.taggingLabel,'').trim();
687 // search ctrl.selected for dupes potentially caused by tagging and return early if found
688 if (_isItemSelected(item)) {
689 ctrl.close(skipFocusser);
694 $scope.$broadcast('uis:select', item);
697 locals[ctrl.parserResult.itemName] = item;
700 ctrl.onSelectCallback($scope, {
702 $model: ctrl.parserResult.modelMapper($scope, locals)
706 if (ctrl.closeOnSelect) {
707 ctrl.close(skipFocusser);
713 // Closes the dropdown
714 ctrl.close = function(skipFocusser) {
715 if (!ctrl.open) return;
716 if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
719 $scope.$broadcast('uis:close', skipFocusser);
723 ctrl.setFocus = function(){
724 if (!ctrl.focus) ctrl.focusInput[0].focus();
727 ctrl.clear = function($event) {
728 ctrl.select(undefined);
729 $event.stopPropagation();
730 $timeout(function() {
731 ctrl.focusser[0].focus();
736 ctrl.toggle = function(e) {
746 // Set default function for locked choices - avoids unnecessary
747 // logic if functionality is not being used
748 ctrl.isLocked = function () {
752 $scope.$watch(function () {
753 return angular.isDefined(ctrl.lockChoiceExpression) && ctrl.lockChoiceExpression !== "";
754 }, _initaliseLockedChoices);
756 function _initaliseLockedChoices(doInitalise) {
757 if(!doInitalise) return;
759 var lockedItems = [];
761 function _updateItemLocked(item, isLocked) {
762 var lockedItemIndex = lockedItems.indexOf(item);
763 if (isLocked && lockedItemIndex === -1) {
764 lockedItems.push(item);
767 if (!isLocked && lockedItemIndex > -1) {
768 lockedItems.splice(lockedItemIndex, 0);
772 function _isItemlocked(item) {
773 return lockedItems.indexOf(item) > -1;
776 ctrl.isLocked = function (itemScope, itemIndex) {
777 var isLocked = false,
778 item = ctrl.selected[itemIndex];
782 isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression));
783 _updateItemLocked(item, isLocked);
785 isLocked = _isItemlocked(item);
794 var sizeWatch = null;
795 var updaterScheduled = false;
796 ctrl.sizeSearchInput = function() {
798 var input = ctrl.searchInput[0],
799 container = ctrl.searchInput.parent().parent()[0],
800 calculateContainerWidth = function() {
801 // Return the container width only if the search input is visible
802 return container.clientWidth * !!input.offsetParent;
804 updateIfVisible = function(containerWidth) {
805 if (containerWidth === 0) {
808 var inputWidth = containerWidth - input.offsetLeft - 10;
809 if (inputWidth < 50) inputWidth = containerWidth;
810 ctrl.searchInput.css('width', inputWidth+'px');
814 ctrl.searchInput.css('width', '10px');
815 $timeout(function() { //Give tags time to render correctly
816 if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
817 sizeWatch = $scope.$watch(function() {
818 if (!updaterScheduled) {
819 updaterScheduled = true;
820 $scope.$$postDigest(function() {
821 updaterScheduled = false;
822 if (updateIfVisible(calculateContainerWidth())) {
833 function _handleDropDownSelection(key) {
834 var processed = true;
837 if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
838 else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; }
841 if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
842 else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) { ctrl.activeIndex--; }
845 if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
848 if(ctrl.open && (ctrl.tagging.isActivated || ctrl.activeIndex >= 0)){
849 ctrl.select(ctrl.items[ctrl.activeIndex], ctrl.skipFocusser); // Make sure at least one dropdown item is highlighted before adding if not in tagging mode
851 ctrl.activate(false, true); //In case its the search input in 'multiple' mode
863 // Bind to keyboard shortcuts
864 ctrl.searchInput.on('keydown', function(e) {
868 if (~[KEY.ENTER,KEY.ESC].indexOf(key)){
873 // if(~[KEY.ESC,KEY.TAB].indexOf(key)){
878 $scope.$apply(function() {
882 if (ctrl.items.length > 0 || ctrl.tagging.isActivated) {
883 if(!_handleDropDownSelection(key) && !ctrl.searchEnabled) {
887 if ( ctrl.taggingTokens.isActivated ) {
888 for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
889 if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) {
890 // make sure there is a new value to push via tagging
891 if ( ctrl.search.length > 0 ) {
897 $timeout(function() {
898 ctrl.searchInput.triggerHandler('tagged');
899 var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim();
900 if ( ctrl.tagging.fct ) {
901 newItem = ctrl.tagging.fct( newItem );
903 if (newItem) ctrl.select(newItem, true);
911 if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){
912 _ensureHighlightVisible();
915 if (key === KEY.ENTER || key === KEY.ESC) {
922 ctrl.searchInput.on('paste', function (e) {
925 if (window.clipboardData && window.clipboardData.getData) { // IE
926 data = window.clipboardData.getData('Text');
928 data = (e.originalEvent || e).clipboardData.getData('text/plain');
931 // Prepend the current input field text to the paste buffer.
932 data = ctrl.search + data;
934 if (data && data.length > 0) {
935 // If tagging try to split by tokens and add items
936 if (ctrl.taggingTokens.isActivated) {
938 for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) { // split by first token that is contained in data
939 var separator = KEY.toSeparator(ctrl.taggingTokens.tokens[i]) || ctrl.taggingTokens.tokens[i];
940 if (data.indexOf(separator) > -1) {
941 items = data.split(separator);
942 break; // only split by one token
945 if (items.length === 0) {
948 var oldsearch = ctrl.search;
949 angular.forEach(items, function (item) {
950 var newItem = ctrl.tagging.fct ? ctrl.tagging.fct(item) : item;
952 ctrl.select(newItem, true);
955 ctrl.search = oldsearch || EMPTY_SEARCH;
958 } else if (ctrl.paste) {
960 ctrl.search = EMPTY_SEARCH;
967 ctrl.searchInput.on('tagged', function() {
968 $timeout(function() {
973 // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431
974 function _ensureHighlightVisible() {
975 var container = $element.querySelectorAll('.ui-select-choices-content');
976 var choices = container.querySelectorAll('.ui-select-choices-row');
977 if (choices.length < 1) {
978 throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length);
981 if (ctrl.activeIndex < 0) {
985 var highlighted = choices[ctrl.activeIndex];
986 var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop;
987 var height = container[0].offsetHeight;
990 container[0].scrollTop += posY - height;
991 } else if (posY < highlighted.clientHeight) {
992 if (ctrl.isGrouped && ctrl.activeIndex === 0)
993 container[0].scrollTop = 0; //To make group header visible when going all the way up
995 container[0].scrollTop -= highlighted.clientHeight - posY;
999 var onResize = $$uisDebounce(function() {
1000 ctrl.sizeSearchInput();
1003 angular.element($window).bind('resize', onResize);
1005 $scope.$on('$destroy', function() {
1006 ctrl.searchInput.off('keyup keydown tagged blur paste');
1007 angular.element($window).off('resize', onResize);
1011 uis.directive('uiSelect',
1012 ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout',
1013 function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) {
1017 templateUrl: function(tElement, tAttrs) {
1018 var theme = tAttrs.theme || uiSelectConfig.theme;
1019 return theme + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html');
1023 require: ['uiSelect', '^ngModel'],
1026 controller: 'uiSelectCtrl',
1027 controllerAs: '$select',
1028 compile: function(tElement, tAttrs) {
1030 // Allow setting ngClass on uiSelect
1031 var match = /{(.*)}\s*{(.*)}/.exec(tAttrs.ngClass);
1033 var combined = '{'+ match[1] +', '+ match[2] +'}';
1034 tAttrs.ngClass = combined;
1035 tElement.attr('ng-class', combined);
1038 //Multiple or Single depending if multiple attribute presence
1039 if (angular.isDefined(tAttrs.multiple))
1040 tElement.append('<ui-select-multiple/>').removeAttr('multiple');
1042 tElement.append('<ui-select-single/>');
1045 tElement.querySelectorAll('input.ui-select-search')[0].id = tAttrs.inputId;
1047 return function(scope, element, attrs, ctrls, transcludeFn) {
1049 var $select = ctrls[0];
1050 var ngModel = ctrls[1];
1052 $select.generatedId = uiSelectConfig.generateId();
1053 $select.baseTitle = attrs.title || 'Select box';
1054 $select.focusserTitle = $select.baseTitle + ' focus';
1055 $select.focusserId = 'focusser-' + $select.generatedId;
1057 $select.closeOnSelect = function() {
1058 if (angular.isDefined(attrs.closeOnSelect)) {
1059 return $parse(attrs.closeOnSelect)();
1061 return uiSelectConfig.closeOnSelect;
1065 scope.$watch('skipFocusser', function() {
1066 var skipFocusser = scope.$eval(attrs.skipFocusser);
1067 $select.skipFocusser = skipFocusser !== undefined ? skipFocusser : uiSelectConfig.skipFocusser;
1070 $select.onSelectCallback = $parse(attrs.onSelect);
1071 $select.onRemoveCallback = $parse(attrs.onRemove);
1073 //Set reference to ngModel from uiSelectCtrl
1074 $select.ngModel = ngModel;
1076 $select.choiceGrouped = function(group){
1077 return $select.isGrouped && group && group.name;
1081 attrs.$observe('tabindex', function(value) {
1082 $select.focusInput.attr('tabindex', value);
1083 element.removeAttr('tabindex');
1087 scope.$watch(function () { return scope.$eval(attrs.searchEnabled); }, function(newVal) {
1088 $select.searchEnabled = newVal !== undefined ? newVal : uiSelectConfig.searchEnabled;
1091 scope.$watch('sortable', function() {
1092 var sortable = scope.$eval(attrs.sortable);
1093 $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable;
1096 attrs.$observe('limit', function() {
1097 //Limit the number of selections allowed
1098 $select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined;
1101 scope.$watch('removeSelected', function() {
1102 var removeSelected = scope.$eval(attrs.removeSelected);
1103 $select.removeSelected = removeSelected !== undefined ? removeSelected : uiSelectConfig.removeSelected;
1106 attrs.$observe('disabled', function() {
1107 // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string
1108 $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false;
1111 attrs.$observe('resetSearchInput', function() {
1112 // $eval() is needed otherwise we get a string instead of a boolean
1113 var resetSearchInput = scope.$eval(attrs.resetSearchInput);
1114 $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true;
1117 attrs.$observe('paste', function() {
1118 $select.paste = scope.$eval(attrs.paste);
1121 attrs.$observe('tagging', function() {
1122 if(attrs.tagging !== undefined)
1124 // $eval() is needed otherwise we get a string instead of a boolean
1125 var taggingEval = scope.$eval(attrs.tagging);
1126 $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined};
1130 $select.tagging = {isActivated: false, fct: undefined};
1134 attrs.$observe('taggingLabel', function() {
1135 if(attrs.tagging !== undefined )
1137 // check eval for FALSE, in this case, we disable the labels
1138 // associated with tagging
1139 if ( attrs.taggingLabel === 'false' ) {
1140 $select.taggingLabel = false;
1144 $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)';
1149 attrs.$observe('taggingTokens', function() {
1150 if (attrs.tagging !== undefined) {
1151 var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER'];
1152 $select.taggingTokens = {isActivated: true, tokens: tokens };
1156 //Automatically gets focus when loaded
1157 if (angular.isDefined(attrs.autofocus)){
1158 $timeout(function(){
1163 //Gets focus based on scope event name (e.g. focus-on='SomeEventName')
1164 if (angular.isDefined(attrs.focusOn)){
1165 scope.$on(attrs.focusOn, function() {
1166 $timeout(function(){
1172 function onDocumentClick(e) {
1173 if (!$select.open) return; //Skip it if dropdown is close
1175 var contains = false;
1177 if (window.jQuery) {
1178 // Firefox 3.6 does not support element.contains()
1179 // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains
1180 contains = window.jQuery.contains(element[0], e.target);
1182 contains = element[0].contains(e.target);
1185 if (!contains && !$select.clickTriggeredSelect) {
1187 if (!$select.skipFocusser) {
1188 //Will lose focus only with certain targets
1189 var focusableControls = ['input','button','textarea','select'];
1190 var targetController = angular.element(e.target).controller('uiSelect'); //To check if target is other ui-select
1191 skipFocusser = targetController && targetController !== $select; //To check if target is other ui-select
1192 if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea
1194 skipFocusser = true;
1196 $select.close(skipFocusser);
1199 $select.clickTriggeredSelect = false;
1202 // See Click everywhere but here event http://stackoverflow.com/questions/12931369
1203 $document.on('click', onDocumentClick);
1205 scope.$on('$destroy', function() {
1206 $document.off('click', onDocumentClick);
1209 // Move transcluded elements to their correct position in main template
1210 transcludeFn(scope, function(clone) {
1211 // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
1213 // One day jqLite will be replaced by jQuery and we will be able to write:
1214 // var transcludedElement = clone.filter('.my-class')
1215 // instead of creating a hackish DOM element:
1216 var transcluded = angular.element('<div>').append(clone);
1218 var transcludedMatch = transcluded.querySelectorAll('.ui-select-match');
1219 transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
1220 transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes
1221 if (transcludedMatch.length !== 1) {
1222 throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
1224 element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch);
1226 var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices');
1227 transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
1228 transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes
1229 if (transcludedChoices.length !== 1) {
1230 throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
1232 element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
1234 var transcludedNoChoice = transcluded.querySelectorAll('.ui-select-no-choice');
1235 transcludedNoChoice.removeAttr('ui-select-no-choice'); //To avoid loop in case directive as attr
1236 transcludedNoChoice.removeAttr('data-ui-select-no-choice'); // Properly handle HTML5 data-attributes
1237 if (transcludedNoChoice.length == 1) {
1238 element.querySelectorAll('.ui-select-no-choice').replaceWith(transcludedNoChoice);
1242 // Support for appending the select field to the body when its open
1243 var appendToBody = scope.$eval(attrs.appendToBody);
1244 if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) {
1245 scope.$watch('$select.open', function(isOpen) {
1253 // Move the dropdown back to its original location when the scope is destroyed. Otherwise
1254 // it might stick around when the user routes away or the select field is otherwise removed
1255 scope.$on('$destroy', function() {
1260 // Hold on to a reference to the .ui-select-container element for appendToBody support
1261 var placeholder = null,
1264 function positionDropdown() {
1265 // Remember the absolute position of the element
1266 var offset = uisOffset(element);
1268 // Clone the element into a placeholder element to take its original place in the DOM
1269 placeholder = angular.element('<div class="ui-select-placeholder"></div>');
1270 placeholder[0].style.width = offset.width + 'px';
1271 placeholder[0].style.height = offset.height + 'px';
1272 element.after(placeholder);
1274 // Remember the original value of the element width inline style, so it can be restored
1275 // when the dropdown is closed
1276 originalWidth = element[0].style.width;
1278 // Now move the actual dropdown element to the end of the body
1279 $document.find('body').append(element);
1281 element[0].style.position = 'absolute';
1282 element[0].style.left = offset.left + 'px';
1283 element[0].style.top = offset.top + 'px';
1284 element[0].style.width = offset.width + 'px';
1287 function resetDropdown() {
1288 if (placeholder === null) {
1289 // The dropdown has not actually been display yet, so there's nothing to reset
1293 // Move the dropdown element back to its original location in the DOM
1294 placeholder.replaceWith(element);
1297 element[0].style.position = '';
1298 element[0].style.left = '';
1299 element[0].style.top = '';
1300 element[0].style.width = originalWidth;
1302 // Set focus back on to the moved element
1306 // Hold on to a reference to the .ui-select-dropdown element for direction support.
1307 var dropdown = null,
1308 directionUpClassName = 'direction-up';
1310 // Support changing the direction of the dropdown if there isn't enough space to render it.
1311 scope.$watch('$select.open', function() {
1313 if ($select.dropdownPosition === 'auto' || $select.dropdownPosition === 'up'){
1314 scope.calculateDropdownPos();
1319 var setDropdownPosUp = function(offset, offsetDropdown){
1321 offset = offset || uisOffset(element);
1322 offsetDropdown = offsetDropdown || uisOffset(dropdown);
1324 dropdown[0].style.position = 'absolute';
1325 dropdown[0].style.top = (offsetDropdown.height * -1) + 'px';
1326 element.addClass(directionUpClassName);
1330 var setDropdownPosDown = function(offset, offsetDropdown){
1332 element.removeClass(directionUpClassName);
1334 offset = offset || uisOffset(element);
1335 offsetDropdown = offsetDropdown || uisOffset(dropdown);
1337 dropdown[0].style.position = '';
1338 dropdown[0].style.top = '';
1342 var calculateDropdownPosAfterAnimation = function() {
1343 // Delay positioning the dropdown until all choices have been added so its height is correct.
1344 $timeout(function() {
1345 if ($select.dropdownPosition === 'up') {
1350 element.removeClass(directionUpClassName);
1352 var offset = uisOffset(element);
1353 var offsetDropdown = uisOffset(dropdown);
1355 //https://code.google.com/p/chromium/issues/detail?id=342307#c4
1356 var scrollTop = $document[0].documentElement.scrollTop || $document[0].body.scrollTop; //To make it cross browser (blink, webkit, IE, Firefox).
1358 // Determine if the direction of the dropdown needs to be changed.
1359 if (offset.top + offset.height + offsetDropdown.height > scrollTop + $document[0].documentElement.clientHeight) {
1361 setDropdownPosUp(offset, offsetDropdown);
1364 setDropdownPosDown(offset, offsetDropdown);
1368 // Display the dropdown once it has been positioned.
1369 dropdown[0].style.opacity = 1;
1375 scope.calculateDropdownPos = function() {
1377 dropdown = angular.element(element).querySelectorAll('.ui-select-dropdown');
1379 if (dropdown.length === 0) {
1383 // Hide the dropdown so there is no flicker until $timeout is done executing.
1384 if ($select.search === '' && !opened) {
1385 dropdown[0].style.opacity = 0;
1389 if (!uisOffset(dropdown).height && $select.$animate && $select.$animate.on && $select.$animate.enabled(dropdown)) {
1390 var needsCalculated = true;
1392 $select.$animate.on('enter', dropdown, function (elem, phase) {
1393 if (phase === 'close' && needsCalculated) {
1394 calculateDropdownPosAfterAnimation();
1395 needsCalculated = false;
1399 calculateDropdownPosAfterAnimation();
1402 if (dropdown === null || dropdown.length === 0) {
1406 // Reset the position of the dropdown.
1407 dropdown[0].style.opacity = 0;
1408 dropdown[0].style.position = '';
1409 dropdown[0].style.top = '';
1410 element.removeClass(directionUpClassName);
1418 uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
1421 require: '^uiSelect',
1424 templateUrl: function(tElement) {
1425 // Needed so the uiSelect can detect the transcluded content
1426 tElement.addClass('ui-select-match');
1428 var parent = tElement.parent();
1429 // Gets theme attribute from parent (ui-select)
1430 var theme = getAttribute(parent, 'theme') || uiSelectConfig.theme;
1431 var multi = angular.isDefined(getAttribute(parent, 'multiple'));
1433 return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
1435 link: function(scope, element, attrs, $select) {
1436 $select.lockChoiceExpression = attrs.uiLockChoice;
1437 attrs.$observe('placeholder', function(placeholder) {
1438 $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
1441 function setAllowClear(allow) {
1442 $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false;
1445 attrs.$observe('allowClear', setAllowClear);
1446 setAllowClear(attrs.allowClear);
1448 if($select.multiple){
1449 $select.sizeSearchInput();
1455 function getAttribute(elem, attribute) {
1456 if (elem[0].hasAttribute(attribute))
1457 return elem.attr(attribute);
1459 if (elem[0].hasAttribute('data-' + attribute))
1460 return elem.attr('data-' + attribute);
1462 if (elem[0].hasAttribute('x-' + attribute))
1463 return elem.attr('x-' + attribute);
1467 uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) {
1470 require: ['^uiSelect', '^ngModel'],
1472 controller: ['$scope','$timeout', function($scope, $timeout){
1475 $select = $scope.$select,
1478 if (angular.isUndefined($select.selected))
1479 $select.selected = [];
1481 //Wait for link fn to inject it
1482 $scope.$evalAsync(function(){ ngModel = $scope.ngModel; });
1484 ctrl.activeMatchIndex = -1;
1486 ctrl.updateModel = function(){
1487 ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
1488 ctrl.refreshComponent();
1491 ctrl.refreshComponent = function(){
1492 //Remove already selected items
1493 //e.g. When user clicks on a selection, the selected array changes and
1494 //the dropdown should remove that item
1495 if($select.refreshItems){
1496 $select.refreshItems();
1498 if($select.sizeSearchInput){
1499 $select.sizeSearchInput();
1503 // Remove item from multiple select
1504 ctrl.removeChoice = function(index){
1506 // if the choice is locked, don't remove it
1507 if($select.isLocked(null, index)) return false;
1509 var removedChoice = $select.selected[index];
1512 locals[$select.parserResult.itemName] = removedChoice;
1514 $select.selected.splice(index, 1);
1515 ctrl.activeMatchIndex = -1;
1516 $select.sizeSearchInput();
1518 // Give some time for scope propagation.
1519 $timeout(function(){
1520 $select.onRemoveCallback($scope, {
1521 $item: removedChoice,
1522 $model: $select.parserResult.modelMapper($scope, locals)
1531 ctrl.getPlaceholder = function(){
1533 if($select.selected && $select.selected.length) return;
1534 return $select.placeholder;
1539 controllerAs: '$selectMultiple',
1541 link: function(scope, element, attrs, ctrls) {
1543 var $select = ctrls[0];
1544 var ngModel = scope.ngModel = ctrls[1];
1545 var $selectMultiple = scope.$selectMultiple;
1547 //$select.selected = raw selected objects (ignoring any property binding)
1549 $select.multiple = true;
1551 //Input that will handle focus
1552 $select.focusInput = $select.searchInput;
1554 //Properly check for empty if set to multiple
1555 ngModel.$isEmpty = function(value) {
1556 return !value || value.length === 0;
1559 //From view --> model
1560 ngModel.$parsers.unshift(function () {
1563 resultMultiple = [];
1564 for (var j = $select.selected.length - 1; j >= 0; j--) {
1566 locals[$select.parserResult.itemName] = $select.selected[j];
1567 result = $select.parserResult.modelMapper(scope, locals);
1568 resultMultiple.unshift(result);
1570 return resultMultiple;
1573 // From model --> view
1574 ngModel.$formatters.unshift(function (inputValue) {
1575 var data = $select.parserResult && $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
1578 if (!data) return inputValue;
1579 var resultMultiple = [];
1580 var checkFnMultiple = function(list, value){
1581 if (!list || !list.length) return;
1582 for (var p = list.length - 1; p >= 0; p--) {
1583 locals[$select.parserResult.itemName] = list[p];
1584 result = $select.parserResult.modelMapper(scope, locals);
1585 if($select.parserResult.trackByExp){
1586 var propsItemNameMatches = /(\w*)\./.exec($select.parserResult.trackByExp);
1587 var matches = /\.([^\s]+)/.exec($select.parserResult.trackByExp);
1588 if(propsItemNameMatches && propsItemNameMatches.length > 0 && propsItemNameMatches[1] == $select.parserResult.itemName){
1589 if(matches && matches.length>0 && result[matches[1]] == value[matches[1]]){
1590 resultMultiple.unshift(list[p]);
1595 if (angular.equals(result,value)){
1596 resultMultiple.unshift(list[p]);
1602 if (!inputValue) return resultMultiple; //If ngModel was undefined
1603 for (var k = inputValue.length - 1; k >= 0; k--) {
1604 //Check model array of currently selected items
1605 if (!checkFnMultiple($select.selected, inputValue[k])){
1606 //Check model array of all items available
1607 if (!checkFnMultiple(data, inputValue[k])){
1608 //If not found on previous lists, just add it directly to resultMultiple
1609 resultMultiple.unshift(inputValue[k]);
1613 return resultMultiple;
1616 //Watch for external model changes
1617 scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) {
1618 if (oldValue != newValue){
1619 //update the view value with fresh data from items, if there is a valid model value
1620 if(angular.isDefined(ngModel.$modelValue)) {
1621 ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
1623 $selectMultiple.refreshComponent();
1627 ngModel.$render = function() {
1628 // Make sure that model value is array
1629 if(!angular.isArray(ngModel.$viewValue)){
1630 // Have tolerance for null or undefined values
1631 if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){
1632 ngModel.$viewValue = [];
1634 throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue);
1637 $select.selected = ngModel.$viewValue;
1638 $selectMultiple.refreshComponent();
1639 scope.$evalAsync(); //To force $digest
1642 scope.$on('uis:select', function (event, item) {
1643 if($select.selected.length >= $select.limit) {
1646 $select.selected.push(item);
1647 $selectMultiple.updateModel();
1650 scope.$on('uis:activate', function () {
1651 $selectMultiple.activeMatchIndex = -1;
1654 scope.$watch('$select.disabled', function(newValue, oldValue) {
1655 // As the search input field may now become visible, it may be necessary to recompute its size
1656 if (oldValue && !newValue) $select.sizeSearchInput();
1659 $select.searchInput.on('keydown', function(e) {
1661 scope.$apply(function() {
1662 var processed = false;
1663 // var tagged = false; //Checkme
1664 if(KEY.isHorizontalMovement(key)){
1665 processed = _handleMatchSelection(key);
1667 if (processed && key != KEY.TAB) {
1668 //TODO Check si el tab selecciona aun correctamente
1671 e.stopPropagation();
1675 function _getCaretPosition(el) {
1676 if(angular.isNumber(el.selectionStart)) return el.selectionStart;
1677 // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise
1678 else return el.value.length;
1680 // Handles selected options in "multiple" mode
1681 function _handleMatchSelection(key){
1682 var caretPosition = _getCaretPosition($select.searchInput[0]),
1683 length = $select.selected.length,
1687 curr = $selectMultiple.activeMatchIndex,
1688 next = $selectMultiple.activeMatchIndex+1,
1689 prev = $selectMultiple.activeMatchIndex-1,
1692 if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false;
1696 function getNewActiveMatchIndex(){
1699 // Select previous/first item
1700 if(~$selectMultiple.activeMatchIndex) return prev;
1706 if(!~$selectMultiple.activeMatchIndex || curr === last){
1710 // Select next/last item
1714 // Remove selected item and select previous/first
1715 if(~$selectMultiple.activeMatchIndex){
1716 if($selectMultiple.removeChoice(curr)) {
1723 // If nothing yet selected, select last item
1728 // Remove selected item and select next item
1729 if(~$selectMultiple.activeMatchIndex){
1730 $selectMultiple.removeChoice($selectMultiple.activeMatchIndex);
1737 newIndex = getNewActiveMatchIndex();
1739 if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1;
1740 else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex));
1745 $select.searchInput.on('keyup', function(e) {
1747 if ( ! KEY.isVerticalMovement(e.which) ) {
1748 scope.$evalAsync( function () {
1749 $select.activeIndex = $select.taggingLabel === false ? -1 : 0;
1752 // Push a "create new" item into array if there is a search string
1753 if ( $select.tagging.isActivated && $select.search.length > 0 ) {
1755 // return early with these keys
1756 if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) {
1759 // always reset the activeIndex to the first item when tagging
1760 $select.activeIndex = $select.taggingLabel === false ? -1 : 0;
1761 // taggingLabel === false bypasses all of this
1762 if ($select.taggingLabel === false) return;
1764 var items = angular.copy( $select.items );
1765 var stashArr = angular.copy( $select.items );
1773 // case for object tagging via transform `$select.tagging.fct` function
1774 if ( $select.tagging.fct !== undefined) {
1775 tagItems = $select.$filter('filter')(items,{'isTag': true});
1776 if ( tagItems.length > 0 ) {
1777 tagItem = tagItems[0];
1779 // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous
1780 if ( items.length > 0 && tagItem ) {
1782 items = items.slice(1,items.length);
1783 stashArr = stashArr.slice(1,stashArr.length);
1785 newItem = $select.tagging.fct($select.search);
1786 // verify the new tag doesn't match the value of a possible selection choice or an already selected item.
1788 stashArr.some(function (origItem) {
1789 return angular.equals(origItem, newItem);
1791 $select.selected.some(function (origItem) {
1792 return angular.equals(origItem, newItem);
1795 scope.$evalAsync(function () {
1796 $select.activeIndex = 0;
1797 $select.items = items;
1801 if (newItem) newItem.isTag = true;
1802 // handle newItem string and stripping dupes in tagging string context
1804 // find any tagging items already in the $select.items array and store them
1805 tagItems = $select.$filter('filter')(items,function (item) {
1806 return item.match($select.taggingLabel);
1808 if ( tagItems.length > 0 ) {
1809 tagItem = tagItems[0];
1812 // remove existing tag item if found (should only ever be one tag item)
1813 if ( item !== undefined && items.length > 0 && tagItem ) {
1815 items = items.slice(1,items.length);
1816 stashArr = stashArr.slice(1,stashArr.length);
1818 newItem = $select.search+' '+$select.taggingLabel;
1819 if ( _findApproxDupe($select.selected, $select.search) > -1 ) {
1822 // verify the the tag doesn't match the value of an existing item from
1823 // the searched data set or the items already selected
1824 if ( _findCaseInsensitiveDupe(stashArr.concat($select.selected)) ) {
1825 // if there is a tag from prev iteration, strip it / queue the change
1829 scope.$evalAsync( function () {
1830 $select.activeIndex = 0;
1831 $select.items = items;
1836 if ( _findCaseInsensitiveDupe(stashArr) ) {
1837 // if there is a tag from prev iteration, strip it
1839 $select.items = stashArr.slice(1,stashArr.length);
1844 if ( hasTag ) dupeIndex = _findApproxDupe($select.selected, newItem);
1845 // dupe found, shave the first item
1846 if ( dupeIndex > -1 ) {
1847 items = items.slice(dupeIndex+1,items.length-1);
1850 if (newItem) items.push(newItem);
1851 items = items.concat(stashArr);
1853 scope.$evalAsync( function () {
1854 $select.activeIndex = 0;
1855 $select.items = items;
1857 if ($select.isGrouped) {
1858 // update item references in groups, so that indexOf will work after angular.copy
1859 var itemsWithoutTag = newItem ? items.slice(1) : items;
1860 $select.setItemsFn(itemsWithoutTag);
1862 // add tag item as a new group
1863 $select.items.unshift(newItem);
1864 $select.groups.unshift({name: '', items: [newItem], tagging: true});
1870 function _findCaseInsensitiveDupe(arr) {
1871 if ( arr === undefined || $select.search === undefined ) {
1874 var hasDupe = arr.filter( function (origItem) {
1875 if ( $select.search.toUpperCase() === undefined || origItem === undefined ) {
1878 return origItem.toUpperCase() === $select.search.toUpperCase();
1883 function _findApproxDupe(haystack, needle) {
1885 if(angular.isArray(haystack)) {
1886 var tempArr = angular.copy(haystack);
1887 for (var i = 0; i <tempArr.length; i++) {
1888 // handle the simple string version of tagging
1889 if ( $select.tagging.fct === undefined ) {
1890 // search the array for the match
1891 if ( tempArr[i]+' '+$select.taggingLabel === needle ) {
1894 // handle the object tagging implementation
1896 var mockObj = tempArr[i];
1897 if (angular.isObject(mockObj)) {
1898 mockObj.isTag = true;
1900 if ( angular.equals(mockObj, needle) ) {
1909 $select.searchInput.on('blur', function() {
1910 $timeout(function() {
1911 $selectMultiple.activeMatchIndex = -1;
1919 uis.directive('uiSelectNoChoice',
1920 ['uiSelectConfig', function (uiSelectConfig) {
1923 require: '^uiSelect',
1926 templateUrl: function (tElement) {
1927 // Needed so the uiSelect can detect the transcluded content
1928 tElement.addClass('ui-select-no-choice');
1930 // Gets theme attribute from parent (ui-select)
1931 var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
1932 return theme + '/no-choice.tpl.html';
1937 uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) {
1940 require: ['^uiSelect', '^ngModel'],
1941 link: function(scope, element, attrs, ctrls) {
1943 var $select = ctrls[0];
1944 var ngModel = ctrls[1];
1946 //From view --> model
1947 ngModel.$parsers.unshift(function (inputValue) {
1950 locals[$select.parserResult.itemName] = inputValue;
1951 result = $select.parserResult.modelMapper(scope, locals);
1955 //From model --> view
1956 ngModel.$formatters.unshift(function (inputValue) {
1957 var data = $select.parserResult && $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
1961 var checkFnSingle = function(d){
1962 locals[$select.parserResult.itemName] = d;
1963 result = $select.parserResult.modelMapper(scope, locals);
1964 return result === inputValue;
1966 //If possible pass same object stored in $select.selected
1967 if ($select.selected && checkFnSingle($select.selected)) {
1968 return $select.selected;
1970 for (var i = data.length - 1; i >= 0; i--) {
1971 if (checkFnSingle(data[i])) return data[i];
1977 //Update viewValue if model change
1978 scope.$watch('$select.selected', function(newValue) {
1979 if (ngModel.$viewValue !== newValue) {
1980 ngModel.$setViewValue(newValue);
1984 ngModel.$render = function() {
1985 $select.selected = ngModel.$viewValue;
1988 scope.$on('uis:select', function (event, item) {
1989 $select.selected = item;
1992 scope.$on('uis:close', function (event, skipFocusser) {
1993 $timeout(function(){
1994 $select.focusser.prop('disabled', false);
1995 if (!skipFocusser) $select.focusser[0].focus();
1999 scope.$on('uis:activate', function () {
2000 focusser.prop('disabled', true); //Will reactivate it on .close()
2003 //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954
2004 var focusser = angular.element("<input ng-disabled='$select.disabled' class='ui-select-focusser ui-select-offscreen' type='text' id='{{ $select.focusserId }}' aria-label='{{ $select.focusserTitle }}' aria-haspopup='true' role='button' />");
2005 $compile(focusser)(scope);
2006 $select.focusser = focusser;
2008 //Input that will handle focus
2009 $select.focusInput = focusser;
2011 element.parent().append(focusser);
2012 focusser.bind("focus", function(){
2013 scope.$evalAsync(function(){
2014 $select.focus = true;
2017 focusser.bind("blur", function(){
2018 scope.$evalAsync(function(){
2019 $select.focus = false;
2022 focusser.bind("keydown", function(e){
2024 if (e.which === KEY.BACKSPACE) {
2026 e.stopPropagation();
2027 $select.select(undefined);
2032 if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
2036 if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){
2038 e.stopPropagation();
2045 focusser.bind("keyup input", function(e){
2047 if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
2051 $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
2062 // Make multiple matches sortable
2063 uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) {
2065 require: ['^^uiSelect', '^ngModel'],
2066 link: function(scope, element, attrs, ctrls) {
2067 if (scope[attrs.uiSelectSort] === null) {
2068 throw uiSelectMinErr('sort', 'Expected a list to sort');
2071 var $select = ctrls[0];
2072 var $ngModel = ctrls[1];
2074 var options = angular.extend({
2077 scope.$eval(attrs.uiSelectSortOptions));
2079 var axis = options.axis;
2080 var draggingClassName = 'dragging';
2081 var droppingClassName = 'dropping';
2082 var droppingBeforeClassName = 'dropping-before';
2083 var droppingAfterClassName = 'dropping-after';
2085 scope.$watch(function(){
2086 return $select.sortable;
2087 }, function(newValue){
2089 element.attr('draggable', true);
2091 element.removeAttr('draggable');
2095 element.on('dragstart', function(event) {
2096 element.addClass(draggingClassName);
2098 (event.dataTransfer || event.originalEvent.dataTransfer).setData('text', scope.$index.toString());
2101 element.on('dragend', function() {
2102 removeClass(draggingClassName);
2105 var move = function(from, to) {
2106 /*jshint validthis: true */
2107 this.splice(to, 0, this.splice(from, 1)[0]);
2110 var removeClass = function(className) {
2111 angular.forEach($select.$element.querySelectorAll('.' + className), function(el){
2112 angular.element(el).removeClass(className);
2116 var dragOverHandler = function(event) {
2117 event.preventDefault();
2119 var offset = axis === 'vertical' ? event.offsetY || event.layerY || (event.originalEvent ? event.originalEvent.offsetY : 0) : event.offsetX || event.layerX || (event.originalEvent ? event.originalEvent.offsetX : 0);
2121 if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) {
2122 removeClass(droppingAfterClassName);
2123 element.addClass(droppingBeforeClassName);
2126 removeClass(droppingBeforeClassName);
2127 element.addClass(droppingAfterClassName);
2133 var dropHandler = function(event) {
2134 event.preventDefault();
2136 var droppedItemIndex = parseInt((event.dataTransfer || event.originalEvent.dataTransfer).getData('text'), 10);
2138 // prevent event firing multiple times in firefox
2139 $timeout.cancel(dropTimeout);
2140 dropTimeout = $timeout(function() {
2141 _dropHandler(droppedItemIndex);
2145 var _dropHandler = function(droppedItemIndex) {
2146 var theList = scope.$eval(attrs.uiSelectSort);
2147 var itemToMove = theList[droppedItemIndex];
2148 var newIndex = null;
2150 if (element.hasClass(droppingBeforeClassName)) {
2151 if (droppedItemIndex < scope.$index) {
2152 newIndex = scope.$index - 1;
2154 newIndex = scope.$index;
2157 if (droppedItemIndex < scope.$index) {
2158 newIndex = scope.$index;
2160 newIndex = scope.$index + 1;
2164 move.apply(theList, [droppedItemIndex, newIndex]);
2166 $ngModel.$setViewValue(Date.now());
2168 scope.$apply(function() {
2169 scope.$emit('uiSelectSort:change', {
2172 from: droppedItemIndex,
2177 removeClass(droppingClassName);
2178 removeClass(droppingBeforeClassName);
2179 removeClass(droppingAfterClassName);
2181 element.off('drop', dropHandler);
2184 element.on('dragenter', function() {
2185 if (element.hasClass(draggingClassName)) {
2189 element.addClass(droppingClassName);
2191 element.on('dragover', dragOverHandler);
2192 element.on('drop', dropHandler);
2195 element.on('dragleave', function(event) {
2196 if (event.target != element) {
2200 removeClass(droppingClassName);
2201 removeClass(droppingBeforeClassName);
2202 removeClass(droppingAfterClassName);
2204 element.off('dragover', dragOverHandler);
2205 element.off('drop', dropHandler);
2212 * Debounces functions
2214 * Taken from UI Bootstrap $$debounce source code
2215 * See https://github.com/angular-ui/bootstrap/blob/master/src/debounce/debounce.js
2218 uis.factory('$$uisDebounce', ['$timeout', function($timeout) {
2219 return function(callback, debounceTime) {
2224 var args = Array.prototype.slice.call(arguments);
2225 if (timeoutPromise) {
2226 $timeout.cancel(timeoutPromise);
2229 timeoutPromise = $timeout(function() {
2230 callback.apply(self, args);
2236 uis.directive('uisOpenClose', ['$parse', '$timeout', function ($parse, $timeout) {
2239 require: 'uiSelect',
2240 link: function (scope, element, attrs, $select) {
2241 $select.onOpenCloseCallback = $parse(attrs.uisOpenClose);
2243 scope.$watch('$select.open', function (isOpen, previousState) {
2244 if (isOpen !== previousState) {
2245 $timeout(function () {
2246 $select.onOpenCloseCallback(scope, {
2257 * Parses "repeat" attribute.
2259 * Taken from AngularJS ngRepeat source code
2260 * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211
2262 * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat:
2263 * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697
2266 uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) {
2271 * expression = "address in addresses | filter: {street: $select.search} track by $index"
2272 * itemName = "address",
2273 * source = "addresses | filter: {street: $select.search}",
2274 * trackByExp = "$index",
2276 self.parse = function(expression) {
2280 //var isObjectCollection = /\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)/.test(expression);
2281 // If an array is used as collection
2283 // if (isObjectCollection){
2284 // 000000000000000000000000000000111111111000000000000000222222222222220033333333333333333333330000444444444444444444000000000000000055555555555000000000000000000000066666666600000000
2285 match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(\s*[\s\S]+?)?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
2289 // 3 Key on (key,value)
2290 // 4 Value on (key,value)
2291 // 5 Source expression (including filters)
2295 throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",
2299 var source = match[5],
2302 // When using (key,value) ui-select requires filters to be extracted, since the object
2303 // is converted to an array for $select.items
2304 // (in which case the filters need to be reapplied)
2306 // Remove any enclosing parenthesis
2307 source = match[5].replace(/(^\()|(\)$)/g, '');
2308 // match all after | but not after ||
2309 var filterMatch = match[5].match(/^\s*(?:[\s\S]+?)(?:[^\|]|\|\|)+([\s\S]*)\s*$/);
2310 if(filterMatch && filterMatch[1].trim()) {
2311 filters = filterMatch[1];
2312 source = source.replace(filters, '');
2317 itemName: match[4] || match[2], // (lhs) Left-hand side,
2318 keyName: match[3], //for (key, value) syntax
2319 source: $parse(source),
2321 trackByExp: match[6],
2322 modelMapper: $parse(match[1] || match[4] || match[2]),
2323 repeatExpression: function (grouped) {
2324 var expression = this.itemName + ' in ' + (grouped ? '$group.items' : '$select.items');
2325 if (this.trackByExp) {
2326 expression += ' track by ' + this.trackByExp;
2334 self.getGroupNgRepeatExpression = function() {
2335 return '$group in $select.groups track by $group.name';
2341 angular.module("ui.select").run(["$templateCache", function($templateCache) {$templateCache.put("bootstrap/choices.tpl.html","<ul class=\"ui-select-choices ui-select-choices-content ui-select-dropdown dropdown-menu\" role=\"listbox\" ng-show=\"$select.open && $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 ng-attr-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\"><span class=\"ui-select-choices-row-inner\"></span></div></li></ul>");
2342 $templateCache.put("bootstrap/match-multiple.tpl.html","<span class=\"ui-select-match\"><span ng-repeat=\"$item in $select.selected track by $index\"><span class=\"ui-select-match-item btn btn-default btn-xs\" tabindex=\"-1\" type=\"button\" ng-disabled=\"$select.disabled\" ng-click=\"$selectMultiple.activeMatchIndex = $index;\" ng-class=\"{\'btn-primary\':$selectMultiple.activeMatchIndex === $index, \'select-locked\':$select.isLocked(this, $index)}\" ui-select-sort=\"$select.selected\"><span class=\"close ui-select-match-close\" ng-hide=\"$select.disabled\" ng-click=\"$selectMultiple.removeChoice($index)\"> ×</span> <span uis-transclude-append=\"\"></span></span></span></span>");
2343 $templateCache.put("bootstrap/match.tpl.html","<div class=\"ui-select-match\" ng-hide=\"$select.open && $select.searchEnabled\" ng-disabled=\"$select.disabled\" ng-class=\"{\'btn-default-focus\':$select.focus}\"><span tabindex=\"-1\" class=\"btn btn-default form-control ui-select-toggle\" aria-label=\"{{ $select.baseTitle }} activate\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activate()\" style=\"outline: 0;\"><span ng-show=\"$select.isEmpty()\" class=\"ui-select-placeholder text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"ui-select-match-text pull-left\" ng-class=\"{\'ui-select-allow-clear\': $select.allowClear && !$select.isEmpty()}\" ng-transclude=\"\"></span> <i class=\"caret pull-right\" ng-click=\"$select.toggle($event)\"></i> <a ng-show=\"$select.allowClear && !$select.isEmpty() && ($select.disabled !== true)\" aria-label=\"{{ $select.baseTitle }} clear\" style=\"margin-right: 10px\" ng-click=\"$select.clear($event)\" class=\"btn btn-xs btn-link pull-right\"><i class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></i></a></span></div>");
2344 $templateCache.put("bootstrap/no-choice.tpl.html","<ul class=\"ui-select-no-choice dropdown-menu\" ng-show=\"$select.items.length == 0\"><li ng-transclude=\"\"></li></ul>");
2345 $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=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" class=\"ui-select-search input-xs\" placeholder=\"{{$selectMultiple.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-click=\"$select.activate()\" ng-model=\"$select.search\" role=\"combobox\" aria-label=\"{{ $select.baseTitle }}\" ondrop=\"return false;\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>");
2346 $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=\"search\" 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\" ng-class=\"{ \'ui-select-search-hidden\' : !$select.searchEnabled }\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-show=\"$select.open\"><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>");
2347 $templateCache.put("select2/choices.tpl.html","<ul tabindex=\"-1\" 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\" ng-attr-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>");
2348 $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 track by $index\" ng-class=\"{\'select2-search-choice-focus\':$selectMultiple.activeMatchIndex === $index, \'select2-locked\':$select.isLocked(this, $index)}\" ui-select-sort=\"$select.selected\"><span uis-transclude-append=\"\"></span> <a href=\"javascript:;\" class=\"ui-select-match-close select2-search-choice-close\" ng-click=\"$selectMultiple.removeChoice($index)\" tabindex=\"-1\"></a></li></span>");
2349 $templateCache.put("select2/match.tpl.html","<a class=\"select2-choice ui-select-match\" ng-class=\"{\'select2-default\': $select.isEmpty()}\" ng-click=\"$select.toggle($event)\" aria-label=\"{{ $select.baseTitle }} select\"><span ng-show=\"$select.isEmpty()\" class=\"select2-chosen\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty()\" class=\"select2-chosen\" ng-transclude=\"\"></span> <abbr ng-if=\"$select.allowClear && !$select.isEmpty()\" class=\"select2-search-choice-close\" ng-click=\"$select.clear($event)\"></abbr> <span class=\"select2-arrow ui-select-toggle\"><b></b></span></a>");
2350 $templateCache.put("select2/no-choice.tpl.html","<div class=\"ui-select-no-choice dropdown\" ng-show=\"$select.items.length == 0\"><div class=\"dropdown-content\"><div data-selectable=\"\" ng-transclude=\"\"></div></div></div>");
2351 $templateCache.put("select2/select-multiple.tpl.html","<div class=\"ui-select-container ui-select-multiple select2 select2-container select2-container-multi\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled}\"><ul class=\"select2-choices\"><span class=\"ui-select-match\"></span><li class=\"select2-search-field\"><input type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"select2-input ui-select-search\" placeholder=\"{{$selectMultiple.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-hide=\"$select.disabled\" ng-model=\"$select.search\" ng-click=\"$select.activate()\" style=\"width: 34px;\" ondrop=\"return false;\"></li></ul><div class=\"ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open || $select.items.length === 0}\"><div class=\"ui-select-choices\"></div></div></div>");
2352 $templateCache.put("select2/select.tpl.html","<div class=\"ui-select-container select2 select2-container\" ng-class=\"{\'select2-container-active select2-dropdown-open open\': $select.open, \'select2-container-disabled\': $select.disabled, \'select2-container-active\': $select.focus, \'select2-allowclear\': $select.allowClear && !$select.isEmpty()}\"><div class=\"ui-select-match\"></div><div class=\"ui-select-dropdown select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"search-container\" ng-class=\"{\'ui-select-search-hidden\':!$select.searchEnabled, \'select2-search\':$select.searchEnabled}\"><input type=\"search\" autocomplete=\"off\" autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" role=\"combobox\" aria-expanded=\"true\" aria-owns=\"ui-select-choices-{{ $select.generatedId }}\" aria-label=\"{{ $select.baseTitle }}\" aria-activedescendant=\"ui-select-choices-row-{{ $select.generatedId }}-{{ $select.activeIndex }}\" class=\"ui-select-search select2-input\" ng-model=\"$select.search\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div></div>");
2353 $templateCache.put("selectize/choices.tpl.html","<div ng-show=\"$select.open\" class=\"ui-select-choices ui-select-dropdown selectize-dropdown single\"><div class=\"ui-select-choices-content selectize-dropdown-content\"><div class=\"ui-select-choices-group optgroup\" role=\"listbox\"><div ng-show=\"$select.isGrouped\" class=\"ui-select-choices-group-label optgroup-header\" ng-bind=\"$group.name\"></div><div role=\"option\" 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>");
2354 $templateCache.put("selectize/match.tpl.html","<div ng-hide=\"$select.searchEnabled && ($select.open || $select.isEmpty())\" class=\"ui-select-match\"><span ng-show=\"!$select.searchEnabled && ($select.isEmpty() || $select.open)\" class=\"ui-select-placeholder text-muted\">{{$select.placeholder}}</span> <span ng-hide=\"$select.isEmpty() || $select.open\" ng-transclude=\"\"></span></div>");
2355 $templateCache.put("selectize/no-choice.tpl.html","<div class=\"ui-select-no-choice selectize-dropdown\" ng-show=\"$select.items.length == 0\"><div class=\"selectize-dropdown-content\"><div data-selectable=\"\" ng-transclude=\"\"></div></div></div>");
2356 $templateCache.put("selectize/select.tpl.html","<div class=\"ui-select-container selectize-control single\" ng-class=\"{\'open\': $select.open}\"><div class=\"selectize-input\" ng-class=\"{\'focus\': $select.open, \'disabled\': $select.disabled, \'selectize-focus\' : $select.focus}\" ng-click=\"$select.open && !$select.searchEnabled ? $select.toggle($event) : $select.activate()\"><div class=\"ui-select-match\"></div><input type=\"search\" autocomplete=\"off\" tabindex=\"-1\" class=\"ui-select-search ui-select-toggle\" ng-class=\"{\'ui-select-search-hidden\':!$select.searchEnabled}\" ng-click=\"$select.toggle($event)\" placeholder=\"{{$select.placeholder}}\" ng-model=\"$select.search\" ng-hide=\"!$select.isEmpty() && !$select.open\" ng-disabled=\"$select.disabled\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div><div class=\"ui-select-no-choice\"></div></div>");}]);