select.js 89 KB

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