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