1!(function (e, t) { 2 "object" == typeof exports && "object" == typeof module ? (module.exports = t()) : "function" == typeof define && define.amd ? define([], t) : "object" == typeof exports ? (exports.NiceSelect = t()) : (e.NiceSelect = t()); 3})(self, () => 4 (() => { 5 "use strict"; 6 var e = { 7 d: (t, i) => { 8 for (var s in i) e.o(i, s) && !e.o(t, s) && Object.defineProperty(t, s, { enumerable: !0, get: i[s] }); 9 }, 10 o: (e, t) => Object.prototype.hasOwnProperty.call(e, t), 11 r: (e) => { 12 "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }), Object.defineProperty(e, "__esModule", { value: !0 }); 13 }, 14 }, 15 t = {}; 16 function i(e) { 17 var t = document.createEvent("MouseEvents"); 18 t.initEvent("click", !0, !1), e.dispatchEvent(t); 19 } 20 function s(e) { 21 var t = document.createEvent("HTMLEvents"); 22 t.initEvent("change", !0, !1), e.dispatchEvent(t); 23 } 24 function o(e) { 25 var t = document.createEvent("FocusEvent"); 26 t.initEvent("focusin", !0, !1), e.dispatchEvent(t); 27 } 28 function n(e) { 29 var t = document.createEvent("FocusEvent"); 30 t.initEvent("focusout", !0, !1), e.dispatchEvent(t); 31 } 32 function d(e) { 33 var t = document.createEvent("UIEvent"); 34 t.initEvent("modalclose", !0, !1), e.dispatchEvent(t); 35 } 36 function l(e, t) { 37 "invalid" == t ? (c(this.dropdown, "invalid"), h(this.dropdown, "valid")) : (c(this.dropdown, "valid"), h(this.dropdown, "invalid")); 38 } 39 function r(e, t) { 40 return null != e[t] ? e[t] : e.getAttribute(t); 41 } 42 function a(e, t) { 43 return !!e && e.classList.contains(t); 44 } 45 function c(e, t) { 46 if (e) return e.classList.add(t); 47 } 48 function h(e, t) { 49 if (e) return e.classList.remove(t); 50 } 51 e.r(t), e.d(t, { bind: () => f, default: () => u }); 52 var p = { data: null, searchable: !1, showSelectedItems: !1 }; 53 function u(e, t) { 54 (this.el = e), 55 (this.config = Object.assign({}, p, t || {})), 56 (this.data = this.config.data), 57 (this.selectedOptions = []), 58 (this.placeholder = r(this.el, "placeholder") || this.config.placeholder || "Select an option"), 59 (this.searchtext = r(this.el, "searchtext") || this.config.searchtext || "Search"), 60 (this.selectedtext = r(this.el, "selectedtext") || this.config.selectedtext || "selected"), 61 (this.dropdown = null),
62 (this.multiple = r(this.el, "multiple")), 63 (this.disabled = r(this.el, "disabled")), 64 this.create(); 65 } 66 function f(e, t) { 67 return new u(e, t); 68 } 69 return ( 70 // custom method add class 71 (u.prototype.addInitClass = function() { 72 // Add class 'init-nice-select' to select 73 this.el.classList.add("init-nice-select"); 74 }), 75 (u.prototype.create = function () { 76 (this.el.style.opacity = "0"), 77 (this.el.style.width = "0"), 78 (this.el.style.display = "none"), 79 (this.el.style.padding = "0"), 80 (this.el.style.height = "0"), 81 this.data ? this.processData(this.data) : this.extractData(), 82 this.renderDropdown(), 83 this.bindEvent(); 84 // init method add class to select 85 this.addInitClass(); 86 }), 87 (u.prototype.processData = function (e) { 88 var t = []; 89 e.forEach((e) => { 90 t.push({ data: e, attributes: { selected: !!e.selected, disabled: !!e.disabled, optgroup: "optgroup" == e.value } }); 91 }), 92 (this.options = t); 93 }), 94 (u.prototype.extractData = function () { 95 var e = this.el.querySelectorAll("option,optgroup"), 96 t = [], 97 i = [], 98 s = []; 99 e.forEach((e) => { 100 if ("OPTGROUP" == e.tagName) var s = { text: e.label, value: "optgroup" }; 101 else s = { text: e.innerText, value: e.value, selected: null != e.getAttribute("selected") || this.el.value == e.value, disabled: null != e.getAttribute("disabled") }; 102 var o = { selected: e.selected, disabled: e.disabled, optgroup: "OPTGROUP" == e.tagName }; 103 t.push(s), i.push({ data: s, attributes: o }); 104 }), 105 (this.data = t), 106 (this.options = i), 107 this.options.forEach((e) => { 108 e.attributes.selected && s.push(e); 109 }), 110 (this.selectedOptions = s); 111 }), 112 (u.prototype.renderDropdown = function () { 113 var e = ["nice-select", r(this.el, "class") || "", this.disabled ? "disabled" : "", this.multiple ? "has-multiple" : ""]; 114 let t = '<div class="nice-select-search-box">'; 115 (t += `<input type="text" class="nice-select-search" placeholder="${this.searchtext}..." title="search"/>`), (t += "</div>"); 116 var i = `<div class="${e.join(" ")}" tabindex="${this.disabled ? null : 0}">`; 117 (i += `<span class="${this.multiple ? "multiple-options" : "current"}"></span>`), 118 (i += '<div class="nice-select-dropdown">'), 119 (i += `${this.config.searchable ? t : ""}`), 120 (i += '<ul class="list"></ul>'), 121 (i += "</div>"), 122 (i += "</div>"), 123 this.el.insertAdjacentHTML("afterend", i), 124 (this.dropdown = this.el.nextElementSibling), 125 this._renderSelectedItems(), 126 this._renderItems(); 127 }), 128 (u.prototype._renderSelectedItems = function () { 129 if (this.multiple) { 130 var e = ""; 131 this.config.showSelectedItems || this.config.showSelectedItems || "auto" == window.getComputedStyle(this.dropdown).width || this.selectedOptions.length < 2 132 ? (this.selectedOptions.forEach(function (t) { 133 e += `<span class="current">${t.data.text}</span>`;
134 }), 135 (e = "" == e ? this.placeholder : e)) 136 : (e = this.selectedOptions.length + " " + this.selectedtext), 137 (this.dropdown.querySelector(".multiple-options").innerHTML = e); 138 } else { 139 var t = this.selectedOptions.length > 0 ? this.selectedOptions[0].data.text : this.placeholder; 140 this.dropdown.querySelector(".current").innerHTML = t; 141 } 142 }), 143 (u.prototype._renderItems = function () { 144 var e = this.dropdown.querySelector("ul"); 145 this.options.forEach((t) => { 146 e.appendChild(this._renderItem(t)); 147 }); 148 }), 149 (u.prototype._renderItem = function (e) { 150 var t = document.createElement("li"); 151 if (((t.innerHTML = e.data.text), e.attributes.optgroup)) c(t, "optgroup"); 152 else { 153 t.setAttribute("data-value", e.data.value); 154 var i = ["option", e.attributes.selected ? "selected" : null, e.attributes.disabled ? "disabled" : null]; 155 t.addEventListener("click", this._onItemClicked.bind(this, e)), t.classList.add(...i); 156 } 157 return (e.element = t), t; 158 }), 159 (u.prototype.update = function () { 160 if ((this.extractData(), this.dropdown)) { 161 var e = a(this.dropdown, "open"); 162 this.dropdown.parentNode.removeChild(this.dropdown), this.create(), e && i(this.dropdown); 163 } 164 r(this.el, "disabled") ? this.disable() : this.enable(); 165 }), 166 (u.prototype.disable = function () { 167 this.disabled || ((this.disabled = !0), c(this.dropdown, "disabled")); 168 }), 169 (u.prototype.enable = function () { 170 this.disabled && ((this.disabled = !1), h(this.dropdown, "disabled")); 171 }), 172 (u.prototype.clear = function () { 173 this.resetSelectValue(), (this.selectedOptions = []), this._renderSelectedItems(), this.update(), s(this.el); 174 }), 175 (u.prototype.destroy = function () { 176 this.dropdown && (this.dropdown.parentNode.removeChild(this.dropdown), (this.el.style.display = "")); 177 }), 178 (u.prototype.bindEvent = function () { 179 this.dropdown.addEventListener("click", this._onClicked.bind(this)), 180 this.dropdown.addEventListener("keydown", this._onKeyPressed.bind(this)), 181 this.dropdown.addEventListener("focusin", o.bind(this, this.el)), 182 this.dropdown.addEventListener("focusout", n.bind(this, this.el)), 183 this.el.addEventListener("invalid", l.bind(this, this.el, "invalid")), 184 window.addEventListener("click", this._onClickedOutside.bind(this)), 185 this.config.searchable && this._bindSearchEvent(); 186 }), 187 (u.prototype._bindSearchEvent = function () { 188 var e = this.dropdown.querySelector(".nice-select-search"); 189 e && 190 e.addEventListener("click", function (e) { 191 return e.stopPropagation(), !1; 192 }), 193 e.addEventListener("input", this._onSearchChanged.bind(this)); 194 }), 195 // custom method check position open select down or up 196 (u.prototype._setDropdownPosition = function () { 197 const dropdownHeight = this.dropdown.querySelector('.nice-select-dropdown').offsetHeight; 198 const rect = this.dropdown.getBoundingClientRect(); 199 const windowHeight = window.innerHeight; 200 201 const spaceBelow = windowHeight - rect.bottom; 202 const spaceAbove = rect.top; 203 204 if (spaceBelow < dropdownHeight && spaceAbove > dropdownHeight) { 205 c(this.dropdown, "open-up"); 206 h(this.dropdown, "open-down"); 207 } else { 208 c(this.dropdown, "open-down"); 209 h(this.dropdown, "open-up"); 210 } 211 }), 212 (u.prototype._onClicked = function (e) { 213 e.preventDefault(); 214 215 if (a(this.dropdown, "open")) { 216 if (!this.multiple) { 217 h(this.dropdown, "open"); 218 d(this.el); 219 } 220 } else { 221 this._setDropdownPosition(); 222 c(this.dropdown, "open"); 223 224 var t = this.el; 225 var i = document.createEvent("UIEvent"); 226 i.initEvent("modalopen", !0, !1); 227 t.dispatchEvent(i); 228 } 229 230 if (a(this.dropdown, "open")) { 231 var searchInput = this.dropdown.querySelector(".nice-select-search"); 232 if (searchInput) { 233 searchInput.value = ""; 234 searchInput.focus(); 235 } 236 237 var focusedOption = this.dropdown.querySelector(".focus"); 238 h(focusedOption, "focus"); 239 c((focusedOption = this.dropdown.querySelector(".selected")), "focus"); 240 241 this.dropdown.querySelectorAll("ul li").forEach(function (item) { 242 item.style.display = ""; 243 }); 244 } else { 245 this.dropdown.focus(); 246 } 247 }), 248 (u.prototype._onItemClicked = function (e, t) { 249 var i = t.target; 250 a(i, "disabled") || 251 (this.multiple 252 ? a(i, "selected") 253 ? (h(i, "selected"), this.selectedOptions.splice(this.selectedOptions.indexOf(e), 1), this.el.querySelector(`option[value="${i.dataset.value}"]`).removeAttribute("selected")) 254 : (c(i, "selected"), this.selectedOptions.push(e)) 255 : (this.selectedOptions.forEach(function (e) { 256 h(e.element, "selected"); 257 }), 258 c(i, "selected"), 259 (this.selectedOptions = [e])), 260 this._renderSelectedItems(), 261 this.updateSelectValue()); 262 }), 263 (u.prototype.updateSelectValue = function () { 264 if (this.multiple) { 265 var e = this.el; 266 this.selectedOptions.forEach(function (t) { 267 var i = e.querySelector(`option[value="${t.data.value}"]`); 268 i && i.setAttribute("selected", !0); 269 }); 270 } else this.selectedOptions.length > 0 && (this.el.value = this.selectedOptions[0].data.value); 271 s(this.el); 272 }), 273 (u.prototype.resetSelectValue = function () { 274 if (this.multiple) { 275 var e = this.el; 276 this.selectedOptions.forEach(function (t) { 277 var i = e.querySelector(`option[value="${t.data.value}"]`); 278 i && i.removeAttribute("selected"); 279 }); 280 } else this.selectedOptions.length > 0 && (this.el.selectedIndex = -1); 281 s(this.el); 282 }), 283 (u.prototype._onClickedOutside = function (e) { 284 this.dropdown.contains(e.target) || (h(this.dropdown, "open"), d(this.el)); 285 }), 286 (u.prototype._onKeyPressed = function (e) { 287 var t = this.dropdown.querySelector(".focus"), 288 s = a(this.dropdown, "open"); 289 if (13 == e.keyCode) i(s ? t : this.dropdown); 290 else if (40 == e.keyCode) { 291 if (s) { 292 var o = this._findNext(t); 293 o && (h(this.dropdown.querySelector(".focus"), "focus"), c(o, "focus")); 294 } else i(this.dropdown); 295 e.preventDefault(); 296 } else if (38 == e.keyCode) { 297 if (s) { 298 var n = this._findPrev(t); 299 n && (h(this.dropdown.querySelector(".focus"), "focus"), c(n, "focus")); 300 } else i(this.dropdown); 301 e.preventDefault(); 302 } else if (27 == e.keyCode && s) i(this.dropdown); 303 else if (32 === e.keyCode && s) return !1; 304 return !1; 305 }), 306 (u.prototype._findNext = function (e) { 307 for (e = e ? e.nextElementSibling : this.dropdown.querySelector(".list .option"); e; ) { 308 if (!a(e, "disabled") && "none" != e.style.display) return e; 309 e = e.nextElementSibling; 310 } 311 return null; 312 }), 313 (u.prototype._findPrev = function (e) { 314 for (e = e ? e.previousElementSibling : this.dropdown.querySelector(".list .option:last-child"); e; ) { 315 if (!a(e, "disabled") && "none" != e.style.display) return e; 316 e = e.previousElementSibling; 317 } 318 return null; 319 }), 320 (u.prototype._onSearchChanged = function (e) { 321 var t = a(this.dropdown, "open"), 322 i = e.target.value; 323 if ("" == (i = i.toLowerCase())) 324 this.options.forEach(function (e) { 325 e.element.style.display = ""; 326 }); 327 else if (t) { 328 var s = new RegExp(i); 329 this.options.forEach(function (e) { 330 var t = e.data.text.toLowerCase(), 331 i = s.test(t); 332 e.element.style.display = i ? "" : "none"; 333 }); 334 } 335 this.dropdown.querySelectorAll(".focus").forEach(function (e) {
336 h(e, "focus"); 337 }), 338 c(this._findNext(null), "focus"); 339 }), 340 t 341 ); 342 })() 343);
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.