select.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  1. /*!
  2. * ui-select
  3. * http://github.com/angular-ui/ui-select
  4. * Version: 0.11.2 - 2015-03-17T04:08:46.474Z
  5. * License: MIT
  6. */
  7. (function () {
  8. "use strict";
  9. var KEY = {
  10. TAB: 9,
  11. ENTER: 13,
  12. ESC: 27,
  13. SPACE: 32,
  14. LEFT: 37,
  15. UP: 38,
  16. RIGHT: 39,
  17. DOWN: 40,
  18. SHIFT: 16,
  19. CTRL: 17,
  20. ALT: 18,
  21. PAGE_UP: 33,
  22. PAGE_DOWN: 34,
  23. HOME: 36,
  24. END: 35,
  25. BACKSPACE: 8,
  26. DELETE: 46,
  27. COMMAND: 91,
  28. 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 : "'"
  29. },
  30. isControl: function (e) {
  31. var k = e.which;
  32. switch (k) {
  33. case KEY.COMMAND:
  34. case KEY.SHIFT:
  35. case KEY.CTRL:
  36. case KEY.ALT:
  37. return true;
  38. }
  39. if (e.metaKey) return true;
  40. return false;
  41. },
  42. isFunctionKey: function (k) {
  43. k = k.which ? k.which : k;
  44. return k >= 112 && k <= 123;
  45. },
  46. isVerticalMovement: function (k){
  47. return ~[KEY.UP, KEY.DOWN].indexOf(k);
  48. },
  49. isHorizontalMovement: function (k){
  50. return ~[KEY.LEFT,KEY.RIGHT,KEY.BACKSPACE,KEY.DELETE].indexOf(k);
  51. }
  52. };
  53. /**
  54. * Add querySelectorAll() to jqLite.
  55. *
  56. * jqLite find() is limited to lookups by tag name.
  57. * TODO This will change with future versions of AngularJS, to be removed when this happens
  58. *
  59. * See jqLite.find - why not use querySelectorAll? https://github.com/angular/angular.js/issues/3586
  60. * See feat(jqLite): use querySelectorAll instead of getElementsByTagName in jqLite.find https://github.com/angular/angular.js/pull/3598
  61. */
  62. if (angular.element.prototype.querySelectorAll === undefined) {
  63. angular.element.prototype.querySelectorAll = function(selector) {
  64. return angular.element(this[0].querySelectorAll(selector));
  65. };
  66. }
  67. /**
  68. * Add closest() to jqLite.
  69. */
  70. if (angular.element.prototype.closest === undefined) {
  71. angular.element.prototype.closest = function( selector) {
  72. var elem = this[0];
  73. var matchesSelector = elem.matches || elem.webkitMatchesSelector || elem.mozMatchesSelector || elem.msMatchesSelector;
  74. while (elem) {
  75. if (matchesSelector.bind(elem)(selector)) {
  76. return elem;
  77. } else {
  78. elem = elem.parentElement;
  79. }
  80. }
  81. return false;
  82. };
  83. }
  84. var latestId = 0;
  85. var uis = angular.module('ui.select', [])
  86. .constant('uiSelectConfig', {
  87. theme: 'bootstrap',
  88. searchEnabled: true,
  89. sortable: false,
  90. placeholder: '', // Empty by default, like HTML tag <select>
  91. refreshDelay: 1000, // In milliseconds
  92. closeOnSelect: true,
  93. generateId: function() {
  94. return latestId++;
  95. },
  96. appendToBody: false
  97. })
  98. // See Rename minErr and make it accessible from outside https://github.com/angular/angular.js/issues/6913
  99. .service('uiSelectMinErr', function() {
  100. var minErr = angular.$$minErr('ui.select');
  101. return function() {
  102. var error = minErr.apply(this, arguments);
  103. var message = error.message.replace(new RegExp('\nhttp://errors.angularjs.org/.*'), '');
  104. return new Error(message);
  105. };
  106. })
  107. // Recreates old behavior of ng-transclude. Used internally.
  108. .directive('uisTranscludeAppend', function () {
  109. return {
  110. link: function (scope, element, attrs, ctrl, transclude) {
  111. transclude(scope, function (clone) {
  112. element.append(clone);
  113. });
  114. }
  115. };
  116. })
  117. /**
  118. * Highlights text that matches $select.search.
  119. *
  120. * Taken from AngularUI Bootstrap Typeahead
  121. * See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L340
  122. */
  123. .filter('highlight', function() {
  124. function escapeRegexp(queryToEscape) {
  125. return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
  126. }
  127. return function(matchItem, query) {
  128. return query && matchItem ? matchItem.replace(new RegExp(escapeRegexp(query), 'gi'), '<span class="ui-select-highlight">$&</span>') : matchItem;
  129. };
  130. })
  131. /**
  132. * A read-only equivalent of jQuery's offset function: http://api.jquery.com/offset/
  133. *
  134. * Taken from AngularUI Bootstrap Position:
  135. * See https://github.com/angular-ui/bootstrap/blob/master/src/position/position.js#L70
  136. */
  137. .factory('uisOffset',
  138. ['$document', '$window',
  139. function ($document, $window) {
  140. return function(element) {
  141. var boundingClientRect = element[0].getBoundingClientRect();
  142. return {
  143. width: boundingClientRect.width || element.prop('offsetWidth'),
  144. height: boundingClientRect.height || element.prop('offsetHeight'),
  145. top: boundingClientRect.top + ($window.pageYOffset || $document[0].documentElement.scrollTop),
  146. left: boundingClientRect.left + ($window.pageXOffset || $document[0].documentElement.scrollLeft)
  147. };
  148. };
  149. }]);
  150. uis.directive('uiSelectChoices',
  151. ['uiSelectConfig', 'uisRepeatParser', 'uiSelectMinErr', '$compile',
  152. function(uiSelectConfig, RepeatParser, uiSelectMinErr, $compile) {
  153. return {
  154. restrict: 'EA',
  155. require: '^uiSelect',
  156. replace: true,
  157. transclude: true,
  158. templateUrl: function(tElement) {
  159. // Gets theme attribute from parent (ui-select)
  160. var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
  161. return theme + '/choices.tpl.html';
  162. },
  163. compile: function(tElement, tAttrs) {
  164. if (!tAttrs.repeat) throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
  165. return function link(scope, element, attrs, $select, transcludeFn) {
  166. // var repeat = RepeatParser.parse(attrs.repeat);
  167. var groupByExp = attrs.groupBy;
  168. $select.parseRepeatAttr(attrs.repeat, groupByExp); //Result ready at $select.parserResult
  169. $select.disableChoiceExpression = attrs.uiDisableChoice;
  170. $select.onHighlightCallback = attrs.onHighlight;
  171. if(groupByExp) {
  172. var groups = element.querySelectorAll('.ui-select-choices-group');
  173. if (groups.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-group but got '{0}'.", groups.length);
  174. groups.attr('ng-repeat', RepeatParser.getGroupNgRepeatExpression());
  175. }
  176. var choices = element.querySelectorAll('.ui-select-choices-row');
  177. if (choices.length !== 1) {
  178. throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row but got '{0}'.", choices.length);
  179. }
  180. choices.attr('ng-repeat', RepeatParser.getNgRepeatExpression($select.parserResult.itemName, '$select.items', $select.parserResult.trackByExp, groupByExp))
  181. .attr('ng-if', '$select.open') //Prevent unnecessary watches when dropdown is closed
  182. .attr('ng-mouseenter', '$select.setActiveItem('+$select.parserResult.itemName +')')
  183. .attr('ng-click', '$select.select(' + $select.parserResult.itemName + ',false,$event)');
  184. var rowsInner = element.querySelectorAll('.ui-select-choices-row-inner');
  185. if (rowsInner.length !== 1) throw uiSelectMinErr('rows', "Expected 1 .ui-select-choices-row-inner but got '{0}'.", rowsInner.length);
  186. rowsInner.attr('uis-transclude-append', ''); //Adding uisTranscludeAppend directive to row element after choices element has ngRepeat
  187. $compile(element, transcludeFn)(scope); //Passing current transcludeFn to be able to append elements correctly from uisTranscludeAppend
  188. scope.$watch('$select.search', function(newValue) {
  189. if(newValue && !$select.open && $select.multiple) $select.activate(false, true);
  190. $select.activeIndex = $select.tagging.isActivated ? -1 : 0;
  191. $select.refresh(attrs.refresh);
  192. });
  193. attrs.$observe('refreshDelay', function() {
  194. // $eval() is needed otherwise we get a string instead of a number
  195. var refreshDelay = scope.$eval(attrs.refreshDelay);
  196. $select.refreshDelay = refreshDelay !== undefined ? refreshDelay : uiSelectConfig.refreshDelay;
  197. });
  198. };
  199. }
  200. };
  201. }]);
  202. /**
  203. * Contains ui-select "intelligence".
  204. *
  205. * The goal is to limit dependency on the DOM whenever possible and
  206. * put as much logic in the controller (instead of the link functions) as possible so it can be easily tested.
  207. */
  208. uis.controller('uiSelectCtrl',
  209. ['$scope', '$element', '$timeout', '$filter', 'uisRepeatParser', 'uiSelectMinErr', 'uiSelectConfig',
  210. function($scope, $element, $timeout, $filter, RepeatParser, uiSelectMinErr, uiSelectConfig) {
  211. var ctrl = this;
  212. var EMPTY_SEARCH = '';
  213. ctrl.placeholder = uiSelectConfig.placeholder;
  214. ctrl.searchEnabled = uiSelectConfig.searchEnabled;
  215. ctrl.sortable = uiSelectConfig.sortable;
  216. ctrl.refreshDelay = uiSelectConfig.refreshDelay;
  217. ctrl.removeSelected = false; //If selected item(s) should be removed from dropdown list
  218. ctrl.closeOnSelect = true; //Initialized inside uiSelect directive link function
  219. ctrl.search = EMPTY_SEARCH;
  220. ctrl.activeIndex = 0; //Dropdown of choices
  221. ctrl.items = []; //All available choices
  222. ctrl.open = false;
  223. ctrl.focus = false;
  224. ctrl.disabled = false;
  225. ctrl.selected = undefined;
  226. ctrl.focusser = undefined; //Reference to input element used to handle focus events
  227. ctrl.resetSearchInput = true;
  228. ctrl.multiple = undefined; // Initialized inside uiSelect directive link function
  229. ctrl.disableChoiceExpression = undefined; // Initialized inside uiSelectChoices directive link function
  230. ctrl.tagging = {isActivated: false, fct: undefined};
  231. ctrl.taggingTokens = {isActivated: false, tokens: undefined};
  232. ctrl.lockChoiceExpression = undefined; // Initialized inside uiSelectMatch directive link function
  233. ctrl.clickTriggeredSelect = false;
  234. ctrl.$filter = $filter;
  235. ctrl.searchInput = $element.querySelectorAll('input.ui-select-search');
  236. if (ctrl.searchInput.length !== 1) {
  237. throw uiSelectMinErr('searchInput', "Expected 1 input.ui-select-search but got '{0}'.", ctrl.searchInput.length);
  238. }
  239. ctrl.isEmpty = function() {
  240. return angular.isUndefined(ctrl.selected) || ctrl.selected === null || ctrl.selected === '';
  241. };
  242. // Most of the time the user does not want to empty the search input when in typeahead mode
  243. function _resetSearchInput() {
  244. if (ctrl.resetSearchInput || (ctrl.resetSearchInput === undefined && uiSelectConfig.resetSearchInput)) {
  245. ctrl.search = EMPTY_SEARCH;
  246. //reset activeIndex
  247. if (ctrl.selected && ctrl.items.length && !ctrl.multiple) {
  248. ctrl.activeIndex = ctrl.items.indexOf(ctrl.selected);
  249. }
  250. }
  251. }
  252. // When the user clicks on ui-select, displays the dropdown list
  253. ctrl.activate = function(initSearchValue, avoidReset) {
  254. if (!ctrl.disabled && !ctrl.open) {
  255. if(!avoidReset) _resetSearchInput();
  256. $scope.$broadcast('uis:activate');
  257. ctrl.open = true;
  258. ctrl.activeIndex = ctrl.activeIndex >= ctrl.items.length ? 0 : ctrl.activeIndex;
  259. // ensure that the index is set to zero for tagging variants
  260. // that where first option is auto-selected
  261. if ( ctrl.activeIndex === -1 && ctrl.taggingLabel !== false ) {
  262. ctrl.activeIndex = 0;
  263. }
  264. // Give it time to appear before focus
  265. $timeout(function() {
  266. ctrl.search = initSearchValue || ctrl.search;
  267. ctrl.searchInput[0].focus();
  268. });
  269. }
  270. };
  271. ctrl.findGroupByName = function(name) {
  272. return ctrl.groups && ctrl.groups.filter(function(group) {
  273. return group.name === name;
  274. })[0];
  275. };
  276. ctrl.parseRepeatAttr = function(repeatAttr, groupByExp) {
  277. function updateGroups(items) {
  278. ctrl.groups = [];
  279. angular.forEach(items, function(item) {
  280. var groupFn = $scope.$eval(groupByExp);
  281. var groupName = angular.isFunction(groupFn) ? groupFn(item) : item[groupFn];
  282. var group = ctrl.findGroupByName(groupName);
  283. if(group) {
  284. group.items.push(item);
  285. }
  286. else {
  287. ctrl.groups.push({name: groupName, items: [item]});
  288. }
  289. });
  290. ctrl.items = [];
  291. ctrl.groups.forEach(function(group) {
  292. ctrl.items = ctrl.items.concat(group.items);
  293. });
  294. }
  295. function setPlainItems(items) {
  296. ctrl.items = items;
  297. }
  298. ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems;
  299. ctrl.parserResult = RepeatParser.parse(repeatAttr);
  300. ctrl.isGrouped = !!groupByExp;
  301. ctrl.itemProperty = ctrl.parserResult.itemName;
  302. ctrl.refreshItems = function (data){
  303. data = data || ctrl.parserResult.source($scope);
  304. var selectedItems = ctrl.selected;
  305. //TODO should implement for single mode removeSelected
  306. if ((angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) {
  307. ctrl.setItemsFn(data);
  308. }else{
  309. if ( data !== undefined ) {
  310. var filteredItems = data.filter(function(i) {return selectedItems.indexOf(i) < 0;});
  311. ctrl.setItemsFn(filteredItems);
  312. }
  313. }
  314. };
  315. // See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L259
  316. $scope.$watchCollection(ctrl.parserResult.source, function(items) {
  317. if (items === undefined || items === null) {
  318. // If the user specifies undefined or null => reset the collection
  319. // Special case: items can be undefined if the user did not initialized the collection on the scope
  320. // i.e $scope.addresses = [] is missing
  321. ctrl.items = [];
  322. } else {
  323. if (!angular.isArray(items)) {
  324. throw uiSelectMinErr('items', "Expected an array but got '{0}'.", items);
  325. } else {
  326. //Remove already selected items (ex: while searching)
  327. //TODO Should add a test
  328. ctrl.refreshItems(items);
  329. ctrl.ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
  330. }
  331. }
  332. });
  333. };
  334. var _refreshDelayPromise;
  335. /**
  336. * Typeahead mode: lets the user refresh the collection using his own function.
  337. *
  338. * See Expose $select.search for external / remote filtering https://github.com/angular-ui/ui-select/pull/31
  339. */
  340. ctrl.refresh = function(refreshAttr) {
  341. if (refreshAttr !== undefined) {
  342. // Debounce
  343. // See https://github.com/angular-ui/bootstrap/blob/0.10.0/src/typeahead/typeahead.js#L155
  344. // FYI AngularStrap typeahead does not have debouncing: https://github.com/mgcrea/angular-strap/blob/v2.0.0-rc.4/src/typeahead/typeahead.js#L177
  345. if (_refreshDelayPromise) {
  346. $timeout.cancel(_refreshDelayPromise);
  347. }
  348. _refreshDelayPromise = $timeout(function() {
  349. $scope.$eval(refreshAttr);
  350. }, ctrl.refreshDelay);
  351. }
  352. };
  353. ctrl.setActiveItem = function(item) {
  354. ctrl.activeIndex = ctrl.items.indexOf(item);
  355. };
  356. ctrl.isActive = function(itemScope) {
  357. if ( !ctrl.open ) {
  358. return false;
  359. }
  360. var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
  361. var isActive = itemIndex === ctrl.activeIndex;
  362. if ( !isActive || ( itemIndex < 0 && ctrl.taggingLabel !== false ) ||( itemIndex < 0 && ctrl.taggingLabel === false) ) {
  363. return false;
  364. }
  365. if (isActive && !angular.isUndefined(ctrl.onHighlightCallback)) {
  366. itemScope.$eval(ctrl.onHighlightCallback);
  367. }
  368. return isActive;
  369. };
  370. ctrl.isDisabled = function(itemScope) {
  371. if (!ctrl.open) return;
  372. var itemIndex = ctrl.items.indexOf(itemScope[ctrl.itemProperty]);
  373. var isDisabled = false;
  374. var item;
  375. if (itemIndex >= 0 && !angular.isUndefined(ctrl.disableChoiceExpression)) {
  376. item = ctrl.items[itemIndex];
  377. isDisabled = !!(itemScope.$eval(ctrl.disableChoiceExpression)); // force the boolean value
  378. item._uiSelectChoiceDisabled = isDisabled; // store this for later reference
  379. }
  380. return isDisabled;
  381. };
  382. // When the user selects an item with ENTER or clicks the dropdown
  383. ctrl.select = function(item, skipFocusser, $event) {
  384. if (item === undefined || !item._uiSelectChoiceDisabled) {
  385. if ( ! ctrl.items && ! ctrl.search ) return;
  386. if (!item || !item._uiSelectChoiceDisabled) {
  387. if(ctrl.tagging.isActivated) {
  388. // if taggingLabel is disabled, we pull from ctrl.search val
  389. if ( ctrl.taggingLabel === false ) {
  390. if ( ctrl.activeIndex < 0 ) {
  391. item = ctrl.tagging.fct !== undefined ? ctrl.tagging.fct(ctrl.search) : ctrl.search;
  392. if (!item || angular.equals( ctrl.items[0], item ) ) {
  393. return;
  394. }
  395. } else {
  396. // keyboard nav happened first, user selected from dropdown
  397. item = ctrl.items[ctrl.activeIndex];
  398. }
  399. } else {
  400. // tagging always operates at index zero, taggingLabel === false pushes
  401. // the ctrl.search value without having it injected
  402. if ( ctrl.activeIndex === 0 ) {
  403. // ctrl.tagging pushes items to ctrl.items, so we only have empty val
  404. // for `item` if it is a detected duplicate
  405. if ( item === undefined ) return;
  406. // create new item on the fly if we don't already have one;
  407. // use tagging function if we have one
  408. if ( ctrl.tagging.fct !== undefined && typeof item === 'string' ) {
  409. item = ctrl.tagging.fct(ctrl.search);
  410. if (!item) return;
  411. // if item type is 'string', apply the tagging label
  412. } else if ( typeof item === 'string' ) {
  413. // trim the trailing space
  414. item = item.replace(ctrl.taggingLabel,'').trim();
  415. }
  416. }
  417. }
  418. // search ctrl.selected for dupes potentially caused by tagging and return early if found
  419. if ( ctrl.selected && angular.isArray(ctrl.selected) && ctrl.selected.filter( function (selection) { return angular.equals(selection, item); }).length > 0 ) {
  420. ctrl.close(skipFocusser);
  421. return;
  422. }
  423. }
  424. $scope.$broadcast('uis:select', item);
  425. var locals = {};
  426. locals[ctrl.parserResult.itemName] = item;
  427. $timeout(function(){
  428. ctrl.onSelectCallback($scope, {
  429. $item: item,
  430. $model: ctrl.parserResult.modelMapper($scope, locals)
  431. });
  432. });
  433. if (ctrl.closeOnSelect) {
  434. ctrl.close(skipFocusser);
  435. }
  436. if ($event && $event.type === 'click') {
  437. ctrl.clickTriggeredSelect = true;
  438. }
  439. }
  440. }
  441. };
  442. // Closes the dropdown
  443. ctrl.close = function(skipFocusser) {
  444. if (!ctrl.open) return;
  445. if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
  446. _resetSearchInput();
  447. ctrl.open = false;
  448. $scope.$broadcast('uis:close', skipFocusser);
  449. };
  450. ctrl.setFocus = function(){
  451. if (!ctrl.focus) ctrl.focusInput[0].focus();
  452. };
  453. ctrl.clear = function($event) {
  454. ctrl.select(undefined);
  455. $event.stopPropagation();
  456. ctrl.focusser[0].focus();
  457. };
  458. // Toggle dropdown
  459. ctrl.toggle = function(e) {
  460. if (ctrl.open) {
  461. ctrl.close();
  462. e.preventDefault();
  463. e.stopPropagation();
  464. } else {
  465. ctrl.activate();
  466. }
  467. };
  468. ctrl.isLocked = function(itemScope, itemIndex) {
  469. var isLocked, item = ctrl.selected[itemIndex];
  470. if (item && !angular.isUndefined(ctrl.lockChoiceExpression)) {
  471. isLocked = !!(itemScope.$eval(ctrl.lockChoiceExpression)); // force the boolean value
  472. item._uiSelectChoiceLocked = isLocked; // store this for later reference
  473. }
  474. return isLocked;
  475. };
  476. var sizeWatch = null;
  477. ctrl.sizeSearchInput = function() {
  478. var input = ctrl.searchInput[0],
  479. container = ctrl.searchInput.parent().parent()[0],
  480. calculateContainerWidth = function() {
  481. // Return the container width only if the search input is visible
  482. return container.clientWidth * !!input.offsetParent;
  483. },
  484. updateIfVisible = function(containerWidth) {
  485. if (containerWidth === 0) {
  486. return false;
  487. }
  488. var inputWidth = containerWidth - input.offsetLeft - 10;
  489. if (inputWidth < 50) inputWidth = containerWidth;
  490. ctrl.searchInput.css('width', inputWidth+'px');
  491. return true;
  492. };
  493. ctrl.searchInput.css('width', '10px');
  494. $timeout(function() { //Give tags time to render correctly
  495. if (sizeWatch === null && !updateIfVisible(calculateContainerWidth())) {
  496. sizeWatch = $scope.$watch(calculateContainerWidth, function(containerWidth) {
  497. if (updateIfVisible(containerWidth)) {
  498. sizeWatch();
  499. sizeWatch = null;
  500. }
  501. });
  502. }
  503. });
  504. };
  505. function _handleDropDownSelection(key) {
  506. var processed = true;
  507. switch (key) {
  508. case KEY.DOWN:
  509. if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
  510. else if (ctrl.activeIndex < ctrl.items.length - 1) { ctrl.activeIndex++; }
  511. break;
  512. case KEY.UP:
  513. if (!ctrl.open && ctrl.multiple) ctrl.activate(false, true); //In case its the search input in 'multiple' mode
  514. else if (ctrl.activeIndex > 0 || (ctrl.search.length === 0 && ctrl.tagging.isActivated && ctrl.activeIndex > -1)) { ctrl.activeIndex--; }
  515. break;
  516. case KEY.TAB:
  517. if (!ctrl.multiple || ctrl.open) ctrl.select(ctrl.items[ctrl.activeIndex], true);
  518. break;
  519. case KEY.ENTER:
  520. if(ctrl.open && ctrl.activeIndex >= 0){
  521. ctrl.select(ctrl.items[ctrl.activeIndex]); // Make sure at least one dropdown item is highlighted before adding.
  522. } else {
  523. ctrl.activate(false, true); //In case its the search input in 'multiple' mode
  524. }
  525. break;
  526. case KEY.ESC:
  527. ctrl.close();
  528. break;
  529. default:
  530. processed = false;
  531. }
  532. return processed;
  533. }
  534. // Bind to keyboard shortcuts
  535. ctrl.searchInput.on('keydown', function(e) {
  536. var key = e.which;
  537. // if(~[KEY.ESC,KEY.TAB].indexOf(key)){
  538. // //TODO: SEGURO?
  539. // ctrl.close();
  540. // }
  541. $scope.$apply(function() {
  542. var tagged = false;
  543. if (ctrl.items.length > 0 || ctrl.tagging.isActivated) {
  544. _handleDropDownSelection(key);
  545. if ( ctrl.taggingTokens.isActivated ) {
  546. for (var i = 0; i < ctrl.taggingTokens.tokens.length; i++) {
  547. if ( ctrl.taggingTokens.tokens[i] === KEY.MAP[e.keyCode] ) {
  548. // make sure there is a new value to push via tagging
  549. if ( ctrl.search.length > 0 ) {
  550. tagged = true;
  551. }
  552. }
  553. }
  554. if ( tagged ) {
  555. $timeout(function() {
  556. ctrl.searchInput.triggerHandler('tagged');
  557. var newItem = ctrl.search.replace(KEY.MAP[e.keyCode],'').trim();
  558. if ( ctrl.tagging.fct ) {
  559. newItem = ctrl.tagging.fct( newItem );
  560. }
  561. if (newItem) ctrl.select(newItem, true);
  562. });
  563. }
  564. }
  565. }
  566. });
  567. if(KEY.isVerticalMovement(key) && ctrl.items.length > 0){
  568. _ensureHighlightVisible();
  569. }
  570. });
  571. // If tagging try to split by tokens and add items
  572. ctrl.searchInput.on('paste', function (e) {
  573. var data = e.originalEvent.clipboardData.getData('text/plain');
  574. if (data && data.length > 0 && ctrl.taggingTokens.isActivated && ctrl.tagging.fct) {
  575. var items = data.split(ctrl.taggingTokens.tokens[0]); // split by first token only
  576. if (items && items.length > 0) {
  577. angular.forEach(items, function (item) {
  578. var newItem = ctrl.tagging.fct(item);
  579. if (newItem) {
  580. ctrl.select(newItem, true);
  581. }
  582. });
  583. e.preventDefault();
  584. e.stopPropagation();
  585. }
  586. }
  587. });
  588. ctrl.searchInput.on('tagged', function() {
  589. $timeout(function() {
  590. _resetSearchInput();
  591. });
  592. });
  593. // See https://github.com/ivaynberg/select2/blob/3.4.6/select2.js#L1431
  594. function _ensureHighlightVisible() {
  595. var container = $element.querySelectorAll('.ui-select-choices-content');
  596. var choices = container.querySelectorAll('.ui-select-choices-row');
  597. if (choices.length < 1) {
  598. throw uiSelectMinErr('choices', "Expected multiple .ui-select-choices-row but got '{0}'.", choices.length);
  599. }
  600. if (ctrl.activeIndex < 0) {
  601. return;
  602. }
  603. var highlighted = choices[ctrl.activeIndex];
  604. var posY = highlighted.offsetTop + highlighted.clientHeight - container[0].scrollTop;
  605. var height = container[0].offsetHeight;
  606. if (posY > height) {
  607. container[0].scrollTop += posY - height;
  608. } else if (posY < highlighted.clientHeight) {
  609. if (ctrl.isGrouped && ctrl.activeIndex === 0)
  610. container[0].scrollTop = 0; //To make group header visible when going all the way up
  611. else
  612. container[0].scrollTop -= highlighted.clientHeight - posY;
  613. }
  614. }
  615. $scope.$on('$destroy', function() {
  616. ctrl.searchInput.off('keyup keydown tagged blur paste');
  617. });
  618. }]);
  619. uis.directive('uiSelect',
  620. ['$document', 'uiSelectConfig', 'uiSelectMinErr', 'uisOffset', '$compile', '$parse', '$timeout',
  621. function($document, uiSelectConfig, uiSelectMinErr, uisOffset, $compile, $parse, $timeout) {
  622. return {
  623. restrict: 'EA',
  624. templateUrl: function(tElement, tAttrs) {
  625. var theme = tAttrs.theme || uiSelectConfig.theme;
  626. return theme + (angular.isDefined(tAttrs.multiple) ? '/select-multiple.tpl.html' : '/select.tpl.html');
  627. },
  628. replace: true,
  629. transclude: true,
  630. require: ['uiSelect', '^ngModel'],
  631. scope: true,
  632. controller: 'uiSelectCtrl',
  633. controllerAs: '$select',
  634. compile: function(tElement, tAttrs) {
  635. //Multiple or Single depending if multiple attribute presence
  636. if (angular.isDefined(tAttrs.multiple))
  637. tElement.append("<ui-select-multiple/>").removeAttr('multiple');
  638. else
  639. tElement.append("<ui-select-single/>");
  640. return function(scope, element, attrs, ctrls, transcludeFn) {
  641. var $select = ctrls[0];
  642. var ngModel = ctrls[1];
  643. $select.generatedId = uiSelectConfig.generateId();
  644. $select.baseTitle = attrs.title || 'Select box';
  645. $select.focusserTitle = $select.baseTitle + ' focus';
  646. $select.focusserId = 'focusser-' + $select.generatedId;
  647. $select.closeOnSelect = function() {
  648. if (angular.isDefined(attrs.closeOnSelect)) {
  649. return $parse(attrs.closeOnSelect)();
  650. } else {
  651. return uiSelectConfig.closeOnSelect;
  652. }
  653. }();
  654. $select.onSelectCallback = $parse(attrs.onSelect);
  655. $select.onRemoveCallback = $parse(attrs.onRemove);
  656. //Set reference to ngModel from uiSelectCtrl
  657. $select.ngModel = ngModel;
  658. $select.choiceGrouped = function(group){
  659. return $select.isGrouped && group && group.name;
  660. };
  661. if(attrs.tabindex){
  662. attrs.$observe('tabindex', function(value) {
  663. $select.focusInput.attr("tabindex", value);
  664. element.removeAttr("tabindex");
  665. });
  666. }
  667. scope.$watch('searchEnabled', function() {
  668. var searchEnabled = scope.$eval(attrs.searchEnabled);
  669. $select.searchEnabled = searchEnabled !== undefined ? searchEnabled : uiSelectConfig.searchEnabled;
  670. });
  671. scope.$watch('sortable', function() {
  672. var sortable = scope.$eval(attrs.sortable);
  673. $select.sortable = sortable !== undefined ? sortable : uiSelectConfig.sortable;
  674. });
  675. attrs.$observe('disabled', function() {
  676. // No need to use $eval() (thanks to ng-disabled) since we already get a boolean instead of a string
  677. $select.disabled = attrs.disabled !== undefined ? attrs.disabled : false;
  678. });
  679. attrs.$observe('resetSearchInput', function() {
  680. // $eval() is needed otherwise we get a string instead of a boolean
  681. var resetSearchInput = scope.$eval(attrs.resetSearchInput);
  682. $select.resetSearchInput = resetSearchInput !== undefined ? resetSearchInput : true;
  683. });
  684. attrs.$observe('tagging', function() {
  685. if(attrs.tagging !== undefined)
  686. {
  687. // $eval() is needed otherwise we get a string instead of a boolean
  688. var taggingEval = scope.$eval(attrs.tagging);
  689. $select.tagging = {isActivated: true, fct: taggingEval !== true ? taggingEval : undefined};
  690. }
  691. else
  692. {
  693. $select.tagging = {isActivated: false, fct: undefined};
  694. }
  695. });
  696. attrs.$observe('taggingLabel', function() {
  697. if(attrs.tagging !== undefined )
  698. {
  699. // check eval for FALSE, in this case, we disable the labels
  700. // associated with tagging
  701. if ( attrs.taggingLabel === 'false' ) {
  702. $select.taggingLabel = false;
  703. }
  704. else
  705. {
  706. $select.taggingLabel = attrs.taggingLabel !== undefined ? attrs.taggingLabel : '(new)';
  707. }
  708. }
  709. });
  710. attrs.$observe('taggingTokens', function() {
  711. if (attrs.tagging !== undefined) {
  712. var tokens = attrs.taggingTokens !== undefined ? attrs.taggingTokens.split('|') : [',','ENTER'];
  713. $select.taggingTokens = {isActivated: true, tokens: tokens };
  714. }
  715. });
  716. //Automatically gets focus when loaded
  717. if (angular.isDefined(attrs.autofocus)){
  718. $timeout(function(){
  719. $select.setFocus();
  720. });
  721. }
  722. //Gets focus based on scope event name (e.g. focus-on='SomeEventName')
  723. if (angular.isDefined(attrs.focusOn)){
  724. scope.$on(attrs.focusOn, function() {
  725. $timeout(function(){
  726. $select.setFocus();
  727. });
  728. });
  729. }
  730. function onDocumentClick(e) {
  731. if (!$select.open) return; //Skip it if dropdown is close
  732. var contains = false;
  733. if (window.jQuery) {
  734. // Firefox 3.6 does not support element.contains()
  735. // See Node.contains https://developer.mozilla.org/en-US/docs/Web/API/Node.contains
  736. contains = window.jQuery.contains(element[0], e.target);
  737. } else {
  738. contains = element[0].contains(e.target);
  739. }
  740. if (!contains && !$select.clickTriggeredSelect) {
  741. //Will lose focus only with certain targets
  742. var focusableControls = ['input','button','textarea'];
  743. var targetScope = angular.element(e.target).scope(); //To check if target is other ui-select
  744. var skipFocusser = targetScope && targetScope.$select && targetScope.$select !== $select; //To check if target is other ui-select
  745. if (!skipFocusser) skipFocusser = ~focusableControls.indexOf(e.target.tagName.toLowerCase()); //Check if target is input, button or textarea
  746. $select.close(skipFocusser);
  747. scope.$digest();
  748. }
  749. $select.clickTriggeredSelect = false;
  750. }
  751. // See Click everywhere but here event http://stackoverflow.com/questions/12931369
  752. $document.on('click', onDocumentClick);
  753. scope.$on('$destroy', function() {
  754. $document.off('click', onDocumentClick);
  755. });
  756. // Move transcluded elements to their correct position in main template
  757. transcludeFn(scope, function(clone) {
  758. // See Transclude in AngularJS http://blog.omkarpatil.com/2012/11/transclude-in-angularjs.html
  759. // One day jqLite will be replaced by jQuery and we will be able to write:
  760. // var transcludedElement = clone.filter('.my-class')
  761. // instead of creating a hackish DOM element:
  762. var transcluded = angular.element('<div>').append(clone);
  763. var transcludedMatch = transcluded.querySelectorAll('.ui-select-match');
  764. transcludedMatch.removeAttr('ui-select-match'); //To avoid loop in case directive as attr
  765. transcludedMatch.removeAttr('data-ui-select-match'); // Properly handle HTML5 data-attributes
  766. if (transcludedMatch.length !== 1) {
  767. throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-match but got '{0}'.", transcludedMatch.length);
  768. }
  769. element.querySelectorAll('.ui-select-match').replaceWith(transcludedMatch);
  770. var transcludedChoices = transcluded.querySelectorAll('.ui-select-choices');
  771. transcludedChoices.removeAttr('ui-select-choices'); //To avoid loop in case directive as attr
  772. transcludedChoices.removeAttr('data-ui-select-choices'); // Properly handle HTML5 data-attributes
  773. if (transcludedChoices.length !== 1) {
  774. throw uiSelectMinErr('transcluded', "Expected 1 .ui-select-choices but got '{0}'.", transcludedChoices.length);
  775. }
  776. element.querySelectorAll('.ui-select-choices').replaceWith(transcludedChoices);
  777. });
  778. // Support for appending the select field to the body when its open
  779. var appendToBody = scope.$eval(attrs.appendToBody);
  780. if (appendToBody !== undefined ? appendToBody : uiSelectConfig.appendToBody) {
  781. scope.$watch('$select.open', function(isOpen) {
  782. if (isOpen) {
  783. positionDropdown();
  784. } else {
  785. resetDropdown();
  786. }
  787. });
  788. // Move the dropdown back to its original location when the scope is destroyed. Otherwise
  789. // it might stick around when the user routes away or the select field is otherwise removed
  790. scope.$on('$destroy', function() {
  791. resetDropdown();
  792. });
  793. }
  794. // Hold on to a reference to the .ui-select-container element for appendToBody support
  795. var placeholder = null,
  796. originalWidth = '';
  797. function positionDropdown() {
  798. // Remember the absolute position of the element
  799. var offset = uisOffset(element);
  800. // Clone the element into a placeholder element to take its original place in the DOM
  801. placeholder = angular.element('<div class="ui-select-placeholder"></div>');
  802. placeholder[0].style.width = offset.width + 'px';
  803. placeholder[0].style.height = offset.height + 'px';
  804. element.after(placeholder);
  805. // Remember the original value of the element width inline style, so it can be restored
  806. // when the dropdown is closed
  807. originalWidth = element[0].style.width;
  808. // Now move the actual dropdown element to the end of the body
  809. $document.find('body').append(element);
  810. element[0].style.position = 'absolute';
  811. element[0].style.left = offset.left + 'px';
  812. element[0].style.top = offset.top + 'px';
  813. element[0].style.width = offset.width + 'px';
  814. }
  815. function resetDropdown() {
  816. if (placeholder === null) {
  817. // The dropdown has not actually been display yet, so there's nothing to reset
  818. return;
  819. }
  820. // Move the dropdown element back to its original location in the DOM
  821. placeholder.replaceWith(element);
  822. placeholder = null;
  823. element[0].style.position = '';
  824. element[0].style.left = '';
  825. element[0].style.top = '';
  826. element[0].style.width = originalWidth;
  827. }
  828. };
  829. }
  830. };
  831. }]);
  832. uis.directive('uiSelectMatch', ['uiSelectConfig', function(uiSelectConfig) {
  833. return {
  834. restrict: 'EA',
  835. require: '^uiSelect',
  836. replace: true,
  837. transclude: true,
  838. templateUrl: function(tElement) {
  839. // Gets theme attribute from parent (ui-select)
  840. var theme = tElement.parent().attr('theme') || uiSelectConfig.theme;
  841. var multi = tElement.parent().attr('multiple');
  842. return theme + (multi ? '/match-multiple.tpl.html' : '/match.tpl.html');
  843. },
  844. link: function(scope, element, attrs, $select) {
  845. $select.lockChoiceExpression = attrs.uiLockChoice;
  846. attrs.$observe('placeholder', function(placeholder) {
  847. $select.placeholder = placeholder !== undefined ? placeholder : uiSelectConfig.placeholder;
  848. });
  849. function setAllowClear(allow) {
  850. $select.allowClear = (angular.isDefined(allow)) ? (allow === '') ? true : (allow.toLowerCase() === 'true') : false;
  851. }
  852. attrs.$observe('allowClear', setAllowClear);
  853. setAllowClear(attrs.allowClear);
  854. if($select.multiple){
  855. $select.sizeSearchInput();
  856. }
  857. }
  858. };
  859. }]);
  860. uis.directive('uiSelectMultiple', ['uiSelectMinErr','$timeout', function(uiSelectMinErr, $timeout) {
  861. return {
  862. restrict: 'EA',
  863. require: ['^uiSelect', '^ngModel'],
  864. controller: ['$scope','$timeout', function($scope, $timeout){
  865. var ctrl = this,
  866. $select = $scope.$select,
  867. ngModel;
  868. //Wait for link fn to inject it
  869. $scope.$evalAsync(function(){ ngModel = $scope.ngModel; });
  870. ctrl.activeMatchIndex = -1;
  871. ctrl.updateModel = function(){
  872. ngModel.$setViewValue(Date.now()); //Set timestamp as a unique string to force changes
  873. ctrl.refreshComponent();
  874. };
  875. ctrl.refreshComponent = function(){
  876. //Remove already selected items
  877. //e.g. When user clicks on a selection, the selected array changes and
  878. //the dropdown should remove that item
  879. $select.refreshItems();
  880. $select.sizeSearchInput();
  881. };
  882. // Remove item from multiple select
  883. ctrl.removeChoice = function(index){
  884. var removedChoice = $select.selected[index];
  885. // if the choice is locked, can't remove it
  886. if(removedChoice._uiSelectChoiceLocked) return;
  887. var locals = {};
  888. locals[$select.parserResult.itemName] = removedChoice;
  889. $select.selected.splice(index, 1);
  890. ctrl.activeMatchIndex = -1;
  891. $select.sizeSearchInput();
  892. // Give some time for scope propagation.
  893. $timeout(function(){
  894. $select.onRemoveCallback($scope, {
  895. $item: removedChoice,
  896. $model: $select.parserResult.modelMapper($scope, locals)
  897. });
  898. });
  899. ctrl.updateModel();
  900. };
  901. ctrl.getPlaceholder = function(){
  902. //Refactor single?
  903. if($select.selected.length) return;
  904. return $select.placeholder;
  905. };
  906. }],
  907. controllerAs: '$selectMultiple',
  908. link: function(scope, element, attrs, ctrls) {
  909. var $select = ctrls[0];
  910. var ngModel = scope.ngModel = ctrls[1];
  911. var $selectMultiple = scope.$selectMultiple;
  912. //$select.selected = raw selected objects (ignoring any property binding)
  913. $select.multiple = true;
  914. $select.removeSelected = true;
  915. //Input that will handle focus
  916. $select.focusInput = $select.searchInput;
  917. //From view --> model
  918. ngModel.$parsers.unshift(function () {
  919. var locals = {},
  920. result,
  921. resultMultiple = [];
  922. for (var j = $select.selected.length - 1; j >= 0; j--) {
  923. locals = {};
  924. locals[$select.parserResult.itemName] = $select.selected[j];
  925. result = $select.parserResult.modelMapper(scope, locals);
  926. resultMultiple.unshift(result);
  927. }
  928. return resultMultiple;
  929. });
  930. // From model --> view
  931. ngModel.$formatters.unshift(function (inputValue) {
  932. var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
  933. locals = {},
  934. result;
  935. if (!data) return inputValue;
  936. var resultMultiple = [];
  937. var checkFnMultiple = function(list, value){
  938. if (!list || !list.length) return;
  939. for (var p = list.length - 1; p >= 0; p--) {
  940. locals[$select.parserResult.itemName] = list[p];
  941. result = $select.parserResult.modelMapper(scope, locals);
  942. if($select.parserResult.trackByExp){
  943. var matches = /\.(.+)/.exec($select.parserResult.trackByExp);
  944. if(matches.length>0 && result[matches[1]] == value[matches[1]]){
  945. resultMultiple.unshift(list[p]);
  946. return true;
  947. }
  948. }
  949. if (angular.equals(result,value)){
  950. resultMultiple.unshift(list[p]);
  951. return true;
  952. }
  953. }
  954. return false;
  955. };
  956. if (!inputValue) return resultMultiple; //If ngModel was undefined
  957. for (var k = inputValue.length - 1; k >= 0; k--) {
  958. //Check model array of currently selected items
  959. if (!checkFnMultiple($select.selected, inputValue[k])){
  960. //Check model array of all items available
  961. if (!checkFnMultiple(data, inputValue[k])){
  962. //If not found on previous lists, just add it directly to resultMultiple
  963. resultMultiple.unshift(inputValue[k]);
  964. }
  965. }
  966. }
  967. return resultMultiple;
  968. });
  969. //Watch for external model changes
  970. scope.$watchCollection(function(){ return ngModel.$modelValue; }, function(newValue, oldValue) {
  971. if (oldValue != newValue){
  972. ngModel.$modelValue = null; //Force scope model value and ngModel value to be out of sync to re-run formatters
  973. $selectMultiple.refreshComponent();
  974. }
  975. });
  976. ngModel.$render = function() {
  977. // Make sure that model value is array
  978. if(!angular.isArray(ngModel.$viewValue)){
  979. // Have tolerance for null or undefined values
  980. if(angular.isUndefined(ngModel.$viewValue) || ngModel.$viewValue === null){
  981. $select.selected = [];
  982. } else {
  983. throw uiSelectMinErr('multiarr', "Expected model value to be array but got '{0}'", ngModel.$viewValue);
  984. }
  985. }
  986. $select.selected = ngModel.$viewValue;
  987. scope.$evalAsync(); //To force $digest
  988. };
  989. scope.$on('uis:select', function (event, item) {
  990. $select.selected.push(item);
  991. $selectMultiple.updateModel();
  992. });
  993. scope.$on('uis:activate', function () {
  994. $selectMultiple.activeMatchIndex = -1;
  995. });
  996. scope.$watch('$select.disabled', function(newValue, oldValue) {
  997. // As the search input field may now become visible, it may be necessary to recompute its size
  998. if (oldValue && !newValue) $select.sizeSearchInput();
  999. });
  1000. $select.searchInput.on('keydown', function(e) {
  1001. var key = e.which;
  1002. scope.$apply(function() {
  1003. var processed = false;
  1004. // var tagged = false; //Checkme
  1005. if(KEY.isHorizontalMovement(key)){
  1006. processed = _handleMatchSelection(key);
  1007. }
  1008. if (processed && key != KEY.TAB) {
  1009. //TODO Check si el tab selecciona aun correctamente
  1010. //Crear test
  1011. e.preventDefault();
  1012. e.stopPropagation();
  1013. }
  1014. });
  1015. });
  1016. function _getCaretPosition(el) {
  1017. if(angular.isNumber(el.selectionStart)) return el.selectionStart;
  1018. // selectionStart is not supported in IE8 and we don't want hacky workarounds so we compromise
  1019. else return el.value.length;
  1020. }
  1021. // Handles selected options in "multiple" mode
  1022. function _handleMatchSelection(key){
  1023. var caretPosition = _getCaretPosition($select.searchInput[0]),
  1024. length = $select.selected.length,
  1025. // none = -1,
  1026. first = 0,
  1027. last = length-1,
  1028. curr = $selectMultiple.activeMatchIndex,
  1029. next = $selectMultiple.activeMatchIndex+1,
  1030. prev = $selectMultiple.activeMatchIndex-1,
  1031. newIndex = curr;
  1032. if(caretPosition > 0 || ($select.search.length && key == KEY.RIGHT)) return false;
  1033. $select.close();
  1034. function getNewActiveMatchIndex(){
  1035. switch(key){
  1036. case KEY.LEFT:
  1037. // Select previous/first item
  1038. if(~$selectMultiple.activeMatchIndex) return prev;
  1039. // Select last item
  1040. else return last;
  1041. break;
  1042. case KEY.RIGHT:
  1043. // Open drop-down
  1044. if(!~$selectMultiple.activeMatchIndex || curr === last){
  1045. $select.activate();
  1046. return false;
  1047. }
  1048. // Select next/last item
  1049. else return next;
  1050. break;
  1051. case KEY.BACKSPACE:
  1052. // Remove selected item and select previous/first
  1053. if(~$selectMultiple.activeMatchIndex){
  1054. $selectMultiple.removeChoice(curr);
  1055. return prev;
  1056. }
  1057. // Select last item
  1058. else return last;
  1059. break;
  1060. case KEY.DELETE:
  1061. // Remove selected item and select next item
  1062. if(~$selectMultiple.activeMatchIndex){
  1063. $selectMultiple.removeChoice($selectMultiple.activeMatchIndex);
  1064. return curr;
  1065. }
  1066. else return false;
  1067. }
  1068. }
  1069. newIndex = getNewActiveMatchIndex();
  1070. if(!$select.selected.length || newIndex === false) $selectMultiple.activeMatchIndex = -1;
  1071. else $selectMultiple.activeMatchIndex = Math.min(last,Math.max(first,newIndex));
  1072. return true;
  1073. }
  1074. $select.searchInput.on('keyup', function(e) {
  1075. if ( ! KEY.isVerticalMovement(e.which) ) {
  1076. scope.$evalAsync( function () {
  1077. $select.activeIndex = $select.taggingLabel === false ? -1 : 0;
  1078. });
  1079. }
  1080. // Push a "create new" item into array if there is a search string
  1081. if ( $select.tagging.isActivated && $select.search.length > 0 ) {
  1082. // return early with these keys
  1083. if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || KEY.isVerticalMovement(e.which) ) {
  1084. return;
  1085. }
  1086. // always reset the activeIndex to the first item when tagging
  1087. $select.activeIndex = $select.taggingLabel === false ? -1 : 0;
  1088. // taggingLabel === false bypasses all of this
  1089. if ($select.taggingLabel === false) return;
  1090. var items = angular.copy( $select.items );
  1091. var stashArr = angular.copy( $select.items );
  1092. var newItem;
  1093. var item;
  1094. var hasTag = false;
  1095. var dupeIndex = -1;
  1096. var tagItems;
  1097. var tagItem;
  1098. // case for object tagging via transform `$select.tagging.fct` function
  1099. if ( $select.tagging.fct !== undefined) {
  1100. tagItems = $select.$filter('filter')(items,{'isTag': true});
  1101. if ( tagItems.length > 0 ) {
  1102. tagItem = tagItems[0];
  1103. }
  1104. // remove the first element, if it has the `isTag` prop we generate a new one with each keyup, shaving the previous
  1105. if ( items.length > 0 && tagItem ) {
  1106. hasTag = true;
  1107. items = items.slice(1,items.length);
  1108. stashArr = stashArr.slice(1,stashArr.length);
  1109. }
  1110. newItem = $select.tagging.fct($select.search);
  1111. newItem.isTag = true;
  1112. // verify the the tag doesn't match the value of an existing item
  1113. if ( stashArr.filter( function (origItem) { return angular.equals( origItem, $select.tagging.fct($select.search) ); } ).length > 0 ) {
  1114. return;
  1115. }
  1116. newItem.isTag = true;
  1117. // handle newItem string and stripping dupes in tagging string context
  1118. } else {
  1119. // find any tagging items already in the $select.items array and store them
  1120. tagItems = $select.$filter('filter')(items,function (item) {
  1121. return item.match($select.taggingLabel);
  1122. });
  1123. if ( tagItems.length > 0 ) {
  1124. tagItem = tagItems[0];
  1125. }
  1126. item = items[0];
  1127. // remove existing tag item if found (should only ever be one tag item)
  1128. if ( item !== undefined && items.length > 0 && tagItem ) {
  1129. hasTag = true;
  1130. items = items.slice(1,items.length);
  1131. stashArr = stashArr.slice(1,stashArr.length);
  1132. }
  1133. newItem = $select.search+' '+$select.taggingLabel;
  1134. if ( _findApproxDupe($select.selected, $select.search) > -1 ) {
  1135. return;
  1136. }
  1137. // verify the the tag doesn't match the value of an existing item from
  1138. // the searched data set or the items already selected
  1139. if ( _findCaseInsensitiveDupe(stashArr.concat($select.selected)) ) {
  1140. // if there is a tag from prev iteration, strip it / queue the change
  1141. // and return early
  1142. if ( hasTag ) {
  1143. items = stashArr;
  1144. scope.$evalAsync( function () {
  1145. $select.activeIndex = 0;
  1146. $select.items = items;
  1147. });
  1148. }
  1149. return;
  1150. }
  1151. if ( _findCaseInsensitiveDupe(stashArr) ) {
  1152. // if there is a tag from prev iteration, strip it
  1153. if ( hasTag ) {
  1154. $select.items = stashArr.slice(1,stashArr.length);
  1155. }
  1156. return;
  1157. }
  1158. }
  1159. if ( hasTag ) dupeIndex = _findApproxDupe($select.selected, newItem);
  1160. // dupe found, shave the first item
  1161. if ( dupeIndex > -1 ) {
  1162. items = items.slice(dupeIndex+1,items.length-1);
  1163. } else {
  1164. items = [];
  1165. items.push(newItem);
  1166. items = items.concat(stashArr);
  1167. }
  1168. scope.$evalAsync( function () {
  1169. $select.activeIndex = 0;
  1170. $select.items = items;
  1171. });
  1172. }
  1173. });
  1174. function _findCaseInsensitiveDupe(arr) {
  1175. if ( arr === undefined || $select.search === undefined ) {
  1176. return false;
  1177. }
  1178. var hasDupe = arr.filter( function (origItem) {
  1179. if ( $select.search.toUpperCase() === undefined || origItem === undefined ) {
  1180. return false;
  1181. }
  1182. return origItem.toUpperCase() === $select.search.toUpperCase();
  1183. }).length > 0;
  1184. return hasDupe;
  1185. }
  1186. function _findApproxDupe(haystack, needle) {
  1187. var dupeIndex = -1;
  1188. if(angular.isArray(haystack)) {
  1189. var tempArr = angular.copy(haystack);
  1190. for (var i = 0; i <tempArr.length; i++) {
  1191. // handle the simple string version of tagging
  1192. if ( $select.tagging.fct === undefined ) {
  1193. // search the array for the match
  1194. if ( tempArr[i]+' '+$select.taggingLabel === needle ) {
  1195. dupeIndex = i;
  1196. }
  1197. // handle the object tagging implementation
  1198. } else {
  1199. var mockObj = tempArr[i];
  1200. mockObj.isTag = true;
  1201. if ( angular.equals(mockObj, needle) ) {
  1202. dupeIndex = i;
  1203. }
  1204. }
  1205. }
  1206. }
  1207. return dupeIndex;
  1208. }
  1209. $select.searchInput.on('blur', function() {
  1210. $timeout(function() {
  1211. $selectMultiple.activeMatchIndex = -1;
  1212. });
  1213. });
  1214. }
  1215. };
  1216. }]);
  1217. uis.directive('uiSelectSingle', ['$timeout','$compile', function($timeout, $compile) {
  1218. return {
  1219. restrict: 'EA',
  1220. require: ['^uiSelect', '^ngModel'],
  1221. link: function(scope, element, attrs, ctrls) {
  1222. var $select = ctrls[0];
  1223. var ngModel = ctrls[1];
  1224. //From view --> model
  1225. ngModel.$parsers.unshift(function (inputValue) {
  1226. var locals = {},
  1227. result;
  1228. locals[$select.parserResult.itemName] = inputValue;
  1229. result = $select.parserResult.modelMapper(scope, locals);
  1230. return result;
  1231. });
  1232. //From model --> view
  1233. ngModel.$formatters.unshift(function (inputValue) {
  1234. var data = $select.parserResult.source (scope, { $select : {search:''}}), //Overwrite $search
  1235. locals = {},
  1236. result;
  1237. if (data){
  1238. var checkFnSingle = function(d){
  1239. locals[$select.parserResult.itemName] = d;
  1240. result = $select.parserResult.modelMapper(scope, locals);
  1241. return result == inputValue;
  1242. };
  1243. //If possible pass same object stored in $select.selected
  1244. if ($select.selected && checkFnSingle($select.selected)) {
  1245. return $select.selected;
  1246. }
  1247. for (var i = data.length - 1; i >= 0; i--) {
  1248. if (checkFnSingle(data[i])) return data[i];
  1249. }
  1250. }
  1251. return inputValue;
  1252. });
  1253. //Update viewValue if model change
  1254. scope.$watch('$select.selected', function(newValue) {
  1255. if (ngModel.$viewValue !== newValue) {
  1256. ngModel.$setViewValue(newValue);
  1257. }
  1258. });
  1259. ngModel.$render = function() {
  1260. $select.selected = ngModel.$viewValue;
  1261. };
  1262. scope.$on('uis:select', function (event, item) {
  1263. $select.selected = item;
  1264. });
  1265. scope.$on('uis:close', function (event, skipFocusser) {
  1266. $timeout(function(){
  1267. $select.focusser.prop('disabled', false);
  1268. if (!skipFocusser) $select.focusser[0].focus();
  1269. },0,false);
  1270. });
  1271. scope.$on('uis:activate', function () {
  1272. focusser.prop('disabled', true); //Will reactivate it on .close()
  1273. });
  1274. //Idea from: https://github.com/ivaynberg/select2/blob/79b5bf6db918d7560bdd959109b7bcfb47edaf43/select2.js#L1954
  1275. 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' />");
  1276. $compile(focusser)(scope);
  1277. $select.focusser = focusser;
  1278. //Input that will handle focus
  1279. $select.focusInput = focusser;
  1280. element.parent().append(focusser);
  1281. focusser.bind("focus", function(){
  1282. scope.$evalAsync(function(){
  1283. $select.focus = true;
  1284. });
  1285. });
  1286. focusser.bind("blur", function(){
  1287. scope.$evalAsync(function(){
  1288. $select.focus = false;
  1289. });
  1290. });
  1291. focusser.bind("keydown", function(e){
  1292. if (e.which === KEY.BACKSPACE) {
  1293. e.preventDefault();
  1294. e.stopPropagation();
  1295. $select.select(undefined);
  1296. scope.$apply();
  1297. return;
  1298. }
  1299. if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC) {
  1300. return;
  1301. }
  1302. if (e.which == KEY.DOWN || e.which == KEY.UP || e.which == KEY.ENTER || e.which == KEY.SPACE){
  1303. e.preventDefault();
  1304. e.stopPropagation();
  1305. $select.activate();
  1306. }
  1307. scope.$digest();
  1308. });
  1309. focusser.bind("keyup input", function(e){
  1310. if (e.which === KEY.TAB || KEY.isControl(e) || KEY.isFunctionKey(e) || e.which === KEY.ESC || e.which == KEY.ENTER || e.which === KEY.BACKSPACE) {
  1311. return;
  1312. }
  1313. $select.activate(focusser.val()); //User pressed some regular key, so we pass it to the search input
  1314. focusser.val('');
  1315. scope.$digest();
  1316. });
  1317. }
  1318. };
  1319. }]);
  1320. // Make multiple matches sortable
  1321. uis.directive('uiSelectSort', ['$timeout', 'uiSelectConfig', 'uiSelectMinErr', function($timeout, uiSelectConfig, uiSelectMinErr) {
  1322. return {
  1323. require: '^uiSelect',
  1324. link: function(scope, element, attrs, $select) {
  1325. if (scope[attrs.uiSelectSort] === null) {
  1326. throw uiSelectMinErr('sort', "Expected a list to sort");
  1327. }
  1328. var options = angular.extend({
  1329. axis: 'horizontal'
  1330. },
  1331. scope.$eval(attrs.uiSelectSortOptions));
  1332. var axis = options.axis,
  1333. draggingClassName = 'dragging',
  1334. droppingClassName = 'dropping',
  1335. droppingBeforeClassName = 'dropping-before',
  1336. droppingAfterClassName = 'dropping-after';
  1337. scope.$watch(function(){
  1338. return $select.sortable;
  1339. }, function(n){
  1340. if (n) {
  1341. element.attr('draggable', true);
  1342. } else {
  1343. element.removeAttr('draggable');
  1344. }
  1345. });
  1346. element.on('dragstart', function(e) {
  1347. element.addClass(draggingClassName);
  1348. (e.dataTransfer || e.originalEvent.dataTransfer).setData('text/plain', scope.$index);
  1349. });
  1350. element.on('dragend', function() {
  1351. element.removeClass(draggingClassName);
  1352. });
  1353. var move = function(from, to) {
  1354. /*jshint validthis: true */
  1355. this.splice(to, 0, this.splice(from, 1)[0]);
  1356. };
  1357. var dragOverHandler = function(e) {
  1358. e.preventDefault();
  1359. var offset = axis === 'vertical' ? e.offsetY || e.layerY || (e.originalEvent ? e.originalEvent.offsetY : 0) : e.offsetX || e.layerX || (e.originalEvent ? e.originalEvent.offsetX : 0);
  1360. if (offset < (this[axis === 'vertical' ? 'offsetHeight' : 'offsetWidth'] / 2)) {
  1361. element.removeClass(droppingAfterClassName);
  1362. element.addClass(droppingBeforeClassName);
  1363. } else {
  1364. element.removeClass(droppingBeforeClassName);
  1365. element.addClass(droppingAfterClassName);
  1366. }
  1367. };
  1368. var dropTimeout;
  1369. var dropHandler = function(e) {
  1370. e.preventDefault();
  1371. var droppedItemIndex = parseInt((e.dataTransfer || e.originalEvent.dataTransfer).getData('text/plain'), 10);
  1372. // prevent event firing multiple times in firefox
  1373. $timeout.cancel(dropTimeout);
  1374. dropTimeout = $timeout(function() {
  1375. _dropHandler(droppedItemIndex);
  1376. }, 20);
  1377. };
  1378. var _dropHandler = function(droppedItemIndex) {
  1379. var theList = scope.$eval(attrs.uiSelectSort),
  1380. itemToMove = theList[droppedItemIndex],
  1381. newIndex = null;
  1382. if (element.hasClass(droppingBeforeClassName)) {
  1383. if (droppedItemIndex < scope.$index) {
  1384. newIndex = scope.$index - 1;
  1385. } else {
  1386. newIndex = scope.$index;
  1387. }
  1388. } else {
  1389. if (droppedItemIndex < scope.$index) {
  1390. newIndex = scope.$index;
  1391. } else {
  1392. newIndex = scope.$index + 1;
  1393. }
  1394. }
  1395. move.apply(theList, [droppedItemIndex, newIndex]);
  1396. scope.$apply(function() {
  1397. scope.$emit('uiSelectSort:change', {
  1398. array: theList,
  1399. item: itemToMove,
  1400. from: droppedItemIndex,
  1401. to: newIndex
  1402. });
  1403. });
  1404. element.removeClass(droppingClassName);
  1405. element.removeClass(droppingBeforeClassName);
  1406. element.removeClass(droppingAfterClassName);
  1407. element.off('drop', dropHandler);
  1408. };
  1409. element.on('dragenter', function() {
  1410. if (element.hasClass(draggingClassName)) {
  1411. return;
  1412. }
  1413. element.addClass(droppingClassName);
  1414. element.on('dragover', dragOverHandler);
  1415. element.on('drop', dropHandler);
  1416. });
  1417. element.on('dragleave', function(e) {
  1418. if (e.target != element) {
  1419. return;
  1420. }
  1421. element.removeClass(droppingClassName);
  1422. element.removeClass(droppingBeforeClassName);
  1423. element.removeClass(droppingAfterClassName);
  1424. element.off('dragover', dragOverHandler);
  1425. element.off('drop', dropHandler);
  1426. });
  1427. }
  1428. };
  1429. }]);
  1430. /**
  1431. * Parses "repeat" attribute.
  1432. *
  1433. * Taken from AngularJS ngRepeat source code
  1434. * See https://github.com/angular/angular.js/blob/v1.2.15/src/ng/directive/ngRepeat.js#L211
  1435. *
  1436. * Original discussion about parsing "repeat" attribute instead of fully relying on ng-repeat:
  1437. * https://github.com/angular-ui/ui-select/commit/5dd63ad#commitcomment-5504697
  1438. */
  1439. uis.service('uisRepeatParser', ['uiSelectMinErr','$parse', function(uiSelectMinErr, $parse) {
  1440. var self = this;
  1441. /**
  1442. * Example:
  1443. * expression = "address in addresses | filter: {street: $select.search} track by $index"
  1444. * itemName = "address",
  1445. * source = "addresses | filter: {street: $select.search}",
  1446. * trackByExp = "$index",
  1447. */
  1448. self.parse = function(expression) {
  1449. var match = expression.match(/^\s*(?:([\s\S]+?)\s+as\s+)?([\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
  1450. if (!match) {
  1451. throw uiSelectMinErr('iexp', "Expected expression in form of '_item_ in _collection_[ track by _id_]' but got '{0}'.",
  1452. expression);
  1453. }
  1454. return {
  1455. itemName: match[2], // (lhs) Left-hand side,
  1456. source: $parse(match[3]),
  1457. trackByExp: match[4],
  1458. modelMapper: $parse(match[1] || match[2])
  1459. };
  1460. };
  1461. self.getGroupNgRepeatExpression = function() {
  1462. return '$group in $select.groups';
  1463. };
  1464. self.getNgRepeatExpression = function(itemName, source, trackByExp, grouped) {
  1465. var expression = itemName + ' in ' + (grouped ? '$group.items' : source);
  1466. if (trackByExp) {
  1467. expression += ' track by ' + trackByExp;
  1468. }
  1469. return expression;
  1470. };
  1471. }]);
  1472. }());
  1473. 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>");
  1474. $templateCache.put("bootstrap/match-multiple.tpl.html","<span class=\"ui-select-match\"><span ng-repeat=\"$item in $select.selected\"><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)\">&nbsp;&times;</span> <span uis-transclude-append=\"\"></span></span></span></span>");
  1475. $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}\"><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()\" 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>");
  1476. $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=\"{{$selectMultiple.getPlaceholder()}}\" ng-disabled=\"$select.disabled\" ng-hide=\"$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>");
  1477. $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>");
  1478. $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>");
  1479. $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\':$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>");
  1480. $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>");
  1481. $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=\"text\" 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=\"select2-drop select2-with-searchbox select2-drop-active\" ng-class=\"{\'select2-display-none\': !$select.open}\"><div class=\"ui-select-choices\"></div></div></div>");
  1482. $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=\"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\" 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></div>");
  1483. $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\" 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>");
  1484. $templateCache.put("selectize/match.tpl.html","<div ng-hide=\"($select.open || $select.isEmpty())\" class=\"ui-select-match\" ng-transclude=\"\"></div>");
  1485. $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.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\" aria-label=\"{{ $select.baseTitle }}\"></div><div class=\"ui-select-choices\"></div></div>");}]);