bootstrap-select.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. if (!Object.keys) {
  2. Object.keys = (function () {
  3. 'use strict';
  4. var hasOwnProperty = Object.prototype.hasOwnProperty,
  5. hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
  6. dontEnums = [
  7. 'toString',
  8. 'toLocaleString',
  9. 'valueOf',
  10. 'hasOwnProperty',
  11. 'isPrototypeOf',
  12. 'propertyIsEnumerable',
  13. 'constructor'
  14. ],
  15. dontEnumsLength = dontEnums.length;
  16. return function (obj) {
  17. if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
  18. throw new TypeError('Object.keys called on non-object');
  19. }
  20. var result = [], prop, i;
  21. for (prop in obj) {
  22. if (hasOwnProperty.call(obj, prop)) {
  23. result.push(prop);
  24. }
  25. }
  26. if (hasDontEnumBug) {
  27. for (i = 0; i < dontEnumsLength; i++) {
  28. if (hasOwnProperty.call(obj, dontEnums[i])) {
  29. result.push(dontEnums[i]);
  30. }
  31. }
  32. }
  33. return result;
  34. };
  35. }());
  36. }
  37. (function ($) {
  38. 'use strict';
  39. // Case insensitive search
  40. $.expr[':'].icontains = function (obj, index, meta) {
  41. return icontains($(obj).text(), meta[3]);
  42. };
  43. // Case and accent insensitive search
  44. $.expr[':'].aicontains = function (obj, index, meta) {
  45. return icontains($(obj).data('normalizedText') || $(obj).text(), meta[3]);
  46. };
  47. /**
  48. * Actual implementation of the case insensitive search.
  49. * @access private
  50. * @param {String} haystack
  51. * @param {String} needle
  52. * @returns {boolean}
  53. */
  54. function icontains(haystack, needle) {
  55. return haystack.toUpperCase().indexOf(needle.toUpperCase()) > -1;
  56. }
  57. /**
  58. * Remove all diatrics from the given text.
  59. * @access private
  60. * @param {String} text
  61. * @returns {String}
  62. */
  63. function normalizeToBase(text) {
  64. var rExps = [
  65. {re: /[\xC0-\xC6]/g, ch: "A"},
  66. {re: /[\xE0-\xE6]/g, ch: "a"},
  67. {re: /[\xC8-\xCB]/g, ch: "E"},
  68. {re: /[\xE8-\xEB]/g, ch: "e"},
  69. {re: /[\xCC-\xCF]/g, ch: "I"},
  70. {re: /[\xEC-\xEF]/g, ch: "i"},
  71. {re: /[\xD2-\xD6]/g, ch: "O"},
  72. {re: /[\xF2-\xF6]/g, ch: "o"},
  73. {re: /[\xD9-\xDC]/g, ch: "U"},
  74. {re: /[\xF9-\xFC]/g, ch: "u"},
  75. {re: /[\xC7-\xE7]/g, ch: "c"},
  76. {re: /[\xD1]/g, ch: "N"},
  77. {re: /[\xF1]/g, ch: "n"}
  78. ];
  79. $.each(rExps, function () {
  80. text = text.replace(this.re, this.ch);
  81. });
  82. return text;
  83. }
  84. function htmlEscape(html) {
  85. var escapeMap = {
  86. '&': '&amp;',
  87. '<': '&lt;',
  88. '>': '&gt;',
  89. '"': '&quot;',
  90. "'": '&#x27;',
  91. '`': '&#x60;'
  92. };
  93. var source = '(?:' + Object.keys(escapeMap).join('|') + ')',
  94. testRegexp = new RegExp(source),
  95. replaceRegexp = new RegExp(source, 'g'),
  96. string = html == null ? '' : '' + html;
  97. return testRegexp.test(string) ? string.replace(replaceRegexp, function (match) {
  98. return escapeMap[match];
  99. }) : string;
  100. }
  101. var Selectpicker = function (element, options, e) {
  102. if (e) {
  103. e.stopPropagation();
  104. e.preventDefault();
  105. }
  106. this.$element = $(element);
  107. this.$newElement = null;
  108. this.$button = null;
  109. this.$menu = null;
  110. this.$lis = null;
  111. this.options = options;
  112. // 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
  113. // data-attribute)
  114. if (this.options.title === null) {
  115. this.options.title = this.$element.attr('title');
  116. }
  117. //Expose public methods
  118. this.val = Selectpicker.prototype.val;
  119. this.render = Selectpicker.prototype.render;
  120. this.refresh = Selectpicker.prototype.refresh;
  121. this.setStyle = Selectpicker.prototype.setStyle;
  122. this.selectAll = Selectpicker.prototype.selectAll;
  123. this.deselectAll = Selectpicker.prototype.deselectAll;
  124. this.destroy = Selectpicker.prototype.remove;
  125. this.remove = Selectpicker.prototype.remove;
  126. this.show = Selectpicker.prototype.show;
  127. this.hide = Selectpicker.prototype.hide;
  128. this.init();
  129. };
  130. Selectpicker.VERSION = '1.6.3';
  131. // part of this is duplicated in i18n/defaults-en_US.js. Make sure to update both.
  132. Selectpicker.DEFAULTS = {
  133. noneSelectedText: 'Nothing selected',
  134. noneResultsText: 'No results match',
  135. countSelectedText: function (numSelected, numTotal) {
  136. return (numSelected == 1) ? "{0} item selected" : "{0} items selected";
  137. },
  138. maxOptionsText: function (numAll, numGroup) {
  139. var arr = [];
  140. arr[0] = (numAll == 1) ? 'Limit reached ({n} item max)' : 'Limit reached ({n} items max)';
  141. arr[1] = (numGroup == 1) ? 'Group limit reached ({n} item max)' : 'Group limit reached ({n} items max)';
  142. return arr;
  143. },
  144. selectAllText: 'Select All',
  145. deselectAllText: 'Deselect All',
  146. multipleSeparator: ', ',
  147. style: 'btn-default',
  148. size: 'auto',
  149. title: null,
  150. selectedTextFormat: 'values',
  151. width: false,
  152. container: false,
  153. hideDisabled: false,
  154. showSubtext: false,
  155. showIcon: true,
  156. showContent: true,
  157. dropupAuto: true,
  158. header: false,
  159. liveSearch: false,
  160. actionsBox: false,
  161. iconBase: 'glyphicon',
  162. tickIcon: 'glyphicon-ok',
  163. maxOptions: false,
  164. mobile: false,
  165. selectOnTab: false,
  166. dropdownAlignRight: false,
  167. searchAccentInsensitive: false
  168. };
  169. Selectpicker.prototype = {
  170. constructor: Selectpicker,
  171. init: function () {
  172. var that = this,
  173. id = this.$element.attr('id');
  174. this.$element.hide();
  175. this.multiple = this.$element.prop('multiple');
  176. this.autofocus = this.$element.prop('autofocus');
  177. this.$newElement = this.createView();
  178. this.$element.after(this.$newElement);
  179. this.$menu = this.$newElement.find('> .dropdown-menu');
  180. this.$button = this.$newElement.find('> button');
  181. this.$searchbox = this.$newElement.find('input');
  182. if (this.options.dropdownAlignRight)
  183. this.$menu.addClass('dropdown-menu-right');
  184. if (typeof id !== 'undefined') {
  185. this.$button.attr('data-id', id);
  186. $('label[for="' + id + '"]').click(function (e) {
  187. e.preventDefault();
  188. that.$button.focus();
  189. });
  190. }
  191. this.checkDisabled();
  192. this.clickListener();
  193. if (this.options.liveSearch) this.liveSearchListener();
  194. this.render();
  195. this.liHeight();
  196. this.setStyle();
  197. this.setWidth();
  198. if (this.options.container) this.selectPosition();
  199. this.$menu.data('this', this);
  200. this.$newElement.data('this', this);
  201. if (this.options.mobile) this.mobile();
  202. },
  203. createDropdown: function () {
  204. // Options
  205. // If we are multiple, then add the show-tick class by default
  206. var multiple = this.multiple ? ' show-tick' : '',
  207. inputGroup = this.$element.parent().hasClass('input-group') ? ' input-group-btn' : '',
  208. autofocus = this.autofocus ? ' autofocus' : '',
  209. btnSize = this.$element.parents().hasClass('form-group-lg') ? ' btn-lg' : (this.$element.parents().hasClass('form-group-sm') ? ' btn-sm' : '');
  210. // Elements
  211. var header = this.options.header ? '<div class="popover-title"><button type="button" class="close" aria-hidden="true">&times;</button>' + this.options.header + '</div>' : '';
  212. var searchbox = this.options.liveSearch ? '<div class="bs-searchbox"><input type="text" class="input-block-level form-control" autocomplete="off" /></div>' : '';
  213. var actionsbox = this.options.actionsBox ? '<div class="bs-actionsbox">' +
  214. '<div class="btn-group btn-block">' +
  215. '<button class="actions-btn bs-select-all btn btn-sm btn-default">' +
  216. this.options.selectAllText +
  217. '</button>' +
  218. '<button class="actions-btn bs-deselect-all btn btn-sm btn-default">' +
  219. this.options.deselectAllText +
  220. '</button>' +
  221. '</div>' +
  222. '</div>' : '';
  223. var drop =
  224. '<div class="btn-group bootstrap-select' + multiple + inputGroup + '">' +
  225. '<button type="button" class="btn dropdown-toggle selectpicker' + btnSize + '" data-toggle="dropdown"' + autofocus + '>' +
  226. '<span class="filter-option pull-left"></span>&nbsp;' +
  227. '<span class="caret"></span>' +
  228. '</button>' +
  229. '<div class="dropdown-menu open">' +
  230. header +
  231. searchbox +
  232. actionsbox +
  233. '<ul class="dropdown-menu inner selectpicker" role="menu">' +
  234. '</ul>' +
  235. '</div>' +
  236. '</div>';
  237. return $(drop);
  238. },
  239. createView: function () {
  240. var $drop = this.createDropdown();
  241. var $li = this.createLi();
  242. $drop.find('ul').append($li);
  243. return $drop;
  244. },
  245. reloadLi: function () {
  246. //Remove all children.
  247. this.destroyLi();
  248. //Re build
  249. var $li = this.createLi();
  250. this.$menu.find('ul').append($li);
  251. },
  252. destroyLi: function () {
  253. this.$menu.find('li').remove();
  254. },
  255. createLi: function () {
  256. var that = this,
  257. _li = [],
  258. optID = 0;
  259. // Helper functions
  260. /**
  261. * @param content
  262. * @param [index]
  263. * @param [classes]
  264. * @returns {string}
  265. */
  266. var generateLI = function (content, index, classes) {
  267. return '<li' +
  268. (typeof classes !== 'undefined' ? ' class="' + classes + '"' : '') +
  269. (typeof index !== 'undefined' | null === index ? ' data-original-index="' + index + '"' : '') +
  270. '>' + content + '</li>';
  271. };
  272. /**
  273. * @param text
  274. * @param [classes]
  275. * @param [inline]
  276. * @param [optgroup]
  277. * @returns {string}
  278. */
  279. var generateA = function (text, classes, inline, optgroup) {
  280. var normText = normalizeToBase(htmlEscape(text));
  281. return '<a tabindex="0"' +
  282. (typeof classes !== 'undefined' ? ' class="' + classes + '"' : '') +
  283. (typeof inline !== 'undefined' ? ' style="' + inline + '"' : '') +
  284. (typeof optgroup !== 'undefined' ? 'data-optgroup="' + optgroup + '"' : '') +
  285. ' data-normalized-text="' + normText + '"' +
  286. '>' + text +
  287. '<span class="' + that.options.iconBase + ' ' + that.options.tickIcon + ' check-mark"></span>' +
  288. '</a>';
  289. };
  290. this.$element.find('option').each(function (_index) {
  291. var $this = $(this);
  292. // Get the class and text for the option
  293. var optionClass = $this.attr('class') || '',
  294. inline = $this.attr('style'),
  295. text = $this.data('content') ? $this.data('content') : $this.html(),
  296. subtext = typeof $this.data('subtext') !== 'undefined' ? '<small class="muted text-muted">' + $this.data('subtext') + '</small>' : '',
  297. icon = typeof $this.data('icon') !== 'undefined' ? '<span class="' + that.options.iconBase + ' ' + $this.data('icon') + '"></span> ' : '',
  298. isDisabled = $this.is(':disabled') || $this.parent().is(':disabled'),
  299. index = _index;//$this[0].index;
  300. if (icon !== '' && isDisabled) {
  301. icon = '<span>' + icon + '</span>';
  302. }
  303. if (!$this.data('content')) {
  304. // Prepend any icon and append any subtext to the main text.
  305. text = icon + '<span class="text">' + text + subtext + '</span>';
  306. }
  307. if (that.options.hideDisabled && isDisabled) {
  308. return;
  309. }
  310. if ($this.parent().is('optgroup') && $this.data('divider') !== true) {
  311. if ($this.index() === 0) { // Is it the first option of the optgroup?
  312. optID += 1;
  313. // Get the opt group label
  314. var label = $this.parent().attr('label');
  315. var labelSubtext = typeof $this.parent().data('subtext') !== 'undefined' ? '<small class="muted text-muted">' + $this.parent().data('subtext') + '</small>' : '';
  316. var labelIcon = $this.parent().data('icon') ? '<span class="' + that.options.iconBase + ' ' + $this.parent().data('icon') + '"></span> ' : '';
  317. label = labelIcon + '<span class="text">' + label + labelSubtext + '</span>';
  318. if (index !== 0 && _li.length > 0) { // Is it NOT the first option of the select && are there elements in the dropdown?
  319. _li.push(generateLI('', null, 'divider'));
  320. }
  321. _li.push(generateLI(label, null, 'dropdown-header'));
  322. }
  323. _li.push(generateLI(generateA(text, 'opt ' + optionClass, inline, optID), index));
  324. } else if ($this.data('divider') === true) {
  325. _li.push(generateLI('', index, 'divider'));
  326. } else if ($this.data('hidden') === true) {
  327. _li.push(generateLI(generateA(text, optionClass, inline), index, 'hide is-hidden'));
  328. } else {
  329. _li.push(generateLI(generateA(text, optionClass, inline), index));
  330. }
  331. });
  332. //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
  333. if (!this.multiple && this.$element.find('option:selected').length === 0 && !this.options.title) {
  334. this.$element.find('option').eq(0).prop('selected', true).attr('selected', 'selected');
  335. }
  336. return $(_li.join(''));
  337. },
  338. findLis: function () {
  339. if (this.$lis == null) this.$lis = this.$menu.find('li');
  340. return this.$lis;
  341. },
  342. /**
  343. * @param [updateLi] defaults to true
  344. */
  345. render: function (updateLi) {
  346. var that = this;
  347. //Update the LI to match the SELECT
  348. if (updateLi !== false) {
  349. this.$element.find('option').each(function (index) {
  350. that.setDisabled(index, $(this).is(':disabled') || $(this).parent().is(':disabled'));
  351. that.setSelected(index, $(this).is(':selected'));
  352. });
  353. }
  354. this.tabIndex();
  355. var notDisabled = this.options.hideDisabled ? ':not([disabled])' : '';
  356. var selectedItems = this.$element.find('option:selected' + notDisabled).map(function () {
  357. var $this = $(this);
  358. var icon = $this.data('icon') && that.options.showIcon ? '<i class="' + that.options.iconBase + ' ' + $this.data('icon') + '"></i> ' : '';
  359. var subtext;
  360. if (that.options.showSubtext && $this.attr('data-subtext') && !that.multiple) {
  361. subtext = ' <small class="muted text-muted">' + $this.data('subtext') + '</small>';
  362. } else {
  363. subtext = '';
  364. }
  365. if ($this.data('content') && that.options.showContent) {
  366. return $this.data('content');
  367. } else if (typeof $this.attr('title') !== 'undefined') {
  368. return $this.attr('title');
  369. } else {
  370. return icon + $this.html() + subtext;
  371. }
  372. }).toArray();
  373. //Fixes issue in IE10 occurring when no default option is selected and at least one option is disabled
  374. //Convert all the values into a comma delimited string
  375. var title = !this.multiple ? selectedItems[0] : selectedItems.join(this.options.multipleSeparator);
  376. //If this is multi select, and the selectText type is count, the show 1 of 2 selected etc..
  377. if (this.multiple && this.options.selectedTextFormat.indexOf('count') > -1) {
  378. var max = this.options.selectedTextFormat.split('>');
  379. if ((max.length > 1 && selectedItems.length > max[1]) || (max.length == 1 && selectedItems.length >= 2)) {
  380. notDisabled = this.options.hideDisabled ? ', [disabled]' : '';
  381. var totalCount = this.$element.find('option').not('[data-divider="true"], [data-hidden="true"]' + notDisabled).length,
  382. tr8nText = (typeof this.options.countSelectedText === 'function') ? this.options.countSelectedText(selectedItems.length, totalCount) : this.options.countSelectedText;
  383. title = tr8nText.replace('{0}', selectedItems.length.toString()).replace('{1}', totalCount.toString());
  384. }
  385. }
  386. this.options.title = this.$element.attr('title');
  387. if (this.options.selectedTextFormat == 'static') {
  388. title = this.options.title;
  389. }
  390. //If we dont have a title, then use the default, or if nothing is set at all, use the not selected text
  391. if (!title) {
  392. title = typeof this.options.title !== 'undefined' ? this.options.title : this.options.noneSelectedText;
  393. }
  394. this.$button.attr('title', htmlEscape(title));
  395. this.$newElement.find('.filter-option').html(title);
  396. },
  397. /**
  398. * @param [style]
  399. * @param [status]
  400. */
  401. setStyle: function (style, status) {
  402. if (this.$element.attr('class')) {
  403. this.$newElement.addClass(this.$element.attr('class').replace(/selectpicker|mobile-device|validate\[.*\]/gi, ''));
  404. }
  405. var buttonClass = style ? style : this.options.style;
  406. if (status == 'add') {
  407. this.$button.addClass(buttonClass);
  408. } else if (status == 'remove') {
  409. this.$button.removeClass(buttonClass);
  410. } else {
  411. this.$button.removeClass(this.options.style);
  412. this.$button.addClass(buttonClass);
  413. }
  414. },
  415. liHeight: function () {
  416. if (this.options.size === false) return;
  417. var $selectClone = this.$menu.parent().clone().find('> .dropdown-toggle').prop('autofocus', false).end().appendTo('body'),
  418. $menuClone = $selectClone.addClass('open').find('> .dropdown-menu'),
  419. liHeight = $menuClone.find('li').not('.divider').not('.dropdown-header').filter(':visible').children('a').outerHeight(),
  420. headerHeight = this.options.header ? $menuClone.find('.popover-title').outerHeight() : 0,
  421. searchHeight = this.options.liveSearch ? $menuClone.find('.bs-searchbox').outerHeight() : 0,
  422. actionsHeight = this.options.actionsBox ? $menuClone.find('.bs-actionsbox').outerHeight() : 0;
  423. $selectClone.remove();
  424. this.$newElement
  425. .data('liHeight', liHeight)
  426. .data('headerHeight', headerHeight)
  427. .data('searchHeight', searchHeight)
  428. .data('actionsHeight', actionsHeight);
  429. },
  430. setSize: function () {
  431. this.findLis();
  432. var that = this,
  433. menu = this.$menu,
  434. menuInner = menu.find('.inner'),
  435. selectHeight = this.$newElement.outerHeight(),
  436. liHeight = this.$newElement.data('liHeight'),
  437. headerHeight = this.$newElement.data('headerHeight'),
  438. searchHeight = this.$newElement.data('searchHeight'),
  439. actionsHeight = this.$newElement.data('actionsHeight'),
  440. divHeight = this.$lis.filter('.divider').outerHeight(true),
  441. menuPadding = parseInt(menu.css('padding-top')) +
  442. parseInt(menu.css('padding-bottom')) +
  443. parseInt(menu.css('border-top-width')) +
  444. parseInt(menu.css('border-bottom-width')),
  445. notDisabled = this.options.hideDisabled ? ', .disabled' : '',
  446. $window = $(window),
  447. menuExtras = menuPadding + parseInt(menu.css('margin-top')) + parseInt(menu.css('margin-bottom')) + 2,
  448. menuHeight,
  449. selectOffsetTop,
  450. selectOffsetBot,
  451. posVert = function () {
  452. // JQuery defines a scrollTop function, but in pure JS it's a property
  453. //noinspection JSValidateTypes
  454. selectOffsetTop = that.$newElement.offset().top - $window.scrollTop();
  455. selectOffsetBot = $window.height() - selectOffsetTop - selectHeight;
  456. };
  457. posVert();
  458. if (this.options.header) menu.css('padding-top', 0);
  459. if (this.options.size == 'auto') {
  460. var getSize = function () {
  461. var minHeight,
  462. lisVis = that.$lis.not('.hide');
  463. posVert();
  464. menuHeight = selectOffsetBot - menuExtras;
  465. if (that.options.dropupAuto) {
  466. that.$newElement.toggleClass('dropup', (selectOffsetTop > selectOffsetBot) && ((menuHeight - menuExtras) < menu.height()));
  467. }
  468. if (that.$newElement.hasClass('dropup')) {
  469. menuHeight = selectOffsetTop - menuExtras;
  470. }
  471. if ((lisVis.length + lisVis.filter('.dropdown-header').length) > 3) {
  472. minHeight = liHeight * 3 + menuExtras - 2;
  473. } else {
  474. minHeight = 0;
  475. }
  476. menu.css({
  477. 'max-height': menuHeight + 'px',
  478. 'overflow': 'hidden',
  479. 'min-height': minHeight + headerHeight + searchHeight + actionsHeight + 'px'
  480. });
  481. menuInner.css({
  482. 'max-height': menuHeight - headerHeight - searchHeight - actionsHeight - menuPadding + 'px',
  483. 'overflow-y': 'auto',
  484. 'min-height': Math.max(minHeight - menuPadding, 0) + 'px'
  485. });
  486. };
  487. getSize();
  488. this.$searchbox.off('input.getSize propertychange.getSize').on('input.getSize propertychange.getSize', getSize);
  489. $(window).off('resize.getSize').on('resize.getSize', getSize);
  490. $(window).off('scroll.getSize').on('scroll.getSize', getSize);
  491. /*K'naan add -- BEGIN*/
  492. var $lis = menuInner.find('> li');
  493. var realHeight = parseFloat($lis.outerHeight() * $lis.length);
  494. var maxHeight = parseFloat(menu.css('max-height'));
  495. if (!menu.data('add20') && realHeight > maxHeight) {
  496. menu.css('width', menu.width() + 20).data('add20', true);
  497. }
  498. /*K'naan add -- END*/
  499. } else if (this.options.size && this.options.size != 'auto' && menu.find('li' + notDisabled).length > this.options.size) {
  500. var optIndex = this.$lis.not('.divider' + notDisabled).find(' > *').slice(0, this.options.size).last().parent().index();
  501. var divLength = this.$lis.slice(0, optIndex + 1).filter('.divider').length;
  502. menuHeight = liHeight * this.options.size + divLength * divHeight + menuPadding;
  503. if (that.options.dropupAuto) {
  504. //noinspection JSUnusedAssignment
  505. this.$newElement.toggleClass('dropup', (selectOffsetTop > selectOffsetBot) && (menuHeight < menu.height()));
  506. }
  507. menu.css({'max-height': menuHeight + headerHeight + searchHeight + actionsHeight + 'px', 'overflow': 'hidden'});
  508. menuInner.css({'max-height': menuHeight - menuPadding + 'px', 'overflow-y': 'auto'});
  509. }
  510. },
  511. setWidth: function () {
  512. if (this.options.width == 'auto') {
  513. this.$menu.css('min-width', '0');
  514. // Get correct width if element hidden
  515. var selectClone = this.$newElement.clone().appendTo('body');
  516. var ulWidth = selectClone.find('> .dropdown-menu').css('width');
  517. var btnWidth = selectClone.css('width', 'auto').find('> button').css('width');
  518. selectClone.remove();
  519. // Set width to whatever's larger, button title or longest option
  520. this.$newElement.css('width', Math.max(parseInt(ulWidth), parseInt(btnWidth)) + 'px');
  521. } else if (this.options.width == 'fit') {
  522. // Remove inline min-width so width can be changed from 'auto'
  523. this.$menu.css('min-width', '');
  524. this.$newElement.css('width', '').addClass('fit-width');
  525. } else if (this.options.width) {
  526. // Remove inline min-width so width can be changed from 'auto'
  527. this.$menu.css('min-width', '');
  528. this.$newElement.css('width', this.options.width);
  529. } else {
  530. // Remove inline min-width/width so width can be changed
  531. this.$menu.css('min-width', '');
  532. this.$newElement.css('width', '');
  533. }
  534. // Remove fit-width class if width is changed programmatically
  535. if (this.$newElement.hasClass('fit-width') && this.options.width !== 'fit') {
  536. this.$newElement.removeClass('fit-width');
  537. }
  538. },
  539. selectPosition: function () {
  540. var that = this,
  541. drop = '<div />',
  542. $drop = $(drop),
  543. pos,
  544. actualHeight,
  545. getPlacement = function ($element) {
  546. $drop.addClass($element.attr('class').replace(/form-control/gi, '')).toggleClass('dropup', $element.hasClass('dropup'));
  547. pos = $element.offset();
  548. actualHeight = $element.hasClass('dropup') ? 0 : $element[0].offsetHeight;
  549. $drop.css({
  550. 'top': pos.top + actualHeight,
  551. 'left': pos.left,
  552. 'width': $element[0].offsetWidth,
  553. 'position': 'absolute'
  554. });
  555. };
  556. this.$newElement.on('click', function () {
  557. if (that.isDisabled()) {
  558. return;
  559. }
  560. getPlacement($(this));
  561. $drop.appendTo(that.options.container);
  562. $drop.toggleClass('open', !$(this).hasClass('open'));
  563. $drop.append(that.$menu);
  564. });
  565. $(window).resize(function () {
  566. getPlacement(that.$newElement);
  567. });
  568. $(window).on('scroll', function () {
  569. getPlacement(that.$newElement);
  570. });
  571. $('html').on('click', function (e) {
  572. if ($(e.target).closest(that.$newElement).length < 1) {
  573. $drop.removeClass('open');
  574. }
  575. });
  576. },
  577. setSelected: function (index, selected) {
  578. this.findLis();
  579. this.$lis.filter('[data-original-index="' + index + '"]').toggleClass('selected', selected);
  580. },
  581. setDisabled: function (index, disabled) {
  582. this.findLis();
  583. if (disabled) {
  584. this.$lis.filter('[data-original-index="' + index + '"]').addClass('disabled').find('a').attr('href', '#').attr('tabindex', -1);
  585. } else {
  586. this.$lis.filter('[data-original-index="' + index + '"]').removeClass('disabled').find('a').removeAttr('href').attr('tabindex', 0);
  587. }
  588. },
  589. isDisabled: function () {
  590. if (this.$newElement.hasClass('readonly')) return true;
  591. return this.$element.is(':disabled');
  592. },
  593. checkDisabled: function () {
  594. var that = this;
  595. if (this.isDisabled()) {
  596. this.$button.addClass('disabled').attr('tabindex', -1);
  597. } else {
  598. if (this.$button.hasClass('disabled')) {
  599. this.$button.removeClass('disabled');
  600. }
  601. if (this.$button.attr('tabindex') == -1) {
  602. if (!this.$element.data('tabindex')) this.$button.removeAttr('tabindex');
  603. }
  604. }
  605. this.$button.click(function () {
  606. return !that.isDisabled();
  607. });
  608. },
  609. tabIndex: function () {
  610. if (this.$element.is('[tabindex]')) {
  611. this.$element.data('tabindex', this.$element.attr('tabindex'));
  612. this.$button.attr('tabindex', this.$element.data('tabindex'));
  613. }
  614. },
  615. clickListener: function () {
  616. var that = this;
  617. this.$newElement.on('touchstart.dropdown', '.dropdown-menu', function (e) {
  618. e.stopPropagation();
  619. });
  620. this.$newElement.on('click', function () {
  621. that.setSize();
  622. if (!that.options.liveSearch && !that.multiple) {
  623. setTimeout(function () {
  624. that.$menu.find('.selected a').focus();
  625. }, 10);
  626. }
  627. });
  628. this.$menu.on('click', 'li a', function (e) {
  629. var $this = $(this),
  630. clickedIndex = $this.parent().data('originalIndex'),
  631. prevValue = that.$element.val(),
  632. prevIndex = that.$element.prop('selectedIndex');
  633. // Don't close on multi choice menu
  634. if (that.multiple) {
  635. e.stopPropagation();
  636. }
  637. e.preventDefault();
  638. //Don't run if we have been disabled
  639. if (!that.isDisabled() && !$this.parent().hasClass('disabled')) {
  640. var $options = that.$element.find('option'),
  641. $option = $options.eq(clickedIndex),
  642. state = $option.prop('selected'),
  643. $optgroup = $option.parent('optgroup'),
  644. maxOptions = that.options.maxOptions,
  645. maxOptionsGrp = $optgroup.data('maxOptions') || false;
  646. if (!that.multiple) { // Deselect all others if not multi select box
  647. $options.prop('selected', false);
  648. $option.prop('selected', true);
  649. that.$menu.find('.selected').removeClass('selected');
  650. that.setSelected(clickedIndex, true);
  651. } else { // Toggle the one we have chosen if we are multi select.
  652. $option.prop('selected', !state);
  653. that.setSelected(clickedIndex, !state);
  654. $this.blur();
  655. if ((maxOptions !== false) || (maxOptionsGrp !== false)) {
  656. var maxReached = maxOptions < $options.filter(':selected').length,
  657. maxReachedGrp = maxOptionsGrp < $optgroup.find('option:selected').length;
  658. if ((maxOptions && maxReached) || (maxOptionsGrp && maxReachedGrp)) {
  659. if (maxOptions && maxOptions == 1) {
  660. $options.prop('selected', false);
  661. $option.prop('selected', true);
  662. that.$menu.find('.selected').removeClass('selected');
  663. that.setSelected(clickedIndex, true);
  664. } else if (maxOptionsGrp && maxOptionsGrp == 1) {
  665. $optgroup.find('option:selected').prop('selected', false);
  666. $option.prop('selected', true);
  667. var optgroupID = $this.data('optgroup');
  668. that.$menu.find('.selected').has('a[data-optgroup="' + optgroupID + '"]').removeClass('selected');
  669. that.setSelected(clickedIndex, true);
  670. } else {
  671. var maxOptionsArr = (typeof that.options.maxOptionsText === 'function') ?
  672. that.options.maxOptionsText(maxOptions, maxOptionsGrp) : that.options.maxOptionsText,
  673. maxTxt = maxOptionsArr[0].replace('{n}', maxOptions),
  674. maxTxtGrp = maxOptionsArr[1].replace('{n}', maxOptionsGrp),
  675. $notify = $('<div class="notify"></div>');
  676. // If {var} is set in array, replace it
  677. /** @deprecated */
  678. if (maxOptionsArr[2]) {
  679. maxTxt = maxTxt.replace('{var}', maxOptionsArr[2][maxOptions > 1 ? 0 : 1]);
  680. maxTxtGrp = maxTxtGrp.replace('{var}', maxOptionsArr[2][maxOptionsGrp > 1 ? 0 : 1]);
  681. }
  682. $option.prop('selected', false);
  683. that.$menu.append($notify);
  684. if (maxOptions && maxReached) {
  685. $notify.append($('<div>' + maxTxt + '</div>'));
  686. that.$element.trigger('maxReached.bs.select');
  687. }
  688. if (maxOptionsGrp && maxReachedGrp) {
  689. $notify.append($('<div>' + maxTxtGrp + '</div>'));
  690. that.$element.trigger('maxReachedGrp.bs.select');
  691. }
  692. setTimeout(function () {
  693. that.setSelected(clickedIndex, false);
  694. }, 10);
  695. $notify.delay(750).fadeOut(300, function () {
  696. $(this).remove();
  697. });
  698. }
  699. }
  700. }
  701. }
  702. if (!that.multiple) {
  703. that.$button.focus();
  704. } else if (that.options.liveSearch) {
  705. that.$searchbox.focus();
  706. }
  707. // Trigger select 'change'
  708. if ((prevValue != that.$element.val() && that.multiple) || (prevIndex != that.$element.prop('selectedIndex') && !that.multiple)) {
  709. that.$element.change();
  710. }
  711. }
  712. });
  713. this.$menu.on('click', 'li.disabled a, .popover-title, .popover-title :not(.close)', function (e) {
  714. if (e.target == this) {
  715. e.preventDefault();
  716. e.stopPropagation();
  717. if (!that.options.liveSearch) {
  718. that.$button.focus();
  719. } else {
  720. that.$searchbox.focus();
  721. }
  722. }
  723. });
  724. this.$menu.on('click', 'li.divider, li.dropdown-header', function (e) {
  725. e.preventDefault();
  726. e.stopPropagation();
  727. if (!that.options.liveSearch) {
  728. that.$button.focus();
  729. } else {
  730. that.$searchbox.focus();
  731. }
  732. });
  733. this.$menu.on('click', '.popover-title .close', function () {
  734. that.$button.focus();
  735. });
  736. this.$searchbox.on('click', function (e) {
  737. e.stopPropagation();
  738. });
  739. this.$menu.on('click', '.actions-btn', function (e) {
  740. if (that.options.liveSearch) {
  741. that.$searchbox.focus();
  742. } else {
  743. that.$button.focus();
  744. }
  745. e.preventDefault();
  746. e.stopPropagation();
  747. if ($(this).is('.bs-select-all')) {
  748. that.selectAll();
  749. } else {
  750. that.deselectAll();
  751. }
  752. that.$element.change();
  753. });
  754. this.$element.change(function () {
  755. that.render(false);
  756. });
  757. },
  758. liveSearchListener: function () {
  759. var that = this,
  760. no_results = $('<li class="no-results"></li>');
  761. this.$newElement.on('click.dropdown.data-api touchstart.dropdown.data-api', function () {
  762. that.$menu.find('.active').removeClass('active');
  763. if (!!that.$searchbox.val()) {
  764. that.$searchbox.val('');
  765. that.$lis.not('.is-hidden').removeClass('hide');
  766. if (!!no_results.parent().length) no_results.remove();
  767. }
  768. if (!that.multiple) that.$menu.find('.selected').addClass('active');
  769. setTimeout(function () {
  770. that.$searchbox.focus();
  771. }, 10);
  772. });
  773. this.$searchbox.on('click.dropdown.data-api focus.dropdown.data-api touchend.dropdown.data-api', function (e) {
  774. e.stopPropagation();
  775. });
  776. this.$searchbox.on('input propertychange', function () {
  777. if (that.$searchbox.val()) {
  778. if (that.options.searchAccentInsensitive) {
  779. that.$lis.not('.is-hidden').removeClass('hide').find('a').not(':aicontains(' + normalizeToBase(that.$searchbox.val()) + ')').parent().addClass('hide');
  780. } else {
  781. that.$lis.not('.is-hidden').removeClass('hide').find('a').not(':icontains(' + that.$searchbox.val() + ')').parent().addClass('hide');
  782. }
  783. if (!that.$menu.find('li').filter(':visible:not(.no-results)').length) {
  784. if (!!no_results.parent().length) no_results.remove();
  785. no_results.html(that.options.noneResultsText + ' "' + htmlEscape(that.$searchbox.val()) + '"').show();
  786. that.$menu.find('li').last().after(no_results);
  787. } else if (!!no_results.parent().length) {
  788. no_results.remove();
  789. }
  790. } else {
  791. that.$lis.not('.is-hidden').removeClass('hide');
  792. if (!!no_results.parent().length) no_results.remove();
  793. }
  794. that.$menu.find('li.active').removeClass('active');
  795. that.$menu.find('li').filter(':visible:not(.divider)').eq(0).addClass('active').find('a').focus();
  796. $(this).focus();
  797. });
  798. },
  799. val: function (value) {
  800. if (typeof value !== 'undefined') {
  801. this.$element.val(value);
  802. this.render();
  803. return this.$element;
  804. } else {
  805. return this.$element.val();
  806. }
  807. },
  808. selectAll: function () {
  809. this.findLis();
  810. this.$lis.not('.divider').not('.disabled').not('.selected').filter(':visible').find('a').click();
  811. },
  812. deselectAll: function () {
  813. this.findLis();
  814. this.$lis.not('.divider').not('.disabled').filter('.selected').filter(':visible').find('a').click();
  815. },
  816. keydown: function (e) {
  817. var $this = $(this),
  818. $parent = ($this.is('input')) ? $this.parent().parent() : $this.parent(),
  819. $items,
  820. that = $parent.data('this'),
  821. index,
  822. next,
  823. first,
  824. last,
  825. prev,
  826. nextPrev,
  827. prevIndex,
  828. isActive,
  829. keyCodeMap = {
  830. 32: ' ',
  831. 48: '0',
  832. 49: '1',
  833. 50: '2',
  834. 51: '3',
  835. 52: '4',
  836. 53: '5',
  837. 54: '6',
  838. 55: '7',
  839. 56: '8',
  840. 57: '9',
  841. 59: ';',
  842. 65: 'a',
  843. 66: 'b',
  844. 67: 'c',
  845. 68: 'd',
  846. 69: 'e',
  847. 70: 'f',
  848. 71: 'g',
  849. 72: 'h',
  850. 73: 'i',
  851. 74: 'j',
  852. 75: 'k',
  853. 76: 'l',
  854. 77: 'm',
  855. 78: 'n',
  856. 79: 'o',
  857. 80: 'p',
  858. 81: 'q',
  859. 82: 'r',
  860. 83: 's',
  861. 84: 't',
  862. 85: 'u',
  863. 86: 'v',
  864. 87: 'w',
  865. 88: 'x',
  866. 89: 'y',
  867. 90: 'z',
  868. 96: '0',
  869. 97: '1',
  870. 98: '2',
  871. 99: '3',
  872. 100: '4',
  873. 101: '5',
  874. 102: '6',
  875. 103: '7',
  876. 104: '8',
  877. 105: '9'
  878. };
  879. if (that.options.liveSearch) $parent = $this.parent().parent();
  880. if (that.options.container) $parent = that.$menu;
  881. $items = $('[role=menu] li a', $parent);
  882. isActive = that.$menu.parent().hasClass('open');
  883. if (!isActive && /([0-9]|[A-z])/.test(String.fromCharCode(e.keyCode))) {
  884. if (!that.options.container) {
  885. that.setSize();
  886. that.$menu.parent().addClass('open');
  887. isActive = true;
  888. } else {
  889. that.$newElement.trigger('click');
  890. }
  891. that.$searchbox.focus();
  892. }
  893. if (that.options.liveSearch) {
  894. if (/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && that.$menu.find('.active').length === 0) {
  895. e.preventDefault();
  896. that.$menu.parent().removeClass('open');
  897. that.$button.focus();
  898. }
  899. $items = $('[role=menu] li:not(.divider):not(.dropdown-header):visible', $parent);
  900. if (!$this.val() && !/(38|40)/.test(e.keyCode.toString(10))) {
  901. if ($items.filter('.active').length === 0) {
  902. if (that.options.searchAccentInsensitive) {
  903. $items = that.$newElement.find('li').filter(':aicontains(' + normalizeToBase(keyCodeMap[e.keyCode]) + ')');
  904. } else {
  905. $items = that.$newElement.find('li').filter(':icontains(' + keyCodeMap[e.keyCode] + ')');
  906. }
  907. }
  908. }
  909. }
  910. if (!$items.length) return;
  911. if (/(38|40)/.test(e.keyCode.toString(10))) {
  912. index = $items.index($items.filter(':focus'));
  913. first = $items.parent(':not(.disabled):visible').first().index();
  914. last = $items.parent(':not(.disabled):visible').last().index();
  915. next = $items.eq(index).parent().nextAll(':not(.disabled):visible').eq(0).index();
  916. prev = $items.eq(index).parent().prevAll(':not(.disabled):visible').eq(0).index();
  917. nextPrev = $items.eq(next).parent().prevAll(':not(.disabled):visible').eq(0).index();
  918. if (that.options.liveSearch) {
  919. $items.each(function (i) {
  920. if ($(this).is(':not(.disabled)')) {
  921. $(this).data('index', i);
  922. }
  923. });
  924. index = $items.index($items.filter('.active'));
  925. first = $items.filter(':not(.disabled):visible').first().data('index');
  926. last = $items.filter(':not(.disabled):visible').last().data('index');
  927. next = $items.eq(index).nextAll(':not(.disabled):visible').eq(0).data('index');
  928. prev = $items.eq(index).prevAll(':not(.disabled):visible').eq(0).data('index');
  929. nextPrev = $items.eq(next).prevAll(':not(.disabled):visible').eq(0).data('index');
  930. }
  931. prevIndex = $this.data('prevIndex');
  932. if (e.keyCode == 38) {
  933. if (that.options.liveSearch) index -= 1;
  934. if (index != nextPrev && index > prev) index = prev;
  935. if (index < first) index = first;
  936. if (index == prevIndex) index = last;
  937. }
  938. if (e.keyCode == 40) {
  939. if (that.options.liveSearch) index += 1;
  940. if (index == -1) index = 0;
  941. if (index != nextPrev && index < next) index = next;
  942. if (index > last) index = last;
  943. if (index == prevIndex) index = first;
  944. }
  945. $this.data('prevIndex', index);
  946. if (!that.options.liveSearch) {
  947. $items.eq(index).focus();
  948. } else {
  949. e.preventDefault();
  950. if (!$this.is('.dropdown-toggle')) {
  951. $items.removeClass('active');
  952. $items.eq(index).addClass('active').find('a').focus();
  953. $this.focus();
  954. }
  955. }
  956. } else if (!$this.is('input')) {
  957. var keyIndex = [],
  958. count,
  959. prevKey;
  960. $items.each(function () {
  961. if ($(this).parent().is(':not(.disabled)')) {
  962. if ($.trim($(this).text().toLowerCase()).substring(0, 1) == keyCodeMap[e.keyCode]) {
  963. keyIndex.push($(this).parent().index());
  964. }
  965. }
  966. });
  967. count = $(document).data('keycount');
  968. count++;
  969. $(document).data('keycount', count);
  970. prevKey = $.trim($(':focus').text().toLowerCase()).substring(0, 1);
  971. if (prevKey != keyCodeMap[e.keyCode]) {
  972. count = 1;
  973. $(document).data('keycount', count);
  974. } else if (count >= keyIndex.length) {
  975. $(document).data('keycount', 0);
  976. if (count > keyIndex.length) count = 1;
  977. }
  978. $items.eq(keyIndex[count - 1]).focus();
  979. }
  980. // Select focused option if "Enter", "Spacebar" or "Tab" (when selectOnTab is true) are pressed inside the menu.
  981. if ((/(13|32)/.test(e.keyCode.toString(10)) || (/(^9$)/.test(e.keyCode.toString(10)) && that.options.selectOnTab)) && isActive) {
  982. if (!/(32)/.test(e.keyCode.toString(10))) e.preventDefault();
  983. if (!that.options.liveSearch) {
  984. $(':focus').click();
  985. } else if (!/(32)/.test(e.keyCode.toString(10))) {
  986. that.$menu.find('.active a').click();
  987. $this.focus();
  988. }
  989. $(document).data('keycount', 0);
  990. }
  991. if ((/(^9$|27)/.test(e.keyCode.toString(10)) && isActive && (that.multiple || that.options.liveSearch)) || (/(27)/.test(e.keyCode.toString(10)) && !isActive)) {
  992. that.$menu.parent().removeClass('open');
  993. that.$button.focus();
  994. }
  995. },
  996. mobile: function () {
  997. this.$element.addClass('mobile-device').appendTo(this.$newElement);
  998. if (this.options.container) this.$menu.hide();
  999. },
  1000. refresh: function () {
  1001. this.$lis = null;
  1002. this.reloadLi();
  1003. this.render();
  1004. this.setWidth();
  1005. this.setStyle();
  1006. this.checkDisabled();
  1007. this.liHeight();
  1008. },
  1009. update: function () {
  1010. this.reloadLi();
  1011. this.setWidth();
  1012. this.setStyle();
  1013. this.checkDisabled();
  1014. this.liHeight();
  1015. },
  1016. hide: function () {
  1017. this.$newElement.hide();
  1018. },
  1019. show: function () {
  1020. this.$newElement.show();
  1021. },
  1022. remove: function () {
  1023. this.$newElement.remove();
  1024. this.$element.remove();
  1025. },
  1026. /*Defined by K'naan*/
  1027. destroyMenu: function() {
  1028. if (this.options.container == 'body') {
  1029. if (!this.$newElement.find(this.$menu).length) {
  1030. this.$menu.appendTo(this.$newElement)
  1031. var $emptyselect = $('body').find('> .bootstrap-select:empty').remove()
  1032. }
  1033. }
  1034. }
  1035. };
  1036. // SELECTPICKER PLUGIN DEFINITION
  1037. // ==============================
  1038. function Plugin(option, event) {
  1039. // get the args of the outer function..
  1040. var args = arguments;
  1041. // The arguments of the function are explicitly re-defined from the argument list, because the shift causes them
  1042. // to get lost
  1043. //noinspection JSDuplicatedDeclaration
  1044. var _option = option,
  1045. option = args[0],
  1046. event = args[1];
  1047. [].shift.apply(args);
  1048. // This fixes a bug in the js implementation on android 2.3 #715
  1049. if (typeof option == 'undefined') {
  1050. option = _option;
  1051. }
  1052. var value;
  1053. var chain = this.each(function () {
  1054. var $this = $(this);
  1055. if ($this.is('select')) {
  1056. var data = $this.data('selectpicker'),
  1057. options = typeof option == 'object' && option;
  1058. if (!data) {
  1059. var config = $.extend({}, Selectpicker.DEFAULTS, $.fn.selectpicker.defaults || {}, $this.data(), options);
  1060. $this.data('selectpicker', (data = new Selectpicker(this, config, event)));
  1061. } else if (options) {
  1062. for (var i in options) {
  1063. if (options.hasOwnProperty(i)) {
  1064. data.options[i] = options[i];
  1065. }
  1066. }
  1067. }
  1068. if (typeof option == 'string') {
  1069. if (data[option] instanceof Function) {
  1070. value = data[option].apply(data, args);
  1071. } else {
  1072. value = data.options[option];
  1073. }
  1074. }
  1075. }
  1076. });
  1077. if (typeof value !== 'undefined') {
  1078. //noinspection JSUnusedAssignment
  1079. return value;
  1080. } else {
  1081. return chain;
  1082. }
  1083. }
  1084. var old = $.fn.selectpicker;
  1085. $.fn.selectpicker = Plugin;
  1086. $.fn.selectpicker.Constructor = Selectpicker;
  1087. // SELECTPICKER NO CONFLICT
  1088. // ========================
  1089. $.fn.selectpicker.noConflict = function () {
  1090. $.fn.selectpicker = old;
  1091. return this;
  1092. };
  1093. $(document)
  1094. .data('keycount', 0)
  1095. .on('keydown', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bs-searchbox input', Selectpicker.prototype.keydown)
  1096. .on('focusin.modal', '.bootstrap-select [data-toggle=dropdown], .bootstrap-select [role=menu], .bs-searchbox input', function (e) {
  1097. e.stopPropagation();
  1098. });
  1099. // SELECTPICKER DATA-API
  1100. // =====================
  1101. $(window).on('load.bs.select.data-api', function () {
  1102. $('.selectpicker').each(function () {
  1103. var $selectpicker = $(this);
  1104. Plugin.call($selectpicker, $selectpicker.data());
  1105. })
  1106. });
  1107. })(jQuery);