bootstrap-select.js 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  1. /*!
  2. * Bootstrap-select v1.10.0 (http://silviomoreto.github.io/bootstrap-select)
  3. *
  4. * Copyright 2013-2016 bootstrap-select
  5. * Licensed under MIT (https://github.com/silviomoreto/bootstrap-select/blob/master/LICENSE)
  6. */
  7. (function (root, factory) {
  8. if (typeof define === 'function' && define.amd) {
  9. // AMD. Register as an anonymous module unless amdModuleId is set
  10. define(["jquery"], function (a0) {
  11. return (factory(a0));
  12. });
  13. } else if (typeof exports === 'object') {
  14. // Node. Does not work with strict CommonJS, but
  15. // only CommonJS-like environments that support module.exports,
  16. // like Node.
  17. module.exports = factory(require("jquery"));
  18. } else {
  19. factory(jQuery);
  20. }
  21. }(this, function (jQuery) {
  22. (function ($) {
  23. 'use strict';
  24. //<editor-fold desc="Shims">
  25. if (!String.prototype.includes) {
  26. (function () {
  27. 'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
  28. var toString = {}.toString;
  29. var defineProperty = (function () {
  30. // IE 8 only supports `Object.defineProperty` on DOM elements
  31. try {
  32. var object = {};
  33. var $defineProperty = Object.defineProperty;
  34. var result = $defineProperty(object, object, object) && $defineProperty;
  35. } catch (error) {
  36. }
  37. return result;
  38. }());
  39. var indexOf = ''.indexOf;
  40. var includes = function (search) {
  41. if (this == null) {
  42. throw new TypeError();
  43. }
  44. var string = String(this);
  45. if (search && toString.call(search) == '[object RegExp]') {
  46. throw new TypeError();
  47. }
  48. var stringLength = string.length;
  49. var searchString = String(search);
  50. var searchLength = searchString.length;
  51. var position = arguments.length > 1 ? arguments[1] : undefined;
  52. // `ToInteger`
  53. var pos = position ? Number(position) : 0;
  54. if (pos != pos) { // better `isNaN`
  55. pos = 0;
  56. }
  57. var start = Math.min(Math.max(pos, 0), stringLength);
  58. // Avoid the `indexOf` call if no match is possible
  59. if (searchLength + start > stringLength) {
  60. return false;
  61. }
  62. return indexOf.call(string, searchString, pos) != -1;
  63. };
  64. if (defineProperty) {
  65. defineProperty(String.prototype, 'includes', {
  66. 'value': includes,
  67. 'configurable': true,
  68. 'writable': true
  69. });
  70. } else {
  71. String.prototype.includes = includes;
  72. }
  73. }());
  74. }
  75. if (!String.prototype.startsWith) {
  76. (function () {
  77. 'use strict'; // needed to support `apply`/`call` with `undefined`/`null`
  78. var defineProperty = (function () {
  79. // IE 8 only supports `Object.defineProperty` on DOM elements
  80. try {
  81. var object = {};
  82. var $defineProperty = Object.defineProperty;
  83. var result = $defineProperty(object, object, object) && $defineProperty;
  84. } catch (error) {
  85. }
  86. return result;
  87. }());
  88. var toString = {}.toString;
  89. var startsWith = function (search) {
  90. if (this == null) {
  91. throw new TypeError();
  92. }
  93. var string = String(this);
  94. if (search && toString.call(search) == '[object RegExp]') {
  95. throw new TypeError();
  96. }
  97. var stringLength = string.length;
  98. var searchString = String(search);
  99. var searchLength = searchString.length;
  100. var position = arguments.length > 1 ? arguments[1] : undefined;
  101. // `ToInteger`
  102. var pos = position ? Number(position) : 0;
  103. if (pos != pos) { // better `isNaN`
  104. pos = 0;
  105. }
  106. var start = Math.min(Math.max(pos, 0), stringLength);
  107. // Avoid the `indexOf` call if no match is possible
  108. if (searchLength + start > stringLength) {
  109. return false;
  110. }
  111. var index = -1;
  112. while (++index < searchLength) {
  113. if (string.charCodeAt(start + index) != searchString.charCodeAt(index)) {
  114. return false;
  115. }
  116. }
  117. return true;
  118. };
  119. if (defineProperty) {
  120. defineProperty(String.prototype, 'startsWith', {
  121. 'value': startsWith,
  122. 'configurable': true,
  123. 'writable': true
  124. });
  125. } else {
  126. String.prototype.startsWith = startsWith;
  127. }
  128. }());
  129. }
  130. if (!Object.keys) {
  131. Object.keys = function (
  132. o, // object
  133. k, // key
  134. r // result array
  135. ){
  136. // initialize object and result
  137. r=[];
  138. // iterate over object keys
  139. for (k in o)
  140. // fill result array with non-prototypical keys
  141. r.hasOwnProperty.call(o, k) && r.push(k);
  142. // return result
  143. return r;
  144. };
  145. }
  146. $.fn.triggerNative = function (eventName) {
  147. var el = this[0],
  148. event;
  149. if (el.dispatchEvent) {
  150. if (typeof Event === 'function') {
  151. // For modern browsers
  152. event = new Event(eventName, {
  153. bubbles: true
  154. });
  155. } else {
  156. // For IE since it doesn't support Event constructor
  157. event = document.createEvent('Event');
  158. event.initEvent(eventName, true, false);
  159. }
  160. el.dispatchEvent(event);
  161. } else {
  162. if (el.fireEvent) {
  163. event = document.createEventObject();
  164. event.eventType = eventName;
  165. el.fireEvent('on' + eventName, event);
  166. }
  167. this.trigger(eventName);
  168. }
  169. };
  170. //</editor-fold>
  171. // Case insensitive contains search
  172. $.expr[':'].icontains = function (obj, index, meta) {
  173. var $obj = $(obj);
  174. var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase();
  175. return haystack.includes(meta[3].toUpperCase());
  176. };
  177. // Case insensitive begins search
  178. $.expr[':'].ibegins = function (obj, index, meta) {
  179. var $obj = $(obj);
  180. var haystack = ($obj.data('tokens') || $obj.text()).toString().toUpperCase();
  181. return haystack.startsWith(meta[3].toUpperCase());
  182. };
  183. // Case and accent insensitive contains search
  184. $.expr[':'].aicontains = function (obj, index, meta) {
  185. var $obj = $(obj);
  186. var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase();
  187. return haystack.includes(meta[3].toUpperCase());
  188. };
  189. // Case and accent insensitive begins search
  190. $.expr[':'].aibegins = function (obj, index, meta) {
  191. var $obj = $(obj);
  192. var haystack = ($obj.data('tokens') || $obj.data('normalizedText') || $obj.text()).toString().toUpperCase();
  193. return haystack.startsWith(meta[3].toUpperCase());
  194. };
  195. /**
  196. * Remove all diatrics from the given text.
  197. * @access private
  198. * @param {String} text
  199. * @returns {String}
  200. */
  201. function normalizeToBase(text) {
  202. var rExps = [
  203. {re: /[\xC0-\xC6]/g, ch: "A"},
  204. {re: /[\xE0-\xE6]/g, ch: "a"},
  205. {re: /[\xC8-\xCB]/g, ch: "E"},
  206. {re: /[\xE8-\xEB]/g, ch: "e"},
  207. {re: /[\xCC-\xCF]/g, ch: "I"},
  208. {re: /[\xEC-\xEF]/g, ch: "i"},
  209. {re: /[\xD2-\xD6]/g, ch: "O"},
  210. {re: /[\xF2-\xF6]/g, ch: "o"},
  211. {re: /[\xD9-\xDC]/g, ch: "U"},
  212. {re: /[\xF9-\xFC]/g, ch: "u"},
  213. {re: /[\xC7-\xE7]/g, ch: "c"},
  214. {re: /[\xD1]/g, ch: "N"},
  215. {re: /[\xF1]/g, ch: "n"}
  216. ];
  217. $.each(rExps, function () {
  218. text = text.replace(this.re, this.ch);
  219. });
  220. return text;
  221. }
  222. function htmlEscape(html) {
  223. var escapeMap = {
  224. '&': '&amp;',
  225. '<': '&lt;',
  226. '>': '&gt;',
  227. '"': '&quot;',
  228. "'": '&#x27;',
  229. '`': '&#x60;'
  230. };
  231. var source = '(?:' + Object.keys(escapeMap).join('|') + ')',
  232. testRegexp = new RegExp(source),
  233. replaceRegexp = new RegExp(source, 'g'),
  234. string = html == null ? '' : '' + html;
  235. return testRegexp.test(string) ? string.replace(replaceRegexp, function (match) {
  236. return escapeMap[match];
  237. }) : string;
  238. }
  239. var Selectpicker = function (element, options, e) {
  240. if (e) {
  241. e.stopPropagation();
  242. e.preventDefault();
  243. }
  244. this.$element = $(element);
  245. this.$newElement = null;
  246. this.$button = null;
  247. this.$menu = null;
  248. this.$lis = null;
  249. this.options = options;
  250. // If we have no title yet, try to pull it from the html title attribute (jQuery doesnt' pick it up as it's not a
  251. // data-attribute)
  252. if (this.options.title === null) {
  253. this.options.title = this.$element.attr('title');
  254. }
  255. //Expose public methods
  256. this.val = Selectpicker.prototype.val;
  257. this.render = Selectpicker.prototype.render;
  258. this.refresh = Selectpicker.prototype.refresh;
  259. this.setStyle = Selectpicker.prototype.setStyle;
  260. this.selectAll = Selectpicker.prototype.selectAll;
  261. this.deselectAll = Selectpicker.prototype.deselectAll;
  262. this.destroy = Selectpicker.prototype.destroy;
  263. this.remove = Selectpicker.prototype.remove;
  264. this.show = Selectpicker.prototype.show;
  265. this.hide = Selectpicker.prototype.hide;
  266. this.init();
  267. };
  268. Selectpicker.VERSION = '1.10.0';
  269. // part of this is duplicated in i18n/defaults-en_US.js. Make sure to update both.
  270. Selectpicker.DEFAULTS = {
  271. noneSelectedText: 'Nothing selected',
  272. noneResultsText: 'No results matched {0}',
  273. countSelectedText: function (numSelected, numTotal) {
  274. return (numSelected == 1) ? "{0} item selected" : "{0} items selected";
  275. },
  276. maxOptionsText: function (numAll, numGroup) {
  277. return [
  278. (numAll == 1) ? 'Limit reached ({n} item max)' : 'Limit reached ({n} items max)',
  279. (numGroup == 1) ? 'Group limit reached ({n} item max)' : 'Group limit reached ({n} items max)'
  280. ];
  281. },
  282. selectAllText: 'Select All',
  283. deselectAllText: 'Deselect All',
  284. doneButton: false,
  285. doneButtonText: 'Close',
  286. multipleSeparator: ', ',
  287. styleBase: 'btn',
  288. style: 'btn-default',
  289. size: 'auto',
  290. title: null,
  291. selectedTextFormat: 'values',
  292. width: false,
  293. container: false,
  294. hideDisabled: false,
  295. showSubtext: false,
  296. showIcon: true,
  297. showContent: true,
  298. dropupAuto: true,
  299. header: false,
  300. liveSearch: false,
  301. liveSearchPlaceholder: null,
  302. liveSearchNormalize: false,
  303. liveSearchStyle: 'contains',
  304. actionsBox: false,
  305. iconBase: 'glyphicon',
  306. tickIcon: 'glyphicon-ok',
  307. showTick: false,
  308. template: {
  309. caret: '<span class="caret"></span>'
  310. },
  311. maxOptions: false,
  312. mobile: false,
  313. selectOnTab: false,
  314. dropdownAlignRight: false
  315. };
  316. Selectpicker.prototype = {
  317. constructor: Selectpicker,
  318. init: function () {
  319. var that = this,
  320. id = this.$element.attr('id');
  321. this.$element.addClass('bs-select-hidden');
  322. // store originalIndex (key) and newIndex (value) in this.liObj for fast accessibility
  323. // allows us to do this.$lis.eq(that.liObj[index]) instead of this.$lis.filter('[data-original-index="' + index + '"]')
  324. this.liObj = {};
  325. this.multiple = this.$element.prop('multiple');
  326. this.autofocus = this.$element.prop('autofocus');
  327. this.$newElement = this.createView();
  328. this.$element
  329. .after(this.$newElement)
  330. .appendTo(this.$newElement);
  331. this.$button = this.$newElement.children('button');
  332. this.$menu = this.$newElement.children('.dropdown-menu');
  333. this.$menuInner = this.$menu.children('.inner');
  334. this.$searchbox = this.$menu.find('input');
  335. this.$element.removeClass('bs-select-hidden');
  336. if (this.options.dropdownAlignRight === true) this.$menu.addClass('dropdown-menu-right');
  337. if (typeof id !== 'undefined') {
  338. this.$button.attr('data-id', id);
  339. $('label[for="' + id + '"]').click(function (e) {
  340. e.preventDefault();
  341. that.$button.focus();
  342. });
  343. }
  344. this.checkDisabled();
  345. this.clickListener();
  346. if (this.options.liveSearch) this.liveSearchListener();
  347. this.render();
  348. this.setStyle();
  349. this.setWidth();
  350. if (this.options.container) this.selectPosition();
  351. this.$menu.data('this', this);
  352. this.$newElement.data('this', this);
  353. if (this.options.mobile) this.mobile();
  354. this.$newElement.on({
  355. 'hide.bs.dropdown': function (e) {
  356. that.$element.trigger('hide.bs.select', e);
  357. },
  358. 'hidden.bs.dropdown': function (e) {
  359. that.$element.trigger('hidden.bs.select', e);
  360. },
  361. 'show.bs.dropdown': function (e) {
  362. that.$element.trigger('show.bs.select', e);
  363. },
  364. 'shown.bs.dropdown': function (e) {
  365. that.$element.trigger('shown.bs.select', e);
  366. }
  367. });
  368. if (that.$element[0].hasAttribute('required')) {
  369. this.$element.on('invalid', function () {
  370. that.$button
  371. .addClass('bs-invalid')
  372. .focus();
  373. that.$element.on({
  374. 'focus.bs.select': function () {
  375. that.$button.focus();
  376. that.$element.off('focus.bs.select');
  377. },
  378. 'shown.bs.select': function () {
  379. that.$element
  380. .val(that.$element.val()) // set the value to hide the validation message in Chrome when menu is opened
  381. .off('shown.bs.select');
  382. },
  383. 'rendered.bs.select': function () {
  384. // if select is no longer invalid, remove the bs-invalid class
  385. if (this.validity.valid) that.$button.removeClass('bs-invalid');
  386. that.$element.off('rendered.bs.select');
  387. }
  388. });
  389. });
  390. }
  391. setTimeout(function () {
  392. that.$element.trigger('loaded.bs.select');
  393. });
  394. },
  395. createDropdown: function () {
  396. // Options
  397. // If we are multiple or showTick option is set, then add the show-tick class
  398. var showTick = (this.multiple || this.options.showTick) ? ' show-tick' : '',
  399. inputGroup = this.$element.parent().hasClass('input-group') ? ' input-group-btn' : '',
  400. autofocus = this.autofocus ? ' autofocus' : '';
  401. // Elements
  402. var header = this.options.header ? '<div class="popover-title"><button type="button" class="close" aria-hidden="true">&times;</button>' + this.options.header + '</div>' : '';
  403. var searchbox = this.options.liveSearch ?
  404. '<div class="bs-searchbox">' +
  405. '<input type="text" class="form-control" autocomplete="off"' +
  406. (null === this.options.liveSearchPlaceholder ? '' : ' placeholder="' + htmlEscape(this.options.liveSearchPlaceholder) + '"') + '>' +
  407. '</div>'
  408. : '';
  409. var actionsbox = this.multiple && this.options.actionsBox ?
  410. '<div class="bs-actionsbox">' +
  411. '<div class="btn-group btn-group-sm btn-block">' +
  412. '<button type="button" class="actions-btn bs-select-all btn btn-default">' +
  413. this.options.selectAllText +
  414. '</button>' +
  415. '<button type="button" class="actions-btn bs-deselect-all btn btn-default">' +
  416. this.options.deselectAllText +
  417. '</button>' +
  418. '</div>' +
  419. '</div>'
  420. : '';
  421. var donebutton = this.multiple && this.options.doneButton ?
  422. '<div class="bs-donebutton">' +
  423. '<div class="btn-group btn-block">' +
  424. '<button type="button" class="btn btn-sm btn-default">' +
  425. this.options.doneButtonText +
  426. '</button>' +
  427. '</div>' +
  428. '</div>'
  429. : '';
  430. var drop =
  431. '<div class="btn-group bootstrap-select' + showTick + inputGroup + '">' +
  432. '<button type="button" class="' + this.options.styleBase + ' dropdown-toggle" data-toggle="dropdown"' + autofocus + '>' +
  433. '<span class="filter-option pull-left"></span>&nbsp;' +
  434. '<span class="bs-caret">' +
  435. this.options.template.caret +
  436. '</span>' +
  437. '</button>' +
  438. '<div class="dropdown-menu open">' +
  439. header +
  440. searchbox +
  441. actionsbox +
  442. '<ul class="dropdown-menu inner" role="menu">' +
  443. '</ul>' +
  444. donebutton +
  445. '</div>' +
  446. '</div>';
  447. return $(drop);
  448. },
  449. createView: function () {
  450. var $drop = this.createDropdown(),
  451. li = this.createLi();
  452. $drop.find('ul')[0].innerHTML = li;
  453. return $drop;
  454. },
  455. reloadLi: function () {
  456. //Remove all children.
  457. this.destroyLi();
  458. //Re build
  459. var li = this.createLi();
  460. this.$menuInner[0].innerHTML = li;
  461. },
  462. destroyLi: function () {
  463. this.$menu.find('li').remove();
  464. },
  465. createLi: function () {
  466. var that = this,
  467. _li = [],
  468. optID = 0,
  469. titleOption = document.createElement('option'),
  470. liIndex = -1; // increment liIndex whenever a new <li> element is created to ensure liObj is correct
  471. // Helper functions
  472. /**
  473. * @param content
  474. * @param [index]
  475. * @param [classes]
  476. * @param [optgroup]
  477. * @returns {string}
  478. */
  479. var generateLI = function (content, index, classes, optgroup) {
  480. return '<li' +
  481. ((typeof classes !== 'undefined' & '' !== classes) ? ' class="' + classes + '"' : '') +
  482. ((typeof index !== 'undefined' & null !== index) ? ' data-original-index="' + index + '"' : '') +
  483. ((typeof optgroup !== 'undefined' & null !== optgroup) ? 'data-optgroup="' + optgroup + '"' : '') +
  484. '>' + content + '</li>';
  485. };
  486. /**
  487. * @param text
  488. * @param [classes]
  489. * @param [inline]
  490. * @param [tokens]
  491. * @returns {string}
  492. */
  493. var generateA = function (text, classes, inline, tokens) {
  494. return '<a tabindex="0"' +
  495. (typeof classes !== 'undefined' ? ' class="' + classes + '"' : '') +
  496. (typeof inline !== 'undefined' ? ' style="' + inline + '"' : '') +
  497. (that.options.liveSearchNormalize ? ' data-normalized-text="' + normalizeToBase(htmlEscape(text)) + '"' : '') +
  498. (typeof tokens !== 'undefined' || tokens !== null ? ' data-tokens="' + tokens + '"' : '') +
  499. '>' + text +
  500. '<span class="' + that.options.iconBase + ' ' + that.options.tickIcon + ' check-mark"></span>' +
  501. '</a>';
  502. };
  503. if (this.options.title && !this.multiple) {
  504. // this option doesn't create a new <li> element, but does add a new option, so liIndex is decreased
  505. // since liObj is recalculated on every refresh, liIndex needs to be decreased even if the titleOption is already appended
  506. liIndex--;
  507. if (!this.$element.find('.bs-title-option').length) {
  508. // Use native JS to prepend option (faster)
  509. var element = this.$element[0];
  510. titleOption.className = 'bs-title-option';
  511. titleOption.appendChild(document.createTextNode(this.options.title));
  512. titleOption.value = '';
  513. element.insertBefore(titleOption, element.firstChild);
  514. // Check if selected attribute is already set on an option. If not, select the titleOption option.
  515. // attr gets the 'default' selected option (from markup), prop gets the 'current' selected option
  516. // the selected item may have been changed by user or programmatically before the bootstrap select plugin runs
  517. var $opt = $(element.options[element.selectedIndex]);
  518. if ($opt.attr('selected') === undefined && $opt.prop('selected') === false) {
  519. titleOption.selected = true;
  520. }
  521. }
  522. }
  523. this.$element.find('option').each(function (index) {
  524. var $this = $(this);
  525. liIndex++;
  526. if ($this.hasClass('bs-title-option')) return;
  527. // Get the class and text for the option
  528. var optionClass = this.className || '',
  529. inline = this.style.cssText,
  530. text = $this.data('content') ? $this.data('content') : $this.html(),
  531. tokens = $this.data('tokens') ? $this.data('tokens') : null,
  532. subtext = typeof $this.data('subtext') !== 'undefined' ? '<small class="text-muted">' + $this.data('subtext') + '</small>' : '',
  533. icon = typeof $this.data('icon') !== 'undefined' ? '<span class="' + that.options.iconBase + ' ' + $this.data('icon') + '"></span> ' : '',
  534. isOptgroup = this.parentNode.tagName === 'OPTGROUP',
  535. isDisabled = this.disabled || (isOptgroup && this.parentNode.disabled);
  536. if (icon !== '' && isDisabled) {
  537. icon = '<span>' + icon + '</span>';
  538. }
  539. if (that.options.hideDisabled && (isDisabled && !isOptgroup || this.parentNode.disabled && isOptgroup)) {
  540. liIndex--;
  541. return;
  542. }
  543. if (!$this.data('content')) {
  544. // Prepend any icon and append any subtext to the main text.
  545. text = icon + '<span class="text">' + text + subtext + '</span>';
  546. }
  547. if (isOptgroup && $this.data('divider') !== true) {
  548. var optGroupClass = ' ' + this.parentNode.className || '';
  549. if ($this.index() === 0) { // Is it the first option of the optgroup?
  550. optID += 1;
  551. // Get the opt group label
  552. var label = this.parentNode.label,
  553. labelSubtext = typeof $this.parent().data('subtext') !== 'undefined' ? '<small class="text-muted">' + $this.parent().data('subtext') + '</small>' : '',
  554. labelIcon = $this.parent().data('icon') ? '<span class="' + that.options.iconBase + ' ' + $this.parent().data('icon') + '"></span> ' : '';
  555. label = labelIcon + '<span class="text">' + label + labelSubtext + '</span>';
  556. if (index !== 0 && _li.length > 0) { // Is it NOT the first option of the select && are there elements in the dropdown?
  557. liIndex++;
  558. _li.push(generateLI('', null, 'divider', optID + 'div'));
  559. }
  560. liIndex++;
  561. _li.push(generateLI(label, null, 'dropdown-header' + optGroupClass, optID));
  562. }
  563. if (that.options.hideDisabled && isDisabled) {
  564. liIndex--;
  565. return;
  566. }
  567. _li.push(generateLI(generateA(text, 'opt ' + optionClass + optGroupClass, inline, tokens), index, '', optID));
  568. } else if ($this.data('divider') === true) {
  569. _li.push(generateLI('', index, 'divider'));
  570. } else if ($this.data('hidden') === true) {
  571. _li.push(generateLI(generateA(text, optionClass, inline, tokens), index, 'hidden is-hidden'));
  572. } else {
  573. var showDivider = this.previousElementSibling && this.previousElementSibling.tagName === 'OPTGROUP';
  574. // if previous element is not an optgroup and hideDisabled is true
  575. if (!showDivider && that.options.hideDisabled) {
  576. // get previous elements
  577. var $prev = $(this).prevAll();
  578. for (var i = 0; i < $prev.length; i++) {
  579. // find the first element in the previous elements that is an optgroup
  580. if ($prev[i].tagName === 'OPTGROUP') {
  581. var optGroupDistance = 0;
  582. // loop through the options in between the current option and the optgroup
  583. // and check if they are hidden or disabled
  584. for (var d = 0; d < i; d++) {
  585. var prevOption = $prev[d];
  586. if (prevOption.disabled || $(prevOption).data('hidden') === true) optGroupDistance++;
  587. }
  588. // if all of the options between the current option and the optgroup are hidden or disabled, show the divider
  589. if (optGroupDistance === i) showDivider = true;
  590. break;
  591. }
  592. }
  593. }
  594. if (showDivider) {
  595. liIndex++;
  596. _li.push(generateLI('', null, 'divider', optID + 'div'));
  597. }
  598. _li.push(generateLI(generateA(text, optionClass, inline, tokens), index));
  599. }
  600. that.liObj[index] = liIndex;
  601. });
  602. //If we are not multiple, we don't have a selected item, and we don't have a title, select the first element so something is set in the button
  603. if (!this.multiple && this.$element.find('option:selected').length === 0 && !this.options.title) {
  604. this.$element.find('option').eq(0).prop('selected', true).attr('selected', 'selected');
  605. }
  606. return _li.join('');
  607. },
  608. findLis: function () {
  609. if (this.$lis == null) this.$lis = this.$menu.find('li');
  610. return this.$lis;
  611. },
  612. /**
  613. * @param [updateLi] defaults to true
  614. */
  615. render: function (updateLi) {
  616. var that = this,
  617. notDisabled;
  618. //Update the LI to match the SELECT
  619. if (updateLi !== false) {
  620. this.$element.find('option').each(function (index) {
  621. var $lis = that.findLis().eq(that.liObj[index]);
  622. that.setDisabled(index, this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled, $lis);
  623. that.setSelected(index, this.selected, $lis);
  624. });
  625. this.togglePlaceholder();
  626. }
  627. this.tabIndex();
  628. var selectedItems = this.$element.find('option').map(function () {
  629. if (this.selected) {
  630. if (that.options.hideDisabled && (this.disabled || this.parentNode.tagName === 'OPTGROUP' && this.parentNode.disabled)) return;
  631. var $this = $(this),
  632. icon = $this.data('icon') && that.options.showIcon ? '<i class="' + that.options.iconBase + ' ' + $this.data('icon') + '"></i> ' : '',
  633. subtext;
  634. if (that.options.showSubtext && $this.data('subtext') && !that.multiple) {
  635. subtext = ' <small class="text-muted">' + $this.data('subtext') + '</small>';
  636. } else {
  637. subtext = '';
  638. }
  639. if (typeof $this.attr('title') !== 'undefined') {
  640. return $this.attr('title');
  641. } else if ($this.data('content') && that.options.showContent) {
  642. return $this.data('content');
  643. } else {
  644. return icon + $this.html() + subtext;
  645. }
  646. }
  647. }).toArray();
  648. //Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled
  649. //Convert all the values into a comma delimited string
  650. var title = !this.multiple ? selectedItems[0] : selectedItems.join(this.options.multipleSeparator);
  651. //If this is multi select, and the selectText type is count, the show 1 of 2 selected etc..
  652. if (this.multiple && this.options.selectedTextFormat.indexOf('count') > -1) {
  653. var max = this.options.selectedTextFormat.split('>');
  654. if ((max.length > 1 && selectedItems.length > max[1]) || (max.length == 1 && selectedItems.length >= 2)) {
  655. notDisabled = this.options.hideDisabled ? ', [disabled]' : '';
  656. var totalCount = this.$element.find('option').not('[data-divider="true"], [data-hidden="true"]' + notDisabled).length,
  657. tr8nText = (typeof this.options.countSelectedText === 'function') ? this.options.countSelectedText(selectedItems.length, totalCount) : this.options.countSelectedText;
  658. title = tr8nText.replace('{0}', selectedItems.length.toString()).replace('{1}', totalCount.toString());
  659. }
  660. }
  661. if (this.options.title == undefined) {
  662. this.options.title = this.$element.attr('title');
  663. }
  664. if (this.options.selectedTextFormat == 'static') {
  665. title = this.options.title;
  666. }
  667. //If we dont have a title, then use the default, or if nothing is set at all, use the not selected text
  668. if (!title) {
  669. title = typeof this.options.title !== 'undefined' ? this.options.title : this.options.noneSelectedText;
  670. }
  671. //strip all html-tags and trim the result
  672. this.$button.attr('title', $.trim(title.replace(/<[^>]*>?/g, '')));
  673. this.$button.children('.filter-option').html(title);
  674. this.$element.trigger('rendered.bs.select');
  675. },
  676. /**
  677. * @param [style]
  678. * @param [status]
  679. */
  680. setStyle: function (style, status) {
  681. if (this.$element.attr('class')) {
  682. this.$newElement.addClass(this.$element.attr('class').replace(/selectpicker|mobile-device|bs-select-hidden|validate\[.*\]/gi, ''));
  683. }
  684. var buttonClass = style ? style : this.options.style;
  685. if (status == 'add') {
  686. this.$button.addClass(buttonClass);
  687. } else if (status == 'remove') {
  688. this.$button.removeClass(buttonClass);
  689. } else {
  690. this.$button.removeClass(this.options.style);
  691. this.$button.addClass(buttonClass);
  692. }
  693. },
  694. liHeight: function (refresh) {
  695. if (!refresh && (this.options.size === false || this.sizeInfo)) return;
  696. var newElement = document.createElement('div'),
  697. menu = document.createElement('div'),
  698. menuInner = document.createElement('ul'),
  699. divider = document.createElement('li'),
  700. li = document.createElement('li'),
  701. a = document.createElement('a'),
  702. text = document.createElement('span'),
  703. header = this.options.header && this.$menu.find('.popover-title').length > 0 ? this.$menu.find('.popover-title')[0].cloneNode(true) : null,
  704. search = this.options.liveSearch ? document.createElement('div') : null,
  705. actions = this.options.actionsBox && this.multiple && this.$menu.find('.bs-actionsbox').length > 0 ? this.$menu.find('.bs-actionsbox')[0].cloneNode(true) : null,
  706. doneButton = this.options.doneButton && this.multiple && this.$menu.find('.bs-donebutton').length > 0 ? this.$menu.find('.bs-donebutton')[0].cloneNode(true) : null;
  707. text.className = 'text';
  708. newElement.className = this.$menu[0].parentNode.className + ' open';
  709. menu.className = 'dropdown-menu open';
  710. menuInner.className = 'dropdown-menu inner';
  711. divider.className = 'divider';
  712. text.appendChild(document.createTextNode('Inner text'));
  713. a.appendChild(text);
  714. li.appendChild(a);
  715. menuInner.appendChild(li);
  716. menuInner.appendChild(divider);
  717. if (header) menu.appendChild(header);
  718. if (search) {
  719. // create a span instead of input as creating an input element is slower
  720. var input = document.createElement('span');
  721. search.className = 'bs-searchbox';
  722. input.className = 'form-control';
  723. search.appendChild(input);
  724. menu.appendChild(search);
  725. }
  726. if (actions) menu.appendChild(actions);
  727. menu.appendChild(menuInner);
  728. if (doneButton) menu.appendChild(doneButton);
  729. newElement.appendChild(menu);
  730. document.body.appendChild(newElement);
  731. var liHeight = a.offsetHeight,
  732. headerHeight = header ? header.offsetHeight : 0,
  733. searchHeight = search ? search.offsetHeight : 0,
  734. actionsHeight = actions ? actions.offsetHeight : 0,
  735. doneButtonHeight = doneButton ? doneButton.offsetHeight : 0,
  736. dividerHeight = $(divider).outerHeight(true),
  737. // fall back to jQuery if getComputedStyle is not supported
  738. menuStyle = typeof getComputedStyle === 'function' ? getComputedStyle(menu) : false,
  739. $menu = menuStyle ? null : $(menu),
  740. menuPadding = {
  741. vert: parseInt(menuStyle ? menuStyle.paddingTop : $menu.css('paddingTop')) +
  742. parseInt(menuStyle ? menuStyle.paddingBottom : $menu.css('paddingBottom')) +
  743. parseInt(menuStyle ? menuStyle.borderTopWidth : $menu.css('borderTopWidth')) +
  744. parseInt(menuStyle ? menuStyle.borderBottomWidth : $menu.css('borderBottomWidth')),
  745. horiz: parseInt(menuStyle ? menuStyle.paddingLeft : $menu.css('paddingLeft')) +
  746. parseInt(menuStyle ? menuStyle.paddingRight : $menu.css('paddingRight')) +
  747. parseInt(menuStyle ? menuStyle.borderLeftWidth : $menu.css('borderLeftWidth')) +
  748. parseInt(menuStyle ? menuStyle.borderRightWidth : $menu.css('borderRightWidth'))
  749. },
  750. menuExtras = {
  751. vert: menuPadding.vert +
  752. parseInt(menuStyle ? menuStyle.marginTop : $menu.css('marginTop')) +
  753. parseInt(menuStyle ? menuStyle.marginBottom : $menu.css('marginBottom')) + 2,
  754. horiz: menuPadding.horiz +
  755. parseInt(menuStyle ? menuStyle.marginLeft : $menu.css('marginLeft')) +
  756. parseInt(menuStyle ? menuStyle.marginRight : $menu.css('marginRight')) + 2
  757. }
  758. document.body.removeChild(newElement);
  759. this.sizeInfo = {
  760. liHeight: liHeight,
  761. headerHeight: headerHeight,
  762. searchHeight: searchHeight,
  763. actionsHeight: actionsHeight,
  764. doneButtonHeight: doneButtonHeight,
  765. dividerHeight: dividerHeight,
  766. menuPadding: menuPadding,
  767. menuExtras: menuExtras
  768. };
  769. },
  770. setSize: function () {
  771. this.findLis();
  772. this.liHeight();
  773. if (this.options.header) this.$menu.css('padding-top', 0);
  774. if (this.options.size === false) return;
  775. var that = this,
  776. $menu = this.$menu,
  777. $menuInner = this.$menuInner,
  778. $window = $(window),
  779. selectHeight = this.$newElement[0].offsetHeight,
  780. selectWidth = this.$newElement[0].offsetWidth,
  781. liHeight = this.sizeInfo['liHeight'],
  782. headerHeight = this.sizeInfo['headerHeight'],
  783. searchHeight = this.sizeInfo['searchHeight'],
  784. actionsHeight = this.sizeInfo['actionsHeight'],
  785. doneButtonHeight = this.sizeInfo['doneButtonHeight'],
  786. divHeight = this.sizeInfo['dividerHeight'],
  787. menuPadding = this.sizeInfo['menuPadding'],
  788. menuExtras = this.sizeInfo['menuExtras'],
  789. notDisabled = this.options.hideDisabled ? '.disabled' : '',
  790. menuHeight,
  791. menuWidth,
  792. getHeight,
  793. getWidth,
  794. selectOffsetTop,
  795. selectOffsetBot,
  796. selectOffsetLeft,
  797. selectOffsetRight,
  798. getPos = function() {
  799. var pos = that.$newElement.offset();
  800. selectOffsetTop = pos.top - $window.scrollTop();
  801. selectOffsetBot = $window.height() - selectOffsetTop - selectHeight;
  802. selectOffsetLeft = pos.left - $window.scrollLeft();
  803. selectOffsetRight = $window.width() - selectOffsetLeft - selectWidth;
  804. };
  805. getPos();
  806. if (this.options.size === 'auto') {
  807. var getSize = function () {
  808. var minHeight,
  809. hasClass = function (className, include) {
  810. return function (element) {
  811. if (include) {
  812. return (element.classList ? element.classList.contains(className) : $(element).hasClass(className));
  813. } else {
  814. return !(element.classList ? element.classList.contains(className) : $(element).hasClass(className));
  815. }
  816. };
  817. },
  818. lis = that.$menuInner[0].getElementsByTagName('li'),
  819. lisVisible = Array.prototype.filter ? Array.prototype.filter.call(lis, hasClass('hidden', false)) : that.$lis.not('.hidden'),
  820. optGroup = Array.prototype.filter ? Array.prototype.filter.call(lisVisible, hasClass('dropdown-header', true)) : lisVisible.filter('.dropdown-header');
  821. getPos();
  822. menuHeight = selectOffsetBot - menuExtras.vert;
  823. menuWidth = selectOffsetRight - menuExtras.horiz;
  824. if (that.options.container) {
  825. if (!$menu.data('height')) $menu.data('height', $menu.height());
  826. getHeight = $menu.data('height');
  827. if (!$menu.data('width')) $menu.data('width', $menu.width());
  828. getWidth = $menu.data('width');
  829. } else {
  830. getHeight = $menu.height();
  831. getWidth = $menu.width();
  832. }
  833. if (that.options.dropupAuto) {
  834. that.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight);
  835. }
  836. if (that.$newElement.hasClass('dropup')) {
  837. menuHeight = selectOffsetTop - menuExtras.vert;
  838. }
  839. if (that.options.dropdownAlignRight === 'auto') {
  840. $menu.toggleClass('dropdown-menu-right', selectOffsetLeft > selectOffsetRight && (menuWidth - menuExtras.horiz) < (getWidth - selectWidth));
  841. }
  842. if ((lisVisible.length + optGroup.length) > 3) {
  843. minHeight = liHeight * 3 + menuExtras.vert - 2;
  844. } else {
  845. minHeight = 0;
  846. }
  847. $menu.css({
  848. 'max-height': menuHeight + 'px',
  849. 'overflow': 'hidden',
  850. 'min-height': minHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px'
  851. });
  852. $menuInner.css({
  853. 'max-height': menuHeight - headerHeight - searchHeight - actionsHeight - doneButtonHeight - menuPadding.vert + 'px',
  854. 'overflow-y': 'auto',
  855. 'min-height': Math.max(minHeight - menuPadding.vert, 0) + 'px'
  856. });
  857. };
  858. getSize();
  859. this.$searchbox.off('input.getSize propertychange.getSize').on('input.getSize propertychange.getSize', getSize);
  860. $window.off('resize.getSize scroll.getSize').on('resize.getSize scroll.getSize', getSize);
  861. } else if (this.options.size && this.options.size != 'auto' && this.$lis.not(notDisabled).length > this.options.size) {
  862. var optIndex = this.$lis.not('.divider').not(notDisabled).children().slice(0, this.options.size).last().parent().index(),
  863. divLength = this.$lis.slice(0, optIndex + 1).filter('.divider').length;
  864. menuHeight = liHeight * this.options.size + divLength * divHeight + menuPadding.vert;
  865. if (that.options.container) {
  866. if (!$menu.data('height')) $menu.data('height', $menu.height());
  867. getHeight = $menu.data('height');
  868. } else {
  869. getHeight = $menu.height();
  870. }
  871. if (that.options.dropupAuto) {
  872. //noinspection JSUnusedAssignment
  873. this.$newElement.toggleClass('dropup', selectOffsetTop > selectOffsetBot && (menuHeight - menuExtras.vert) < getHeight);
  874. }
  875. $menu.css({
  876. 'max-height': menuHeight + headerHeight + searchHeight + actionsHeight + doneButtonHeight + 'px',
  877. 'overflow': 'hidden',
  878. 'min-height': ''
  879. });
  880. $menuInner.css({
  881. 'max-height': menuHeight - menuPadding.vert + 'px',
  882. 'overflow-y': 'auto',
  883. 'min-height': ''
  884. });
  885. }
  886. },
  887. setWidth: function () {
  888. if (this.options.width === 'auto') {
  889. this.$menu.css('min-width', '0');
  890. // Get correct width if element is hidden
  891. var $selectClone = this.$menu.parent().clone().appendTo('body'),
  892. $selectClone2 = this.options.container ? this.$newElement.clone().appendTo('body') : $selectClone,
  893. ulWidth = $selectClone.children('.dropdown-menu').outerWidth(),
  894. btnWidth = $selectClone2.css('width', 'auto').children('button').outerWidth();
  895. $selectClone.remove();
  896. $selectClone2.remove();
  897. // Set width to whatever's larger, button title or longest option
  898. this.$newElement.css('width', Math.max(ulWidth, btnWidth) + 'px');
  899. } else if (this.options.width === 'fit') {
  900. // Remove inline min-width so width can be changed from 'auto'
  901. this.$menu.css('min-width', '');
  902. this.$newElement.css('width', '').addClass('fit-width');
  903. } else if (this.options.width) {
  904. // Remove inline min-width so width can be changed from 'auto'
  905. this.$menu.css('min-width', '');
  906. this.$newElement.css('width', this.options.width);
  907. } else {
  908. // Remove inline min-width/width so width can be changed
  909. this.$menu.css('min-width', '');
  910. this.$newElement.css('width', '');
  911. }
  912. // Remove fit-width class if width is changed programmatically
  913. if (this.$newElement.hasClass('fit-width') && this.options.width !== 'fit') {
  914. this.$newElement.removeClass('fit-width');
  915. }
  916. },
  917. selectPosition: function () {
  918. this.$bsContainer = $('<div class="bs-container" />');
  919. var that = this,
  920. pos,
  921. actualHeight,
  922. getPlacement = function ($element) {
  923. that.$bsContainer.addClass($element.attr('class').replace(/form-control|fit-width/gi, '')).toggleClass('dropup', $element.hasClass('dropup'));
  924. pos = $element.offset();
  925. actualHeight = $element.hasClass('dropup') ? 0 : $element[0].offsetHeight;
  926. that.$bsContainer.css({
  927. 'top': pos.top + actualHeight,
  928. 'left': pos.left,
  929. 'width': $element[0].offsetWidth
  930. });
  931. };
  932. this.$button.on('click', function () {
  933. var $this = $(this);
  934. if (that.isDisabled()) {
  935. return;
  936. }
  937. getPlacement(that.$newElement);
  938. that.$bsContainer
  939. .appendTo(that.options.container)
  940. .toggleClass('open', !$this.hasClass('open'))
  941. .append(that.$menu);
  942. });
  943. $(window).on('resize scroll', function () {
  944. getPlacement(that.$newElement);
  945. });
  946. this.$element.on('hide.bs.select', function () {
  947. that.$menu.data('height', that.$menu.height());
  948. that.$bsContainer.detach();
  949. });
  950. },
  951. /**
  952. * @param {number} index - the index of the option that is being changed
  953. * @param {boolean} selected - true if the option is being selected, false if being deselected
  954. * @param {JQuery} $lis - the 'li' element that is being modified
  955. */
  956. setSelected: function (index, selected, $lis) {
  957. if (!$lis) {
  958. this.togglePlaceholder(); // check if setSelected is being called by changing the value of the select
  959. $lis = this.findLis().eq(this.liObj[index]);
  960. }
  961. $lis.toggleClass('selected', selected);
  962. },
  963. /**
  964. * @param {number} index - the index of the option that is being disabled
  965. * @param {boolean} disabled - true if the option is being disabled, false if being enabled
  966. * @param {JQuery} $lis - the 'li' element that is being modified
  967. */
  968. setDisabled: function (index, disabled, $lis) {
  969. if (!$lis) {
  970. $lis = this.findLis().eq(this.liObj[index]);
  971. }
  972. if (disabled) {
  973. $lis.addClass('disabled').children('a').attr('href', '#').attr('tabindex', -1);
  974. } else {
  975. $lis.removeClass('disabled').children('a').removeAttr('href').attr('tabindex', 0);
  976. }
  977. },
  978. isDisabled: function () {
  979. return this.$element[0].disabled;
  980. },
  981. checkDisabled: function () {
  982. var that = this;
  983. if (this.isDisabled()) {
  984. this.$newElement.addClass('disabled');
  985. this.$button.addClass('disabled').attr('tabindex', -1);
  986. } else {
  987. if (this.$button.hasClass('disabled')) {
  988. this.$newElement.removeClass('disabled');
  989. this.$button.removeClass('disabled');
  990. }
  991. if (this.$button.attr('tabindex') == -1 && !this.$element.data('tabindex')) {
  992. this.$button.removeAttr('tabindex');
  993. }
  994. }
  995. this.$button.click(function () {
  996. return !that.isDisabled();
  997. });
  998. },
  999. togglePlaceholder: function () {
  1000. var value = this.$element.val();
  1001. this.$button.toggleClass('bs-placeholder', value === null || value === '');
  1002. },
  1003. tabIndex: function () {
  1004. if (this.$element.data('tabindex') !== this.$element.attr('tabindex') &&
  1005. (this.$element.attr('tabindex') !== -98 && this.$element.attr('tabindex') !== '-98')) {
  1006. this.$element.data('tabindex', this.$element.attr('tabindex'));
  1007. this.$button.attr('tabindex', this.$element.data('tabindex'));
  1008. }
  1009. this.$element.attr('tabindex', -98);
  1010. },
  1011. clickListener: function () {
  1012. var that = this,
  1013. $document = $(document);
  1014. this.$newElement.on('touchstart.dropdown', '.dropdown-menu', function (e) {
  1015. e.stopPropagation();
  1016. });
  1017. $document.data('spaceSelect', false);
  1018. this.$button.on('keyup', function (e) {
  1019. if (/(32)/.test(e.keyCode.toString(10)) && $document.data('spaceSelect')) {
  1020. e.preventDefault();
  1021. $document.data('spaceSelect', false);
  1022. }
  1023. });
  1024. this.$button.on('click', function () {
  1025. that.setSize();
  1026. });
  1027. this.$element.on('shown.bs.select', function () {
  1028. if (!that.options.liveSearch && !that.multiple) {
  1029. that.$menuInner.find('.selected a').focus();
  1030. } else if (!that.multiple) {
  1031. var selectedIndex = that.liObj[that.$element[0].selectedIndex];
  1032. if (typeof selectedIndex !== 'number' || that.options.size === false) return;
  1033. // scroll to selected option
  1034. var offset = that.$lis.eq(selectedIndex)[0].offsetTop - that.$menuInner[0].offsetTop;
  1035. offset = offset - that.$menuInner[0].offsetHeight/2 + that.sizeInfo.liHeight/2;
  1036. that.$menuInner[0].scrollTop = offset;
  1037. }
  1038. });
  1039. this.$menuInner.on('click', 'li a', function (e) {
  1040. var $this = $(this),
  1041. clickedIndex = $this.parent().data('originalIndex'),
  1042. prevValue = that.$element.val(),
  1043. prevIndex = that.$element.prop('selectedIndex'),
  1044. triggerChange = true;
  1045. // Don't close on multi choice menu
  1046. if (that.multiple && that.options.maxOptions !== 1) {
  1047. e.stopPropagation();
  1048. }
  1049. e.preventDefault();
  1050. //Don't run if we have been disabled
  1051. if (!that.isDisabled() && !$this.parent().hasClass('disabled')) {
  1052. var $options = that.$element.find('option'),
  1053. $option = $options.eq(clickedIndex),
  1054. state = $option.prop('selected'),
  1055. $optgroup = $option.parent('optgroup'),
  1056. maxOptions = that.options.maxOptions,
  1057. maxOptionsGrp = $optgroup.data('maxOptions') || false;
  1058. if (!that.multiple) { // Deselect all others if not multi select box
  1059. $options.prop('selected', false);
  1060. $option.prop('selected', true);
  1061. that.$menuInner.find('.selected').removeClass('selected');
  1062. that.setSelected(clickedIndex, true);
  1063. } else { // Toggle the one we have chosen if we are multi select.
  1064. $option.prop('selected', !state);
  1065. that.setSelected(clickedIndex, !state);
  1066. $this.blur();
  1067. if (maxOptions !== false || maxOptionsGrp !== false) {
  1068. var maxReached = maxOptions < $options.filter(':selected').length,
  1069. maxReachedGrp = maxOptionsGrp < $optgroup.find('option:selected').length;
  1070. if ((maxOptions && maxReached) || (maxOptionsGrp && maxReachedGrp)) {
  1071. if (maxOptions && maxOptions == 1) {
  1072. $options.prop('selected', false);
  1073. $option.prop('selected', true);
  1074. that.$menuInner.find('.selected').removeClass('selected');
  1075. that.setSelected(clickedIndex, true);
  1076. } else if (maxOptionsGrp && maxOptionsGrp == 1) {
  1077. $optgroup.find('option:selected').prop('selected', false);
  1078. $option.prop('selected', true);
  1079. var optgroupID = $this.parent().data('optgroup');
  1080. that.$menuInner.find('[data-optgroup="' + optgroupID + '"]').removeClass('selected');
  1081. that.setSelected(clickedIndex, true);
  1082. } else {
  1083. var maxOptionsText = typeof that.options.maxOptionsText === 'string' ? [that.options.maxOptionsText, that.options.maxOptionsText] : that.options.maxOptionsText,
  1084. maxOptionsArr = typeof maxOptionsText === 'function' ? maxOptionsText(maxOptions, maxOptionsGrp) : maxOptionsText,
  1085. maxTxt = maxOptionsArr[0].replace('{n}', maxOptions),
  1086. maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp),
  1087. $notify = $('<div class="notify"></div>');
  1088. // If {var} is set in array, replace it
  1089. /** @deprecated */
  1090. if (maxOptionsArr[2]) {
  1091. maxTxt = maxTxt.replace('{var}', maxOptionsArr[2][maxOptions > 1 ? 0 : 1]);
  1092. maxTxtGrp = maxTxtGrp.replace('{var}', maxOptionsArr[2][maxOptionsGrp > 1 ? 0 : 1]);
  1093. }
  1094. $option.prop('selected', false);
  1095. that.$menu.append($notify);
  1096. if (maxOptions && maxReached) {
  1097. $notify.append($('<div>' + maxTxt + '</div>'));
  1098. triggerChange = false;
  1099. that.$element.trigger('maxReached.bs.select');
  1100. }
  1101. if (maxOptionsGrp && maxReachedGrp) {
  1102. $notify.append($('<div>' + maxTxtGrp + '</div>'));
  1103. triggerChange = false;
  1104. that.$element.trigger('maxReachedGrp.bs.select');
  1105. }
  1106. setTimeout(function () {
  1107. that.setSelected(clickedIndex, false);
  1108. }, 10);
  1109. $notify.delay(750).fadeOut(300, function () {
  1110. $(this).remove();
  1111. });
  1112. }
  1113. }
  1114. }
  1115. }
  1116. if (!that.multiple || (that.multiple && that.options.maxOptions === 1)) {
  1117. that.$button.focus();
  1118. } else if (that.options.liveSearch) {
  1119. that.$searchbox.focus();
  1120. }
  1121. // Trigger select 'change'
  1122. if (triggerChange) {
  1123. if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) {
  1124. // $option.prop('selected') is current option state (selected/unselected). state is previous option state.
  1125. that.$element
  1126. .trigger('changed.bs.select', [clickedIndex, $option.prop('selected'), state])
  1127. .triggerNative('change');
  1128. }
  1129. }
  1130. }
  1131. });
  1132. this.$menu.on('click', 'li.disabled a, .popover-title, .popover-title :not(.close)', function (e) {
  1133. if (e.currentTarget == this) {
  1134. e.preventDefault();
  1135. e.stopPropagation();
  1136. if (that.options.liveSearch && !$(e.target).hasClass('close')) {
  1137. that.$searchbox.focus();
  1138. } else {
  1139. that.$button.focus();
  1140. }
  1141. }
  1142. });
  1143. this.$menuInner.on('click', '.divider, .dropdown-header', function (e) {
  1144. e.preventDefault();
  1145. e.stopPropagation();
  1146. if (that.options.liveSearch) {
  1147. that.$searchbox.focus();
  1148. } else {
  1149. that.$button.focus();
  1150. }
  1151. });
  1152. this.$menu.on('click', '.popover-title .close', function () {
  1153. that.$button.click();
  1154. });
  1155. this.$searchbox.on('click', function (e) {
  1156. e.stopPropagation();
  1157. });
  1158. this.$menu.on('click', '.actions-btn', function (e) {
  1159. if (that.options.liveSearch) {
  1160. that.$searchbox.focus();
  1161. } else {
  1162. that.$button.focus();
  1163. }
  1164. e.preventDefault();
  1165. e.stopPropagation();
  1166. if ($(this).hasClass('bs-select-all')) {
  1167. that.selectAll();
  1168. } else {
  1169. that.deselectAll();
  1170. }
  1171. });
  1172. this.$element.change(function () {
  1173. that.render(false);
  1174. });
  1175. },
  1176. liveSearchListener: function () {
  1177. var that = this,
  1178. $no_results = $('<li class="no-results"></li>');
  1179. this.$button.on('click.dropdown.data-api touchstart.dropdown.data-api', function () {
  1180. that.$menuInner.find('.active').removeClass('active');
  1181. if (!!that.$searchbox.val()) {
  1182. that.$searchbox.val('');
  1183. that.$lis.not('.is-hidden').removeClass('hidden');
  1184. if (!!$no_results.parent().length) $no_results.remove();
  1185. }
  1186. if (!that.multiple) that.$menuInner.find('.selected').addClass('active');
  1187. setTimeout(function () {
  1188. that.$searchbox.focus();
  1189. }, 10);
  1190. });
  1191. this.$searchbox.on('click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api', function (e) {
  1192. e.stopPropagation();
  1193. });
  1194. this.$searchbox.on('input propertychange', function () {
  1195. if (that.$searchbox.val()) {
  1196. var $searchBase = that.$lis.not('.is-hidden').removeClass('hidden').children('a');
  1197. if (that.options.liveSearchNormalize) {
  1198. $searchBase = $searchBase.not(':a' + that._searchStyle() + '("' + normalizeToBase(that.$searchbox.val()) + '")');
  1199. } else {
  1200. $searchBase = $searchBase.not(':' + that._searchStyle() + '("' + that.$searchbox.val() + '")');
  1201. }
  1202. $searchBase.parent().addClass('hidden');
  1203. that.$lis.filter('.dropdown-header').each(function () {
  1204. var $this = $(this),
  1205. optgroup = $this.data('optgroup');
  1206. if (that.$lis.filter('[data-optgroup=' + optgroup + ']').not($this).not('.hidden').length === 0) {
  1207. $this.addClass('hidden');
  1208. that.$lis.filter('[data-optgroup=' + optgroup + 'div]').addClass('hidden');
  1209. }
  1210. });
  1211. var $lisVisible = that.$lis.not('.hidden');
  1212. // hide divider if first or last visible, or if followed by another divider
  1213. $lisVisible.each(function (index) {
  1214. var $this = $(this);
  1215. if ($this.hasClass('divider') && (
  1216. $this.index() === $lisVisible.first().index() ||
  1217. $this.index() === $lisVisible.last().index() ||
  1218. $lisVisible.eq(index + 1).hasClass('divider'))) {
  1219. $this.addClass('hidden');
  1220. }
  1221. });
  1222. if (!that.$lis.not('.hidden, .no-results').length) {
  1223. if (!!$no_results.parent().length) {
  1224. $no_results.remove();
  1225. }
  1226. $no_results.html(that.options.noneResultsText.replace('{0}', '"' + htmlEscape(that.$searchbox.val()) + '"')).show();
  1227. that.$menuInner.append($no_results);
  1228. } else if (!!$no_results.parent().length) {
  1229. $no_results.remove();
  1230. }
  1231. } else {
  1232. that.$lis.not('.is-hidden').removeClass('hidden');
  1233. if (!!$no_results.parent().length) {
  1234. $no_results.remove();
  1235. }
  1236. }
  1237. that.$lis.filter('.active').removeClass('active');
  1238. if (that.$searchbox.val()) that.$lis.not('.hidden, .divider, .dropdown-header').eq(0).addClass('active').children('a').focus();
  1239. $(this).focus();
  1240. });
  1241. },
  1242. _searchStyle: function () {
  1243. var styles = {
  1244. begins: 'ibegins',
  1245. startsWith: 'ibegins'
  1246. };
  1247. return styles[this.options.liveSearchStyle] || 'icontains';
  1248. },
  1249. val: function (value) {
  1250. if (typeof value !== 'undefined') {
  1251. this.$element.val(value);
  1252. this.render();
  1253. return this.$element;
  1254. } else {
  1255. return this.$element.val();
  1256. }
  1257. },
  1258. changeAll: function (status) {
  1259. if (typeof status === 'undefined') status = true;
  1260. this.findLis();
  1261. var $options = this.$element.find('option'),
  1262. $lisVisible = this.$lis.not('.divider, .dropdown-header, .disabled, .hidden'),
  1263. lisVisLen = $lisVisible.length,
  1264. selectedOptions = [];
  1265. if (status) {
  1266. if ($lisVisible.filter('.selected').length === $lisVisible.length) return;
  1267. } else {
  1268. if ($lisVisible.filter('.selected').length === 0) return;
  1269. }
  1270. $lisVisible.toggleClass('selected', status);
  1271. for (var i = 0; i < lisVisLen; i++) {
  1272. var origIndex = $lisVisible[i].getAttribute('data-original-index');
  1273. selectedOptions[selectedOptions.length] = $options.eq(origIndex)[0];
  1274. }
  1275. $(selectedOptions).prop('selected', status);
  1276. this.render(false);
  1277. this.togglePlaceholder();
  1278. this.$element
  1279. .trigger('changed.bs.select')
  1280. .triggerNative('change');
  1281. },
  1282. selectAll: function () {
  1283. return this.changeAll(true);
  1284. },
  1285. deselectAll: function () {
  1286. return this.changeAll(false);
  1287. },
  1288. toggle: function (e) {
  1289. e = e || window.event;
  1290. if (e) e.stopPropagation();
  1291. this.$button.trigger('click');
  1292. },
  1293. keydown: function (e) {
  1294. var $this = $(this),
  1295. $parent = $this.is('input') ? $this.parent().parent() : $this.parent(),
  1296. $items,
  1297. that = $parent.data('this'),
  1298. index,
  1299. next,
  1300. first,
  1301. last,
  1302. prev,
  1303. nextPrev,
  1304. prevIndex,
  1305. isActive,
  1306. selector = ':not(.disabled, .hidden, .dropdown-header, .divider)',
  1307. keyCodeMap = {
  1308. 32: ' ',
  1309. 48: '0',
  1310. 49: '1',
  1311. 50: '2',
  1312. 51: '3',
  1313. 52: '4',
  1314. 53: '5',
  1315. 54: '6',
  1316. 55: '7',
  1317. 56: '8',
  1318. 57: '9',
  1319. 59: ';',
  1320. 65: 'a',
  1321. 66: 'b',
  1322. 67: 'c',
  1323. 68: 'd',
  1324. 69: 'e',
  1325. 70: 'f',
  1326. 71: 'g',
  1327. 72: 'h',
  1328. 73: 'i',
  1329. 74: 'j',
  1330. 75: 'k',
  1331. 76: 'l',
  1332. 77: 'm',
  1333. 78: 'n',
  1334. 79: 'o',
  1335. 80: 'p',
  1336. 81: 'q',
  1337. 82: 'r',
  1338. 83: 's',
  1339. 84: 't',
  1340. 85: 'u',
  1341. 86: 'v',
  1342. 87: 'w',
  1343. 88: 'x',
  1344. 89: 'y',
  1345. 90: 'z',
  1346. 96: '0',
  1347. 97: '1',
  1348. 98: '2',
  1349. 99: '3',
  1350. 100: '4',
  1351. 101: '5',
  1352. 102: '6',
  1353. 103: '7',
  1354. 104: '8',
  1355. 105: '9'
  1356. };
  1357. if (that.options.liveSearch) $parent = $this.parent().parent();
  1358. if (that.options.container) $parent = that.$menu;
  1359. $items = $('[role=menu] li', $parent);
  1360. isActive = that.$newElement.hasClass('open');
  1361. if (!isActive && (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90)) {
  1362. if (!that.options.container) {
  1363. that.setSize();
  1364. that.$menu.parent().addClass('open');
  1365. isActive = true;
  1366. } else {
  1367. that.$button.trigger('click');
  1368. }
  1369. that.$searchbox.focus();
  1370. return;
  1371. }
  1372. if (that.options.liveSearch) {
  1373. if (/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && that.$menu.find('.active').length === 0) {
  1374. e.preventDefault();
  1375. that.$menu.parent().removeClass('open');
  1376. if (that.options.container) that.$newElement.removeClass('open');
  1377. that.$button.focus();
  1378. }
  1379. // $items contains li elements when liveSearch is enabled
  1380. $items = $('[role=menu] li' + selector, $parent);
  1381. if (!$this.val() && !/(38|40)/.test(e.keyCode.toString(10))) {
  1382. if ($items.filter('.active').length === 0) {
  1383. $items = that.$menuInner.find('li');
  1384. if (that.options.liveSearchNormalize) {
  1385. $items = $items.filter(':a' + that._searchStyle() + '(' + normalizeToBase(keyCodeMap[e.keyCode]) + ')');
  1386. } else {
  1387. $items = $items.filter(':' + that._searchStyle() + '(' + keyCodeMap[e.keyCode] + ')');
  1388. }
  1389. }
  1390. }
  1391. }
  1392. if (!$items.length) return;
  1393. if (/(38|40)/.test(e.keyCode.toString(10))) {
  1394. index = $items.index($items.find('a').filter(':focus').parent());
  1395. first = $items.filter(selector).first().index();
  1396. last = $items.filter(selector).last().index();
  1397. next = $items.eq(index).nextAll(selector).eq(0).index();
  1398. prev = $items.eq(index).prevAll(selector).eq(0).index();
  1399. nextPrev = $items.eq(next).prevAll(selector).eq(0).index();
  1400. if (that.options.liveSearch) {
  1401. $items.each(function (i) {
  1402. if (!$(this).hasClass('disabled')) {
  1403. $(this).data('index', i);
  1404. }
  1405. });
  1406. index = $items.index($items.filter('.active'));
  1407. first = $items.first().data('index');
  1408. last = $items.last().data('index');
  1409. next = $items.eq(index).nextAll().eq(0).data('index');
  1410. prev = $items.eq(index).prevAll().eq(0).data('index');
  1411. nextPrev = $items.eq(next).prevAll().eq(0).data('index');
  1412. }
  1413. prevIndex = $this.data('prevIndex');
  1414. if (e.keyCode == 38) {
  1415. if (that.options.liveSearch) index--;
  1416. if (index != nextPrev && index > prev) index = prev;
  1417. if (index < first) index = first;
  1418. if (index == prevIndex) index = last;
  1419. } else if (e.keyCode == 40) {
  1420. if (that.options.liveSearch) index++;
  1421. if (index == -1) index = 0;
  1422. if (index != nextPrev && index < next) index = next;
  1423. if (index > last) index = last;
  1424. if (index == prevIndex) index = first;
  1425. }
  1426. $this.data('prevIndex', index);
  1427. if (!that.options.liveSearch) {
  1428. $items.eq(index).children('a').focus();
  1429. } else {
  1430. e.preventDefault();
  1431. if (!$this.hasClass('dropdown-toggle')) {
  1432. $items.removeClass('active').eq(index).addClass('active').children('a').focus();
  1433. $this.focus();
  1434. }
  1435. }
  1436. } else if (!$this.is('input')) {
  1437. var keyIndex = [],
  1438. count,
  1439. prevKey;
  1440. $items.each(function () {
  1441. if (!$(this).hasClass('disabled')) {
  1442. if ($.trim($(this).children('a').text().toLowerCase()).substring(0, 1) == keyCodeMap[e.keyCode]) {
  1443. keyIndex.push($(this).index());
  1444. }
  1445. }
  1446. });
  1447. count = $(document).data('keycount');
  1448. count++;
  1449. $(document).data('keycount', count);
  1450. prevKey = $.trim($(':focus').text().toLowerCase()).substring(0, 1);
  1451. if (prevKey != keyCodeMap[e.keyCode]) {
  1452. count = 1;
  1453. $(document).data('keycount', count);
  1454. } else if (count >= keyIndex.length) {
  1455. $(document).data('keycount', 0);
  1456. if (count > keyIndex.length) count = 1;
  1457. }
  1458. $items.eq(keyIndex[count - 1]).children('a').focus();
  1459. }
  1460. // Select focused option if "Enter", "Spacebar" or "Tab" (when selectOnTab is true) are pressed inside the menu.
  1461. if ((/(13|32)/.test(e.keyCode.toString(10)) || (/(^9$)/.test(e.keyCode.toString(10)) && that.options.selectOnTab)) && isActive) {
  1462. if (!/(32)/.test(e.keyCode.toString(10))) e.preventDefault();
  1463. if (!that.options.liveSearch) {
  1464. var elem = $(':focus');
  1465. elem.click();
  1466. // Bring back focus for multiselects
  1467. elem.focus();
  1468. // Prevent screen from scrolling if the user hit the spacebar
  1469. e.preventDefault();
  1470. // Fixes spacebar selection of dropdown items in FF & IE
  1471. $(document).data('spaceSelect', true);
  1472. } else if (!/(32)/.test(e.keyCode.toString(10))) {
  1473. that.$menuInner.find('.active a').click();
  1474. $this.focus();
  1475. }
  1476. $(document).data('keycount', 0);
  1477. }
  1478. if ((/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && (that.multiple || that.options.liveSearch)) || (/(27)/.test(e.keyCode.toString(10)) && !isActive)) {
  1479. that.$menu.parent().removeClass('open');
  1480. if (that.options.container) that.$newElement.removeClass('open');
  1481. that.$button.focus();
  1482. }
  1483. },
  1484. mobile: function () {
  1485. this.$element.addClass('mobile-device');
  1486. },
  1487. refresh: function () {
  1488. this.$lis = null;
  1489. this.liObj = {};
  1490. this.reloadLi();
  1491. this.render();
  1492. this.checkDisabled();
  1493. this.liHeight(true);
  1494. this.setStyle();
  1495. this.setWidth();
  1496. if (this.$lis) this.$searchbox.trigger('propertychange');
  1497. this.$element.trigger('refreshed.bs.select');
  1498. },
  1499. hide: function () {
  1500. this.$newElement.hide();
  1501. },
  1502. show: function () {
  1503. this.$newElement.show();
  1504. },
  1505. remove: function () {
  1506. this.$newElement.remove();
  1507. this.$element.remove();
  1508. },
  1509. destroy: function () {
  1510. this.$newElement.before(this.$element).remove();
  1511. if (this.$bsContainer) {
  1512. this.$bsContainer.remove();
  1513. } else {
  1514. this.$menu.remove();
  1515. }
  1516. this.$element
  1517. .off('.bs.select')
  1518. .removeData('selectpicker')
  1519. .removeClass('bs-select-hidden selectpicker');
  1520. }
  1521. };
  1522. // SELECTPICKER PLUGIN DEFINITION
  1523. // ==============================
  1524. function Plugin(option, event) {
  1525. // get the args of the outer function..
  1526. var args = arguments;
  1527. // The arguments of the function are explicitly re-defined from the argument list, because the shift causes them
  1528. // to get lost/corrupted in android 2.3 and IE9 #715 #775
  1529. var _option = option,
  1530. _event = event;
  1531. [].shift.apply(args);
  1532. var value;
  1533. var chain = this.each(function () {
  1534. var $this = $(this);
  1535. if ($this.is('select')) {
  1536. var data = $this.data('selectpicker'),
  1537. options = typeof _option == 'object' && _option;
  1538. if (!data) {
  1539. var config = $.extend({}, Selectpicker.DEFAULTS, $.fn.selectpicker.defaults || {}, $this.data(), options);
  1540. config.template = $.extend({}, Selectpicker.DEFAULTS.template, ($.fn.selectpicker.defaults ? $.fn.selectpicker.defaults.template : {}), $this.data().template, options.template);
  1541. $this.data('selectpicker', (data = new Selectpicker(this, config, _event)));
  1542. } else if (options) {
  1543. for (var i in options) {
  1544. if (options.hasOwnProperty(i)) {
  1545. data.options[i] = options[i];
  1546. }
  1547. }
  1548. }
  1549. if (typeof _option == 'string') {
  1550. if (data[_option] instanceof Function) {
  1551. value = data[_option].apply(data, args);
  1552. } else {
  1553. value = data.options[_option];
  1554. }
  1555. }
  1556. }
  1557. });
  1558. if (typeof value !== 'undefined') {
  1559. //noinspection JSUnusedAssignment
  1560. return value;
  1561. } else {
  1562. return chain;
  1563. }
  1564. }
  1565. var old = $.fn.selectpicker;
  1566. $.fn.selectpicker = Plugin;
  1567. $.fn.selectpicker.Constructor = Selectpicker;
  1568. // SELECTPICKER NO CONFLICT
  1569. // ========================
  1570. $.fn.selectpicker.noConflict = function () {
  1571. $.fn.selectpicker = old;
  1572. return this;
  1573. };
  1574. $(document)
  1575. .data('keycount', 0)
  1576. .on('keydown.bs.select', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input', Selectpicker.prototype.keydown)
  1577. .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role="menu"], .bs-searchbox input', function (e) {
  1578. e.stopPropagation();
  1579. });
  1580. // SELECTPICKER DATA-API
  1581. // =====================
  1582. $(window).on('load.bs.select.data-api', function () {
  1583. $('.selectpicker').each(function () {
  1584. var $selectpicker = $(this);
  1585. Plugin.call($selectpicker, $selectpicker.data());
  1586. })
  1587. });
  1588. })(jQuery);
  1589. }));