From a054c841c386692a974037ddb457053f44c4907d Mon Sep 17 00:00:00 2001 From: Mobius1 Date: Wed, 21 Nov 2018 21:33:21 +0000 Subject: [PATCH] v2.4.7, fixes #87 --- bower.json | 2 +- dist/selectr.min.css | 2 +- dist/selectr.min.js | 60 ++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- src/selectr.css | 2 +- src/selectr.js | 8 +++++- 6 files changed, 69 insertions(+), 7 deletions(-) diff --git a/bower.json b/bower.json index 99cd4f6..c76bdca 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "mobius1-selectr", - "version": "2.4.6", + "version": "2.4.7", "ignore": [ ".gitattributes", "README.md" diff --git a/dist/selectr.min.css b/dist/selectr.min.css index be7cbd8..8f11be1 100644 --- a/dist/selectr.min.css +++ b/dist/selectr.min.css @@ -1,5 +1,5 @@ /*! - * Selectr 2.4.6 + * Selectr 2.4.7 * http://mobius.ovh/docs/selectr * * Released under the MIT license diff --git a/dist/selectr.min.js b/dist/selectr.min.js index 372dc9b..9c5aed0 100644 --- a/dist/selectr.min.js +++ b/dist/selectr.min.js @@ -1,7 +1,63 @@ /* - Selectr 2.4.6 + Selectr 2.4.7 http://mobius.ovh/docs/selectr Released under the MIT license */ -(function(m,n){var p="Selectr";"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n(p):m[p]=n(p)})(this,function(){"use strict";function n(K,L){return K.hasOwnProperty(L)&&(!0===K[L]||K[L].length)}function p(K,L,M){K.parentNode?!K.parentNode.parentNode&&L.appendChild(K.parentNode):L.appendChild(K),u.removeClass(K,"excluded"),M||(K.innerHTML=K.textContent)}var q={defaultSelected:!0,width:"auto",disabled:!1,searchable:!0,clearable:!1,sortSelected:!1,allowDeselect:!1,closeOnScroll:!1,nativeDropdown:!1,nativeKeyboard:!1,placeholder:"Select an option...",taggable:!1,tagPlaceholder:"Enter a tag...",messages:{noResults:"No results.",maxSelections:"A maximum of {max} items can be selected.",tagDuplicate:"That tag is already in use"}},s=function(){};s.prototype={on:function(K,L){this._events=this._events||{},this._events[K]=this._events[K]||[],this._events[K].push(L)},off:function(K,L){this._events=this._events||{},!1==K in this._events||this._events[K].splice(this._events[K].indexOf(L),1)},emit:function(K){if(this._events=this._events||{},!1!=K in this._events)for(var L=0;L"+T.label+""}),u.each(T.children,function(U,V){V.idx=N,M.appendChild(B.call(this,V,M)),N++},this)):(T.idx=N,B.call(this,T),N++)},this),this.config.data&&Array.isArray(this.config.data)){this.data=[];var P,O=!1;M=!1,N=0,u.each(this.config.data,function(S,T){n(T,"children")?(O=u.createElement("optgroup",{label:T.text}),M=u.createElement("ul",{class:"selectr-optgroup",role:"group",html:"
  • "+T.text+"
  • "}),u.each(T.children,function(U,V){P=new Option(V.text,V.value,!1,V.hasOwnProperty("selected")&&!0===V.selected),P.disabled=n(V,"disabled"),this.options.push(P),O.appendChild(P),P.idx=N,M.appendChild(B.call(this,P,V)),this.data[N]=V,N++},this),this.el.appendChild(O)):(P=new Option(T.text,T.value,!1,T.hasOwnProperty("selected")&&!0===T.selected),P.disabled=n(T,"disabled"),this.options.push(P),P.idx=N,B.call(this,P,T),this.data[N]=T,N++)},this)}this.setSelected(!0);var Q;this.navIndex=0;for(var R=0;Rthis.tree.lastElementChild.idx){this.navIndex=this.tree.lastElementChild.idx;break}else if(this.navIndexthis.optsRect.top+this.optsRect.height&&(this.tree.scrollTop+=O.top+O.height-(this.optsRect.top+this.optsRect.height)),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&G.call(this)):0===this.navIndex?this.tree.scrollTop=0:0>O.top-this.optsRect.top&&(this.tree.scrollTop+=O.top-this.optsRect.top),M&&u.removeClass(M,"active"),u.addClass(this.items[this.navIndex],"active")},E=function(K){var M,L=this,N=document.createDocumentFragment(),O=this.options[K.idx],P=this.data?this.data[K.idx]:O,Q=this.customSelected?this.config.renderSelection(P):O.textContent,R=u.createElement("li",{class:"selectr-tag",html:Q}),S=u.createElement("button",{class:"selectr-tag-remove",type:"button"});if(R.appendChild(S),R.idx=K.idx,R.tag=O.value,this.tags.push(R),this.config.sortSelected){var T=this.tags.slice();M=function(U,V){U.replace(/(\d+)|(\D+)/g,function(W,X,Y){V.push([X||Infinity,Y||""])})},T.sort(function(U,V){var Y,Z,W=[],X=[];for(!0===L.config.sortSelected?(Y=U.tag,Z=V.tag):"text"===L.config.sortSelected&&(Y=U.textContent,Z=V.textContent),M(Y,W),M(Z,X);W.length&&X.length;){var $=W.shift(),_=X.shift(),aa=$[0]-_[0]||$[1].localeCompare(_[1]);if(aa)return aa}return W.length-X.length}),u.each(T,function(U,V){N.appendChild(V)}),this.label.innerHTML=""}else N.appendChild(R);this.config.taggable?this.label.insertBefore(N,this.input.parentNode):this.label.appendChild(N)},F=function(K){var L=!1;u.each(this.tags,function(M,N){N.idx===K.idx&&(L=N)},this),L&&(this.label.removeChild(L),this.tags.splice(this.tags.indexOf(L),1))},G=function(){var K=this.tree,L=K.scrollTop,M=K.scrollHeight,N=K.offsetHeight;if(L>=M-N&&this.pageIndex"+M[0]+"")},J=function(K,L){if(L=L||{},!K)throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");if(this.el=K,"string"==typeof K&&(this.el=document.querySelector(K)),null===this.el)throw new Error("The element you passed to Selectr can not be found.");if("select"!==this.el.nodeName.toLowerCase())throw new Error("The element you passed to Selectr is not a HTMLSelectElement.");this.render(L)};return J.prototype.render=function(K){if(!this.rendered){this.config=u.extend(q,K),this.originalType=this.el.type,this.originalIndex=this.el.tabIndex,this.defaultSelected=[],this.originalOptionCount=this.el.options.length,(this.config.multiple||this.config.taggable)&&(this.el.multiple=!0),this.disabled=n(this.config,"disabled"),this.opened=!1,this.config.taggable&&(this.config.searchable=!1),this.navigating=!1,this.mobileDevice=!1,/Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent)&&(this.mobileDevice=!0),this.customOption=this.config.hasOwnProperty("renderOption")&&"function"==typeof this.config.renderOption,this.customSelected=this.config.hasOwnProperty("renderSelection")&&"function"==typeof this.config.renderSelection,s.mixin(this),C.call(this),this.bindEvents(),this.update(),this.optsRect=u.rect(this.tree),this.rendered=!0,this.el.multiple||(this.el.selectedIndex=this.selectedIndex);var L=this;setTimeout(function(){L.emit("selectr.init")},20)}},J.prototype.getSelected=function(){var K=this.el.querySelectorAll("option:checked");return K},J.prototype.getSelectedProperties=function(K){var L=this.getSelected(),M=[].slice.call(L).map(function(N){return N[K]}).filter(function(N){return null!==N&&void 0!==N});return M},J.prototype.bindEvents=function(){var K=this;if(this.events={},this.events.dismiss=A.bind(this),this.events.navigate=D.bind(this),this.events.reset=this.reset.bind(this),this.config.nativeDropdown||this.mobileDevice){this.container.addEventListener("touchstart",function(O){O.changedTouches[0].target===K.el&&K.toggle()}),this.container.addEventListener("click",function(O){O.target===K.el&&K.toggle()});var L=function(O,P){for(var S,Q=[],R=O.slice(0),T=0;T=O.key.length&&String[String.fromCodePoint?"fromCodePoint":"fromCharCode"](O.key[String.codePointAt?"codePointAt":"charCodeAt"](0))===O.key){if(K.config.multiple)K.open(),K.config.searchable&&(K.input.value=O.key,K.input.focus(),K.search(null,!0));else{null,M+=O.key;var P=K.search(M,!0);P&&P.length&&(K.clear(),K.setValue(P[0].value)),setTimeout(function(){M=""},1e3)}return O.preventDefault(),void O.stopPropagation()}}}),this.container.addEventListener("keyup",function(O){K.opened&&"Escape"===O.key&&(K.close(),O.stopPropagation(),K.selected.focus())})}this.label.addEventListener("click",function(O){u.hasClass(O.target,"selectr-tag-remove")&&K.deselect(O.target.parentNode.idx)}),this.selectClear&&this.selectClear.addEventListener("click",this.clear.bind(this)),this.tree.addEventListener("mousedown",function(O){O.preventDefault()}),this.tree.addEventListener("click",function(O){var P=u.closest(O.target,function(Q){return Q&&u.hasClass(Q,"selectr-option")});P&&!u.hasClass(P,"disabled")&&(u.hasClass(P,"selected")?(K.el.multiple||!K.el.multiple&&K.config.allowDeselect)&&K.deselect(P.idx):K.select(P.idx),K.opened&&!K.el.multiple&&K.close()),O.preventDefault(),O.stopPropagation()}),this.tree.addEventListener("mouseover",function(O){u.hasClass(O.target,"selectr-option")&&!u.hasClass(O.target,"disabled")&&(u.removeClass(K.items[K.navIndex],"active"),u.addClass(O.target,"active"),K.navIndex=[].slice.call(K.items).indexOf(O.target))}),this.config.searchable&&(this.input.addEventListener("focus",function(){K.searching=!0}),this.input.addEventListener("blur",function(){K.searching=!1}),this.input.addEventListener("keyup",function(){K.search(),K.config.taggable||(this.value.length?u.addClass(this.parentNode,"active"):u.removeClass(this.parentNode,"active"))}),this.inputClear.addEventListener("click",function(){K.input.value=null,H.call(K),K.tree.childElementCount||z.call(K)})),this.config.taggable&&this.input.addEventListener("keyup",function(O){if(K.search(),K.config.taggable&&this.value.length){var P=this.value.trim();if(13===O.which||u.includes(K.tagSeperators,O.key)){u.each(K.tagSeperators,function(R,S){P=P.replace(S,"")});var Q=K.add({value:P,text:P,selected:!0},!0);Q?(K.close(),H.call(K)):(this.value="",K.setMessage(K.config.messages.tagDuplicate))}}}),this.update=u.debounce(function(){K.opened&&K.config.closeOnScroll&&K.close(),K.width&&(K.container.style.width=K.width),K.invert()},50),this.requiresPagination&&(this.paginateItems=u.debounce(function(){G.call(this)},50),this.tree.addEventListener("scroll",this.paginateItems.bind(this))),document.addEventListener("click",this.events.dismiss),window.addEventListener("keydown",this.events.navigate),window.addEventListener("resize",this.update),window.addEventListener("scroll",this.update),this.on("selectr.destroy",function(){document.removeEventListener("click",this.events.dismiss),window.removeEventListener("keydown",this.events.navigate),window.removeEventListener("resize",this.update),window.removeEventListener("scroll",this.update)}),this.el.form&&(this.el.form.addEventListener("reset",this.events.reset),this.on("selectr.destroy",function(){this.el.form.removeEventListener("reset",this.events.reset)}))},J.prototype.setSelected=function(){if(this.config.data||this.el.multiple||!this.el.options.length||(0===this.el.selectedIndex&&!this.el.options[0].defaultSelected&&!this.config.defaultSelected&&(this.el.selectedIndex=-1),this.selectedIndex=this.el.selectedIndex,-1this.el.selectedIndex&&this.select(0);var L=0;u.each(this.config.data,function(M,N){n(N,"children")?u.each(N.children,function(O,P){P.hasOwnProperty("selected")&&!0===P.selected&&this.select(L),L++},this):(N.hasOwnProperty("selected")&&!0===N.selected&&this.select(L),L++)},this)}},J.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),u.removeClass(this.el,"selectr-hidden"),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1)},J.prototype.change=function(K){var L=this.items[K],M=this.options[K];M.disabled||(M.selected&&u.hasClass(L,"selected")?this.deselect(K):this.select(K),this.opened&&!this.el.multiple&&this.close())},J.prototype.select=function(K){var L=this.items[K],M=[].slice.call(this.el.options),N=this.options[K];if(this.el.multiple){if(u.includes(this.selectedIndexes,K))return!1;if(this.config.maxSelections&&this.tags.length===this.config.maxSelections)return this.setMessage(this.config.messages.maxSelections.replace("{max}",this.config.maxSelections),!0),!1;this.selectedValues.push(N.value),this.selectedIndexes.push(K),E.call(this,L)}else{var O=this.data?this.data[K]:N;this.label.innerHTML=this.customSelected?this.config.renderSelection(O):N.textContent,this.selectedValue=N.value,this.selectedIndex=K,u.each(this.options,function(Q,R){var S=this.items[Q];Q!==K&&(S&&u.removeClass(S,"selected"),R.selected=!1,R.removeAttribute("selected"))},this)}if(u.includes(M,N)||this.el.add(N),L.setAttribute("aria-selected",!0),u.addClass(L,"selected"),u.addClass(this.container,"has-selected"),N.selected=!0,N.setAttribute("selected",""),this.emit("selectr.change",N),this.emit("selectr.select",N),"createEvent"in document){var P=document.createEvent("HTMLEvents");P.initEvent("change",!0,!0),this.el.dispatchEvent(P)}else this.el.fireEvent("onchange")},J.prototype.deselect=function(K,L){var M=this.items[K],N=this.options[K];if(this.el.multiple){var O=this.selectedIndexes.indexOf(K);this.selectedIndexes.splice(O,1);var P=this.selectedValues.indexOf(N.value);this.selectedValues.splice(P,1),F.call(this,M),this.tags.length||u.removeClass(this.container,"has-selected")}else{if(!L&&!this.config.clearable&&!this.config.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=this.selectedIndex=-1,u.removeClass(this.container,"has-selected")}if(this.items[K].setAttribute("aria-selected",!1),u.removeClass(this.items[K],"selected"),N.selected=!1,N.removeAttribute("selected"),this.emit("selectr.change",null),this.emit("selectr.deselect",N),"createEvent"in document){var Q=document.createEvent("HTMLEvents");Q.initEvent("change",!0,!0),this.el.dispatchEvent(Q)}else this.el.fireEvent("onchange")},J.prototype.setValue=function(K){var L=Array.isArray(K);return L||(K=K.toString().trim()),!this.el.multiple&&L?!1:void u.each(this.options,function(M,N){(L&&u.includes(K,N.value.toString())||N.value===K)&&this.change(N.idx)},this)},J.prototype.getValue=function(K,L){var M;if(this.el.multiple)K?this.selectedIndexes.length&&(M={},M.values=[],u.each(this.selectedIndexes,function(O,P){var Q=this.options[P];M.values[O]={value:Q.value,text:Q.textContent}},this)):M=this.selectedValues.slice();else if(K){var N=this.options[this.selectedIndex];M={value:N.value,text:N.textContent}}else M=this.selectedValue;return K&&L&&(M=JSON.stringify(M)),M},J.prototype.add=function(K,L){if(K){if(this.data=this.data||[],this.items=this.items||[],this.options=this.options||[],Array.isArray(K))u.each(K,function(O,P){this.add(P,L)},this);else if("[object Object]"===Object.prototype.toString.call(K)){if(L){var M=!1;if(u.each(this.options,function(O,P){P.value.toLowerCase()===K.value.toLowerCase()&&(M=!0)}),M)return!1}var N=u.createElement("option",K);return this.data.push(K),this.options.push(N),N.idx=0M;N?(u.addClass(this.container,"inverted"),this.isInverted=!0):(u.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=u.rect(this.tree)},J.prototype.getOptionByIndex=function(K){return this.options[K]},J.prototype.getOptionByValue=function(K){for(var L=!1,M=0,N=this.options.length;M"+b.label+""}),c.each(b.children,function(a,c){c.idx=d;e.appendChild(m.call(this,c,e));d++},this)):(b.idx=d,m.call(this,b),d++)},this);if(this.config.data&&Array.isArray(this.config.data)){this.data=[];var f=!1,h;e=!1;d=0;c.each(this.config.data,function(a,b){k(b,"children")?(f=c.createElement("optgroup",{label:b.text}),e=c.createElement("ul",{"class":"selectr-optgroup", +role:"group",html:"
  • "+b.text+"
  • "}),c.each(b.children,function(a,b){h=new Option(b.text,b.value,!1,b.hasOwnProperty("selected")&&!0===b.selected);h.disabled=k(b,"disabled");this.options.push(h);f.appendChild(h);h.idx=d;e.appendChild(m.call(this,h,b));this.data[d]=b;d++},this),this.el.appendChild(f)):(h=new Option(b.text,b.value,!1,b.hasOwnProperty("selected")&&!0===b.selected),h.disabled=k(b,"disabled"),this.options.push(h),h.idx=d,m.call(this,h,b),this.data[d]= +b,d++)},this)}this.setSelected(!0);for(var g=this.navIndex=0;gthis.tree.lastElementChild.idx){this.navIndex=this.tree.lastElementChild.idx;break}else if(this.navIndexthis.optsRect.top+ +this.optsRect.height&&(this.tree.scrollTop+=a.top+a.height-(this.optsRect.top+this.optsRect.height)),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&r.call(this)):0===this.navIndex?this.tree.scrollTop=0:0>a.top-this.optsRect.top&&(this.tree.scrollTop+=a.top-this.optsRect.top);b&&c.removeClass(b,"active");c.addClass(this.items[this.navIndex],"active")}else this.navigating=!1},x=function(a){var b=this,e=document.createDocumentFragment(),d=this.options[a.idx],f=this.data?this.data[a.idx]: +d;f=this.customSelected?this.config.renderSelection(f):d.textContent;f=c.createElement("li",{"class":"selectr-tag",html:f});var h=c.createElement("button",{"class":"selectr-tag-remove",type:"button"});f.appendChild(h);f.idx=a.idx;f.tag=d.value;this.tags.push(f);if(this.config.sortSelected){a=this.tags.slice();var g=function(a,b){a.replace(/(\d+)|(\D+)/g,function(a,d,c){b.push([d||Infinity,c||""])})};a.sort(function(a,d){var c=[],e=[];if(!0===b.config.sortSelected){var f=a.tag;var h=d.tag}else"text"=== +b.config.sortSelected&&(f=a.textContent,h=d.textContent);g(f,c);for(g(h,e);c.length&&e.length;)if(f=c.shift(),h=e.shift(),f=f[0]-h[0]||f[1].localeCompare(h[1]))return f;return c.length-e.length});c.each(a,function(a,b){e.appendChild(b)});this.label.innerHTML=""}else e.appendChild(f);this.config.taggable?this.label.insertBefore(e,this.input.parentNode):this.label.appendChild(e)},y=function(a){var b=!1;c.each(this.tags,function(c,d){d.idx===a.idx&&(b=d)},this);b&&(this.label.removeChild(b),this.tags.splice(this.tags.indexOf(b), +1))},r=function(){var a=this.tree;if(a.scrollTop>=a.scrollHeight-a.offsetHeight&&this.pageIndex=b.key.length&&String[String.fromCodePoint?"fromCodePoint":"fromCharCode"](b.key[String.codePointAt?"codePointAt":"charCodeAt"](0))===b.key){if(a.config.multiple)a.open(),a.config.searchable&&(a.input.value=b.key,a.input.focus(),a.search(null,!0));else{e+=b.key;var c= +a.search(e,!0);c&&c.length&&(a.clear(),a.setValue(c[0].value));setTimeout(function(){e=""},1E3)}b.preventDefault();b.stopPropagation()}});this.container.addEventListener("keyup",function(b){a.opened&&"Escape"===b.key&&(a.close(),b.stopPropagation(),a.selected.focus())})}this.label.addEventListener("click",function(b){c.hasClass(b.target,"selectr-tag-remove")&&a.deselect(b.target.parentNode.idx)});this.selectClear&&this.selectClear.addEventListener("click",this.clear.bind(this));this.tree.addEventListener("mousedown", +function(a){a.preventDefault()});this.tree.addEventListener("click",function(b){var d=c.closest(b.target,function(a){return a&&c.hasClass(a,"selectr-option")});d&&!c.hasClass(d,"disabled")&&(c.hasClass(d,"selected")?(a.el.multiple||!a.el.multiple&&a.config.allowDeselect)&&a.deselect(d.idx):a.select(d.idx),a.opened&&!a.el.multiple&&a.close());b.preventDefault();b.stopPropagation()});this.tree.addEventListener("mouseover",function(b){c.hasClass(b.target,"selectr-option")&&!c.hasClass(b.target,"disabled")&& +(c.removeClass(a.items[a.navIndex],"active"),c.addClass(b.target,"active"),a.navIndex=[].slice.call(a.items).indexOf(b.target))});this.config.searchable&&(this.input.addEventListener("focus",function(b){a.searching=!0}),this.input.addEventListener("blur",function(b){a.searching=!1}),this.input.addEventListener("keyup",function(b){a.search();a.config.taggable||(this.value.length?c.addClass(this.parentNode,"active"):c.removeClass(this.parentNode,"active"))}),this.inputClear.addEventListener("click", +function(b){a.input.value=null;q.call(a);a.tree.childElementCount||p.call(a)}));this.config.taggable&&this.input.addEventListener("keyup",function(b){a.search();if(a.config.taggable&&this.value.length){var d=this.value.trim();if(13===b.which||c.includes(a.tagSeperators,b.key))c.each(a.tagSeperators,function(a,b){d=d.replace(b,"")}),a.add({value:d,text:d,selected:!0},!0)?(a.close(),q.call(a)):(this.value="",a.setMessage(a.config.messages.tagDuplicate))}});this.update=c.debounce(function(){a.opened&& +a.config.closeOnScroll&&a.close();a.width&&(a.container.style.width=a.width);a.invert()},50);this.requiresPagination&&(this.paginateItems=c.debounce(function(){r.call(this)},50),this.tree.addEventListener("scroll",this.paginateItems.bind(this)));document.addEventListener("click",this.events.dismiss);window.addEventListener("keydown",this.events.navigate);window.addEventListener("resize",this.update);window.addEventListener("scroll",this.update);this.on("selectr.destroy",function(){document.removeEventListener("click", +this.events.dismiss);window.removeEventListener("keydown",this.events.navigate);window.removeEventListener("resize",this.update);window.removeEventListener("scroll",this.update)});this.el.form&&(this.el.form.addEventListener("reset",this.events.reset),this.on("selectr.destroy",function(){this.el.form.removeEventListener("reset",this.events.reset)}))};g.prototype.setSelected=function(a){this.config.data||this.el.multiple||!this.el.options.length||(0!==this.el.selectedIndex||this.el.options[0].defaultSelected|| +this.config.defaultSelected||(this.el.selectedIndex=-1),this.selectedIndex=this.el.selectedIndex,-1this.el.selectedIndex&&this.select(0);var b=0;c.each(this.config.data,function(a,d){k(d,"children")?c.each(d.children,function(a,c){c.hasOwnProperty("selected")&&!0===c.selected&&this.select(b);b++},this):(d.hasOwnProperty("selected")&&!0===d.selected&&this.select(b),b++)},this)}};g.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),c.removeClass(this.el, +"selectr-hidden"),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1,delete this.el.selectr)};g.prototype.change=function(a){var b=this.items[a],e=this.options[a];e.disabled||(e.selected&&c.hasClass(b,"selected")?this.deselect(a):this.select(a),this.opened&&!this.el.multiple&&this.close())};g.prototype.select=function(a){var b=this.items[a],e=[].slice.call(this.el.options),d=this.options[a];if(this.el.multiple){if(c.includes(this.selectedIndexes,a))return!1;if(this.config.maxSelections&& +this.tags.length===this.config.maxSelections)return this.setMessage(this.config.messages.maxSelections.replace("{max}",this.config.maxSelections),!0),!1;this.selectedValues.push(d.value);this.selectedIndexes.push(a);x.call(this,b)}else{var f=this.data?this.data[a]:d;this.label.innerHTML=this.customSelected?this.config.renderSelection(f):d.textContent;this.selectedValue=d.value;this.selectedIndex=a;c.each(this.options,function(b,d){var e=this.items[b];b!==a&&(e&&c.removeClass(e,"selected"),d.selected= +!1,d.removeAttribute("selected"))},this)}c.includes(e,d)||this.el.add(d);b.setAttribute("aria-selected",!0);c.addClass(b,"selected");c.addClass(this.container,"has-selected");d.selected=!0;d.setAttribute("selected","");this.emit("selectr.change",d);this.emit("selectr.select",d);"createEvent"in document?(b=document.createEvent("HTMLEvents"),b.initEvent("change",!0,!0),this.el.dispatchEvent(b)):this.el.fireEvent("onchange")};g.prototype.deselect=function(a,b){var e=this.items[a],d=this.options[a];if(this.el.multiple){var f= +this.selectedIndexes.indexOf(a);this.selectedIndexes.splice(f,1);f=this.selectedValues.indexOf(d.value);this.selectedValues.splice(f,1);y.call(this,e);this.tags.length||c.removeClass(this.container,"has-selected")}else{if(!b&&!this.config.clearable&&!this.config.allowDeselect)return!1;this.label.innerHTML="";this.selectedValue=null;this.el.selectedIndex=this.selectedIndex=-1;c.removeClass(this.container,"has-selected")}this.items[a].setAttribute("aria-selected",!1);c.removeClass(this.items[a],"selected"); +d.selected=!1;d.removeAttribute("selected");this.emit("selectr.change",null);this.emit("selectr.deselect",d);"createEvent"in document?(e=document.createEvent("HTMLEvents"),e.initEvent("change",!0,!0),this.el.dispatchEvent(e)):this.el.fireEvent("onchange")};g.prototype.setValue=function(a){var b=Array.isArray(a);b||(a=a.toString().trim());if(!this.el.multiple&&b)return!1;c.each(this.options,function(c,d){(b&&-1"+l[0]+""):!1;k.innerHTML=l}}else e&&c.addClass(k, +"excluded")},this);if(e){if(f.childElementCount){var k=this.items[this.navIndex],l=f.querySelector(".selectr-option:not(.excluded)");this.noResults=!1;c.removeClass(k,"active");this.navIndex=l.idx;c.addClass(l,"active")}else this.config.taggable||(this.noResults=!0,this.setMessage(this.config.messages.noResults));this.tree.appendChild(f)}}else p.call(this);return d}};g.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())};g.prototype.open=function(){var a=this;if(!this.options.length)return!1; +this.opened||this.emit("selectr.open");this.opened=!0;this.mobileDevice||this.config.nativeDropdown?(c.addClass(this.container,"native-open"),this.config.data&&c.each(this.options,function(a,c){this.el.add(c)},this)):(c.addClass(this.container,"open"),p.call(this),this.invert(),this.tree.scrollTop=0,c.removeClass(this.container,"notice"),this.selected.setAttribute("aria-expanded",!0),this.tree.setAttribute("aria-hidden",!1),this.tree.setAttribute("aria-expanded",!0),this.config.searchable&&!this.config.taggable&& +setTimeout(function(){a.input.focus();a.input.tabIndex=0},10))};g.prototype.close=function(){this.opened&&this.emit("selectr.close");this.navigating=this.opened=!1;if(this.mobileDevice||this.config.nativeDropdown)c.removeClass(this.container,"native-open");else{var a=c.hasClass(this.container,"notice");this.config.searchable&&!a&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1);a&&(c.removeClass(this.container,"notice"),this.notice.textContent="");c.removeClass(this.container,"open"); +c.removeClass(this.container,"native-open");this.selected.setAttribute("aria-expanded",!1);this.tree.setAttribute("aria-hidden",!0);this.tree.setAttribute("aria-expanded",!1);c.truncate(this.tree);q.call(this);this.selected.focus()}};g.prototype.enable=function(){this.disabled=!1;this.el.disabled=!1;this.selected.tabIndex=this.originalIndex;this.el.multiple&&c.each(this.tags,function(a,b){b.lastElementChild.tabIndex=0});c.removeClass(this.container,"selectr-disabled")};g.prototype.disable=function(a){a|| +(this.el.disabled=!0);this.selected.tabIndex=-1;this.el.multiple&&c.each(this.tags,function(a,c){c.lastElementChild.tabIndex=-1});this.disabled=!0;c.addClass(this.container,"selectr-disabled")};g.prototype.reset=function(){this.disabled||(this.clear(),this.setSelected(!0),c.each(this.defaultSelected,function(a,b){this.select(b)},this),this.emit("selectr.reset"))};g.prototype.clear=function(a){this.el.multiple?this.selectedIndexes.length&&(a=this.selectedIndexes.slice(),c.each(a,function(a,c){this.deselect(c)}, +this)):-1window.innerHeight?(c.addClass(this.container,"inverted"),this.isInverted=!0):(c.removeClass(this.container,"inverted"),this.isInverted=!1);this.optsRect=c.rect(this.tree)};g.prototype.getOptionByIndex=function(a){return this.options[a]};g.prototype.getOptionByValue=function(a){for(var b=!1,c=0,d=this.options.length;c