Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobius1-selectr

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobius1-selectr - npm Package Compare versions

Comparing version 2.4.4 to 2.4.5

2

bower.json
{
"name": "mobius1-selectr",
"version": "2.4.4",
"version": "2.4.5",
"ignore": [

@@ -5,0 +5,0 @@ ".gitattributes",

/*
Selectr 2.4.4
Selectr 2.4.5
http://mobius.ovh/docs/selectr

@@ -7,2 +7,2 @@

*/
(function(m,n){var q="Selectr";"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n(q):m[q]=n(q)})(this,function(){"use strict";function n(L,M){return L.hasOwnProperty(M)&&(!0===L[M]||L[M].length)}function q(L,M,N){L.parentNode?!L.parentNode.parentNode&&M.appendChild(L.parentNode):M.appendChild(L),z.removeClass(L,"excluded"),N||(L.innerHTML=L.textContent)}var s={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..."},u=function(){};u.prototype={on:function(L,M){this._events=this._events||{},this._events[L]=this._events[L]||[],this._events[L].push(M)},off:function(L,M){this._events=this._events||{},!1==L in this._events||this._events[L].splice(this._events[L].indexOf(M),1)},emit:function(L){if(this._events=this._events||{},!1!=L in this._events)for(var M=0;M<this._events[L].length;M++)this._events[L][M].apply(this,Array.prototype.slice.call(arguments,1))}},u.mixin=function(L){for(var M=["on","off","emit"],N=0;N<M.length;N++)"function"==typeof L?L.prototype[M[N]]=u.prototype[M[N]]:L[M[N]]=u.prototype[M[N]];return L};var z={extend:function(L,M){M=M||{};for(var N in L)L.hasOwnProperty(N)&&(M.hasOwnProperty(N)||(M[N]=L[N]));return M},each:function(L,M,N){if("[object Object]"===Object.prototype.toString.call(L))for(var O in L)Object.prototype.hasOwnProperty.call(L,O)&&M.call(N,O,L[O],L);else for(var P=0,Q=L.length;P<Q;P++)M.call(N,P,L[P],L)},createElement:function(L,M){var N=document,O=N.createElement(L);if(M&&"[object Object]"===Object.prototype.toString.call(M)){for(var P in M)if(P in O)O[P]=M[P];else if("html"===P)O.innerHTML=M[P];else if("text"===P){var Q=N.createTextNode(M[P]);O.appendChild(Q)}else O.setAttribute(P,M[P])}return O},hasClass:function(L,M){if(L)return L.classList?L.classList.contains(M):!!L.className&&!!L.className.match(new RegExp("(\\s|^)"+M+"(\\s|$)"))},addClass:function(L,M){z.hasClass(L,M)||(L.classList?L.classList.add(M):L.className=L.className.trim()+" "+M)},removeClass:function(L,M){z.hasClass(L,M)&&(L.classList?L.classList.remove(M):L.className=L.className.replace(new RegExp("(^|\\s)"+M.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(L,M){return L&&L!==document.body&&(M(L)?L:z.closest(L.parentNode,M))},isInt:function(L){return"number"==typeof L&&isFinite(L)&&Math.floor(L)===L},debounce:function(L,M,N){var O;return function(){var P=this,Q=arguments,S=N&&!O;clearTimeout(O),O=setTimeout(function(){O=null,N||L.apply(P,Q)},M),S&&L.apply(P,Q)}},rect:function(L,M){var N=window,O=L.getBoundingClientRect(),P=M?N.pageXOffset:0,Q=M?N.pageYOffset:0;return{bottom:O.bottom+Q,height:O.height,left:O.left+P,right:O.right+P,top:O.top+Q,width:O.width}},includes:function(L,M){return-1<L.indexOf(M)},startsWith:function(L,M){return L.substr(0,M.length)===M},truncate:function(L){for(;L.firstChild;)L.removeChild(L.firstChild)}},A=function(){if(this.items.length){var L=document.createDocumentFragment();if(this.config.pagination){var M=this.pages.slice(0,this.pageIndex);z.each(M,function(N,O){z.each(O,function(P,Q){q(Q,L,this.customOption)},this)},this)}else z.each(this.items,function(N,O){q(O,L,this.customOption)},this);L.childElementCount&&(z.removeClass(this.items[this.navIndex],"active"),this.navIndex=(L.querySelector(".selectr-option.selected")||L.querySelector(".selectr-option")).idx,z.addClass(this.items[this.navIndex],"active")),this.tree.appendChild(L)}},B=function(L){var M=L.target;!this.container.contains(M)&&(this.opened||z.hasClass(this.container,"notice"))&&this.close()},C=function(L,M){M=M||L;var N=this.customOption?this.config.renderOption(M):L.textContent,O=z.createElement("li",{class:"selectr-option",html:N,role:"treeitem","aria-selected":!1});return O.idx=L.idx,this.items.push(O),L.defaultSelected&&this.defaultSelected.push(L.idx),L.disabled&&(O.disabled=!0,z.addClass(O,"disabled")),O},D=function(){this.requiresPagination=this.config.pagination&&0<this.config.pagination,n(this.config,"width")&&(z.isInt(this.config.width)?this.width=this.config.width+"px":"auto"===this.config.width?this.width="100%":z.includes(this.config.width,"%")&&(this.width=this.config.width)),this.container=z.createElement("div",{class:"selectr-container"}),this.config.customClass&&z.addClass(this.container,this.config.customClass),this.mobileDevice?z.addClass(this.container,"selectr-mobile"):z.addClass(this.container,"selectr-desktop"),this.el.tabIndex=-1,this.config.nativeDropdown||this.mobileDevice?z.addClass(this.el,"selectr-visible"):z.addClass(this.el,"selectr-hidden"),this.selected=z.createElement("div",{class:"selectr-selected",disabled:this.disabled,tabIndex:0,"aria-expanded":!1}),this.label=z.createElement(this.el.multiple?"ul":"span",{class:"selectr-label"});var L=z.createElement("div",{class:"selectr-options-container"});if(this.tree=z.createElement("ul",{class:"selectr-options",role:"tree","aria-hidden":!0,"aria-expanded":!1}),this.notice=z.createElement("div",{class:"selectr-notice"}),this.el.setAttribute("aria-hidden",!0),this.disabled&&(this.el.disabled=!0),this.el.multiple&&(z.addClass(this.label,"selectr-tags"),z.addClass(this.container,"multiple"),this.tags=[],this.selectedValues=this.getSelectedProperties("value"),this.selectedIndexes=this.getSelectedProperties("idx")),this.selected.appendChild(this.label),this.config.clearable&&(this.selectClear=z.createElement("button",{class:"selectr-clear",type:"button"}),this.container.appendChild(this.selectClear),z.addClass(this.container,"clearable")),this.config.taggable){var M=z.createElement("li",{class:"input-tag"});this.input=z.createElement("input",{class:"selectr-tag-input",placeholder:this.config.tagPlaceholder,tagIndex:0,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),M.appendChild(this.input),this.label.appendChild(M),z.addClass(this.container,"taggable"),this.tagSeperators=[","],this.config.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(this.config.tagSeperators))}this.config.searchable&&(this.input=z.createElement("input",{class:"selectr-input",tagIndex:-1,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),this.inputClear=z.createElement("button",{class:"selectr-input-clear",type:"button"}),this.inputContainer=z.createElement("div",{class:"selectr-input-container"}),this.inputContainer.appendChild(this.input),this.inputContainer.appendChild(this.inputClear),L.appendChild(this.inputContainer)),L.appendChild(this.notice),L.appendChild(this.tree),this.items=[],this.options=[],this.el.options.length&&(this.options=[].slice.call(this.el.options));var N=!1,O=0;if(this.el.children.length&&z.each(this.el.children,function(T,U){"OPTGROUP"===U.nodeName?(N=z.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+U.label+"</li>"}),z.each(U.children,function(V,W){W.idx=O,N.appendChild(C.call(this,W,N)),O++},this)):(U.idx=O,C.call(this,U),O++)},this),this.config.data&&Array.isArray(this.config.data)){this.data=[];var Q,P=!1;N=!1,O=0,z.each(this.config.data,function(T,U){n(U,"children")?(P=z.createElement("optgroup",{label:U.text}),N=z.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+U.text+"</li>"}),z.each(U.children,function(V,W){Q=new Option(W.text,W.value,!1,W.hasOwnProperty("selected")&&!0===W.selected),Q.disabled=n(W,"disabled"),this.options.push(Q),P.appendChild(Q),Q.idx=O,N.appendChild(C.call(this,Q,W)),this.data[O]=W,O++},this)):(Q=new Option(U.text,U.value,!1,U.hasOwnProperty("selected")&&!0===U.selected),Q.disabled=n(U,"disabled"),this.options.push(Q),Q.idx=O,C.call(this,Q,U),this.data[O]=U,O++)},this)}this.setSelected(!0);var R;this.navIndex=0;for(var S=0;S<this.items.length;S++)if(R=this.items[S],!z.hasClass(R,"disabled")){z.addClass(R,"active"),this.navIndex=S;break}this.requiresPagination&&(this.pageIndex=1,this.paginate()),this.container.appendChild(this.selected),this.container.appendChild(L),this.placeEl=z.createElement("div",{class:"selectr-placeholder"}),this.setPlaceholder(),this.selected.appendChild(this.placeEl),this.disabled&&this.disable(),this.el.parentNode.insertBefore(this.container,this.el),this.container.appendChild(this.el)},E=function(L){if(L=L||window.event,!this.items.length||!this.opened||!z.includes([13,38,40],L.which))return void(this.navigating=!1);if(L.preventDefault(),13===L.which)return this.config.taggable&&0<this.input.value.length?!1:this.change(this.navIndex);var M,N=this.items[this.navIndex],O=this.navIndex;switch(L.which){case 38:M=0,0<this.navIndex&&this.navIndex--;break;case 40:M=1,this.navIndex<this.items.length-1&&this.navIndex++;}for(this.navigating=!0;z.hasClass(this.items[this.navIndex],"disabled")||z.hasClass(this.items[this.navIndex],"excluded");){if(0<this.navIndex&&this.navIndex<this.items.length-1)M?this.navIndex++:this.navIndex--;else{this.navIndex=O;break}if(this.searching)if(this.navIndex>this.tree.lastElementChild.idx){this.navIndex=this.tree.lastElementChild.idx;break}else if(this.navIndex<this.tree.firstElementChild.idx){this.navIndex=this.tree.firstElementChild.idx;break}}var P=z.rect(this.items[this.navIndex]);M?(0===this.navIndex?this.tree.scrollTop=0:P.top+P.height>this.optsRect.top+this.optsRect.height&&(this.tree.scrollTop+=P.top+P.height-(this.optsRect.top+this.optsRect.height)),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&H.call(this)):0===this.navIndex?this.tree.scrollTop=0:0>P.top-this.optsRect.top&&(this.tree.scrollTop+=P.top-this.optsRect.top),N&&z.removeClass(N,"active"),z.addClass(this.items[this.navIndex],"active")},F=function(L){var N,M=this,O=document.createDocumentFragment(),P=this.options[L.idx],Q=this.data?this.data[L.idx]:P,R=this.customSelected?this.config.renderSelection(Q):P.textContent,S=z.createElement("li",{class:"selectr-tag",html:R}),T=z.createElement("button",{class:"selectr-tag-remove",type:"button"});if(S.appendChild(T),S.idx=L.idx,S.tag=P.value,this.tags.push(S),this.config.sortSelected){var U=this.tags.slice();N=function(V,W){V.replace(/(\d+)|(\D+)/g,function(X,Y,Z){W.push([Y||Infinity,Z||""])})},U.sort(function(V,W){var Z,$,X=[],Y=[];for(!0===M.config.sortSelected?(Z=V.tag,$=W.tag):"text"===M.config.sortSelected&&(Z=V.textContent,$=W.textContent),N(Z,X),N($,Y);X.length&&Y.length;){var _=X.shift(),aa=Y.shift(),ba=_[0]-aa[0]||_[1].localeCompare(aa[1]);if(ba)return ba}return X.length-Y.length}),z.each(U,function(V,W){O.appendChild(W)}),this.label.innerHTML=""}else O.appendChild(S);this.config.taggable?this.label.insertBefore(O,this.input.parentNode):this.label.appendChild(O)},G=function(L){var M=!1;z.each(this.tags,function(N,O){O.idx===L.idx&&(M=O)},this),M&&(this.label.removeChild(M),this.tags.splice(this.tags.indexOf(M),1))},H=function(){var L=this.tree,M=L.scrollTop,N=L.scrollHeight,O=L.offsetHeight;if(M>=N-O&&this.pageIndex<this.pages.length){var Q=document.createDocumentFragment();z.each(this.pages[this.pageIndex],function(R,S){q(S,Q,this.customOption)},this),L.appendChild(Q),this.pageIndex++,this.emit("selectr.paginate",{items:this.items.length,total:this.data.length,page:this.pageIndex,pages:this.pages.length})}},I=function(){(this.config.searchable||this.config.taggable)&&(this.input.value=null,this.searching=!1,this.config.searchable&&z.removeClass(this.inputContainer,"active"),z.hasClass(this.container,"notice")&&(z.removeClass(this.container,"notice"),z.addClass(this.container,"open"),this.input.focus()),z.each(this.items,function(L,M){z.removeClass(M,"excluded"),this.customOption||(M.innerHTML=M.textContent)},this))},J=function(L,M){var N=new RegExp(L,"i").exec(M.textContent);return!!N&&M.textContent.replace(N[0],"<span class='selectr-match'>"+N[0]+"</span>")},K=function(L,M){if(M=M||{},!L)throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");if(this.el=L,"string"==typeof L&&(this.el=document.querySelector(L)),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(M)};return K.prototype.render=function(L){if(!this.rendered){this.config=z.extend(s,L),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,u.mixin(this),D.call(this),this.bindEvents(),this.update(),this.optsRect=z.rect(this.tree),this.rendered=!0,this.el.multiple||(this.el.selectedIndex=this.selectedIndex);var M=this;setTimeout(function(){M.emit("selectr.init")},20)}},K.prototype.getSelected=function(){var L=this.el.querySelectorAll("option:checked");return L},K.prototype.getSelectedProperties=function(L){var M=this.getSelected(),N=[].slice.call(M).map(function(O){return O[L]}).filter(function(O){return null!==O&&void 0!==O});return N},K.prototype.bindEvents=function(){var L=this;if(this.events={},this.events.dismiss=B.bind(this),this.events.navigate=E.bind(this),this.events.reset=this.reset.bind(this),this.config.nativeDropdown||this.mobileDevice){this.container.addEventListener("touchstart",function(P){P.changedTouches[0].target===L.el&&L.toggle()}),this.container.addEventListener("click",function(P){P.target===L.el&&L.toggle()});var M=function(P,Q){for(var T,R=[],S=P.slice(0),U=0;U<Q.length;U++)T=S.indexOf(Q[U]),-1<T?S.splice(T,1):R.push(Q[U]);return[R,S]};this.el.addEventListener("change",function(){if(L.el.multiple){var Q=L.getSelectedProperties("idx"),R=M(L.selectedIndexes,Q);z.each(R[0],function(S,T){L.select(T)},L),z.each(R[1],function(S,T){L.deselect(T)},L)}else-1<L.el.selectedIndex&&L.select(L.el.selectedIndex)})}if(this.container.addEventListener("keydown",function(P){"Escape"===P.key&&L.close(),"Enter"===P.key&&L.selected===document.activeElement&&"undefined"!=typeof L.el.form.submit&&L.el.form.submit(),(" "===P.key||"ArrowUp"===P.key||"ArrowDown"===P.key)&&L.selected===document.activeElement&&(setTimeout(function(){L.toggle()},200),L.config.nativeDropdown&&setTimeout(function(){L.el.focus()},200))}),this.selected.addEventListener("click",function(P){L.disabled||L.toggle(),P.preventDefault()}),this.config.nativeKeyboard){var N="";this.selected.addEventListener("keydown",function(P){if(!(L.disabled||L.selected!==document.activeElement||P.altKey||P.ctrlKey||P.metaKey)){if(" "===P.key||!L.opened&&-1<["Enter","ArrowUp","ArrowDown"].indexOf(P.key))return L.toggle(),P.preventDefault(),void P.stopPropagation();if(2>=P.key.length&&String[String.fromCodePoint?"fromCodePoint":"fromCharCode"](P.key[String.codePointAt?"codePointAt":"charCodeAt"](0))===P.key){if(L.config.multiple)L.open(),L.config.searchable&&(L.input.value=P.key,L.input.focus(),L.search(null,!0));else{null,N+=P.key;var Q=L.search(N,!0);Q&&Q.length&&(L.clear(),L.setValue(Q[0].value)),setTimeout(function(){N=""},1e3)}return P.preventDefault(),void P.stopPropagation()}}}),this.container.addEventListener("keyup",function(P){L.opened&&"Escape"===P.key&&(L.close(),P.stopPropagation(),L.selected.focus())})}this.label.addEventListener("click",function(P){z.hasClass(P.target,"selectr-tag-remove")&&L.deselect(P.target.parentNode.idx)}),this.selectClear&&this.selectClear.addEventListener("click",this.clear.bind(this)),this.tree.addEventListener("mousedown",function(P){P.preventDefault()}),this.tree.addEventListener("click",function(P){var Q=z.closest(P.target,function(R){return R&&z.hasClass(R,"selectr-option")});Q&&!z.hasClass(Q,"disabled")&&(z.hasClass(Q,"selected")?(L.el.multiple||!L.el.multiple&&L.config.allowDeselect)&&L.deselect(Q.idx):L.select(Q.idx),L.opened&&!L.el.multiple&&L.close()),P.preventDefault(),P.stopPropagation()}),this.tree.addEventListener("mouseover",function(P){z.hasClass(P.target,"selectr-option")&&!z.hasClass(P.target,"disabled")&&(z.removeClass(L.items[L.navIndex],"active"),z.addClass(P.target,"active"),L.navIndex=[].slice.call(L.items).indexOf(P.target))}),this.config.searchable&&(this.input.addEventListener("focus",function(){L.searching=!0}),this.input.addEventListener("blur",function(){L.searching=!1}),this.input.addEventListener("keyup",function(){L.search(),L.config.taggable||(this.value.length?z.addClass(this.parentNode,"active"):z.removeClass(this.parentNode,"active"))}),this.inputClear.addEventListener("click",function(){L.input.value=null,I.call(L),L.tree.childElementCount||A.call(L)})),this.config.taggable&&this.input.addEventListener("keyup",function(P){if(L.search(),L.config.taggable&&this.value.length){var Q=this.value.trim();if(13===P.which||z.includes(L.tagSeperators,P.key)){z.each(L.tagSeperators,function(S,T){Q=Q.replace(T,"")});var R=L.add({value:Q,text:Q,selected:!0},!0);R?(L.close(),I.call(L)):(this.value="",L.setMessage("That tag is already in use."))}}}),this.update=z.debounce(function(){L.opened&&L.config.closeOnScroll&&L.close(),L.width&&(L.container.style.width=L.width),L.invert()},50),this.requiresPagination&&(this.paginateItems=z.debounce(function(){H.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)}))},K.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,-1<this.selectedIndex&&this.select(this.selectedIndex)),this.config.multiple&&"select-one"===this.originalType&&!this.config.data&&this.el.options[0].selected&&!this.el.options[0].defaultSelected&&(this.el.options[0].selected=!1),z.each(this.options,function(N,O){O.selected&&O.defaultSelected&&this.select(O.idx)},this),this.config.selectedValue&&this.setValue(this.config.selectedValue),this.config.data){!this.el.multiple&&this.config.defaultSelected&&0>this.el.selectedIndex&&this.select(0);var M=0;z.each(this.config.data,function(N,O){n(O,"children")?z.each(O.children,function(P,Q){Q.hasOwnProperty("selected")&&!0===Q.selected&&this.select(M),M++},this):(O.hasOwnProperty("selected")&&!0===O.selected&&this.select(M),M++)},this)}},K.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),z.removeClass(this.el,"selectr-hidden"),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1)},K.prototype.change=function(L){var M=this.items[L],N=this.options[L];N.disabled||(N.selected&&z.hasClass(M,"selected")?this.deselect(L):this.select(L),this.opened&&!this.el.multiple&&this.close())},K.prototype.select=function(L){var M=this.items[L],N=[].slice.call(this.el.options),O=this.options[L];if(this.el.multiple){if(z.includes(this.selectedIndexes,L))return!1;if(this.config.maxSelections&&this.tags.length===this.config.maxSelections)return this.setMessage("A maximum of "+this.config.maxSelections+" items can be selected.",!0),!1;this.selectedValues.push(O.value),this.selectedIndexes.push(L),F.call(this,M)}else{var P=this.data?this.data[L]:O;this.label.innerHTML=this.customSelected?this.config.renderSelection(P):O.textContent,this.selectedValue=O.value,this.selectedIndex=L,z.each(this.options,function(R,S){var T=this.items[R];R!==L&&(T&&z.removeClass(T,"selected"),S.selected=!1,S.removeAttribute("selected"))},this)}if(z.includes(N,O)||this.el.add(O),M.setAttribute("aria-selected",!0),z.addClass(M,"selected"),z.addClass(this.container,"has-selected"),O.selected=!0,O.setAttribute("selected",""),this.emit("selectr.change",O),this.emit("selectr.select",O),"createEvent"in document){var Q=document.createEvent("HTMLEvents");Q.initEvent("change",!0,!0),this.el.dispatchEvent(Q)}else this.el.fireEvent("onchange")},K.prototype.deselect=function(L,M){var N=this.items[L],O=this.options[L];if(this.el.multiple){var P=this.selectedIndexes.indexOf(L);this.selectedIndexes.splice(P,1);var Q=this.selectedValues.indexOf(O.value);this.selectedValues.splice(Q,1),G.call(this,N),this.tags.length||z.removeClass(this.container,"has-selected")}else{if(!M&&!this.config.clearable&&!this.config.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=this.selectedIndex=-1,z.removeClass(this.container,"has-selected")}if(this.items[L].setAttribute("aria-selected",!1),z.removeClass(this.items[L],"selected"),O.selected=!1,O.removeAttribute("selected"),this.emit("selectr.change",null),this.emit("selectr.deselect",O),"createEvent"in document){var R=document.createEvent("HTMLEvents");R.initEvent("change",!0,!0),this.el.dispatchEvent(R)}else this.el.fireEvent("onchange")},K.prototype.setValue=function(L){var M=Array.isArray(L);return M||(L=L.toString().trim()),!this.el.multiple&&M?!1:void z.each(this.options,function(N,O){(M&&z.includes(L,O.value.toString())||O.value===L)&&this.change(O.idx)},this)},K.prototype.getValue=function(L,M){var N;if(this.el.multiple)L?this.selectedIndexes.length&&(N={},N.values=[],z.each(this.selectedIndexes,function(P,Q){var R=this.options[Q];N.values[P]={value:R.value,text:R.textContent}},this)):N=this.selectedValues.slice();else if(L){var O=this.options[this.selectedIndex];N={value:O.value,text:O.textContent}}else N=this.selectedValue;return L&&M&&(N=JSON.stringify(N)),N},K.prototype.add=function(L,M){if(L){if(this.data=this.data||[],this.items=this.items||[],this.options=this.options||[],Array.isArray(L))z.each(L,function(P,Q){this.add(Q,M)},this);else if("[object Object]"===Object.prototype.toString.call(L)){if(M){var N=!1;if(z.each(this.options,function(P,Q){Q.value.toLowerCase()===L.value.toLowerCase()&&(N=!0)}),N)return!1}var O=z.createElement("option",L);return this.data.push(L),this.options.push(O),O.idx=0<this.options.length?this.options.length-1:0,C.call(this,O),L.selected&&this.select(O.idx),this.setPlaceholder(),O}return this.config.pagination&&this.paginate(),!0}},K.prototype.remove=function(L){var M=[];if(Array.isArray(L)?z.each(L,function(O,P){z.isInt(P)?M.push(this.getOptionByIndex(P)):"string"==typeof L&&M.push(this.getOptionByValue(P))},this):z.isInt(L)?M.push(this.getOptionByIndex(L)):"string"==typeof L&&M.push(this.getOptionByValue(L)),M.length){var N;z.each(M,function(O,P){N=P.idx,this.el.remove(P),this.options.splice(N,1);var Q=this.items[N].parentNode;Q&&Q.removeChild(this.items[N]),this.items.splice(N,1),z.each(this.options,function(R,S){S.idx=R,this.items[R].idx=R},this)},this),this.setPlaceholder(),this.config.pagination&&this.paginate()}},K.prototype.removeAll=function(){this.clear(!0),z.each(this.el.options,function(L,M){this.el.remove(M)},this),z.truncate(this.tree),this.items=[],this.options=[],this.data=[],this.navIndex=0,this.requiresPagination&&(this.requiresPagination=!1,this.pageIndex=1,this.pages=[]),this.setPlaceholder()},K.prototype.search=function(L,M){if(!this.navigating){var N=!1;L||(L=this.input.value,N=!0,this.removeMessage(),z.truncate(this.tree));var O=[],P=document.createDocumentFragment();if(L=L.trim().toLowerCase(),0<L.length){var Q=M?z.startsWith:z.includes;if(z.each(this.options,function(T,U){var V=this.items[U.idx],W=Q(U.textContent.trim().toLowerCase(),L);W&&!U.disabled?(O.push({text:U.textContent,value:U.value}),N&&(q(V,P,this.customOption),z.removeClass(V,"excluded"),!this.customOption&&(V.innerHTML=J(L,U)))):N&&z.addClass(V,"excluded")},this),N){if(!P.childElementCount)this.config.taggable||this.setMessage("no results.");else{var R=this.items[this.navIndex],S=P.querySelector(".selectr-option:not(.excluded)");z.removeClass(R,"active"),this.navIndex=S.idx,z.addClass(S,"active")}this.tree.appendChild(P)}}else A.call(this);return O}},K.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())},K.prototype.open=function(){var L=this;return!!this.options.length&&(this.opened||this.emit("selectr.open"),this.opened=!0,this.mobileDevice||this.config.nativeDropdown?(z.addClass(this.container,"native-open"),void(this.config.data&&z.each(this.options,function(M,N){this.el.add(N)},this))):void(z.addClass(this.container,"open"),A.call(this),this.invert(),this.tree.scrollTop=0,z.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(){L.input.focus(),L.input.tabIndex=0},10)))},K.prototype.close=function(){if(this.opened&&this.emit("selectr.close"),this.opened=!1,this.navigating=!1,this.mobileDevice||this.config.nativeDropdown)return void z.removeClass(this.container,"native-open");var L=z.hasClass(this.container,"notice");this.config.searchable&&!L&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),L&&(z.removeClass(this.container,"notice"),this.notice.textContent=""),z.removeClass(this.container,"open"),z.removeClass(this.container,"native-open"),this.selected.setAttribute("aria-expanded",!1),this.tree.setAttribute("aria-hidden",!0),this.tree.setAttribute("aria-expanded",!1),z.truncate(this.tree),I.call(this),this.selected.focus()},K.prototype.enable=function(){this.disabled=!1,this.el.disabled=!1,this.selected.tabIndex=this.originalIndex,this.el.multiple&&z.each(this.tags,function(L,M){M.lastElementChild.tabIndex=0}),z.removeClass(this.container,"selectr-disabled")},K.prototype.disable=function(L){L||(this.el.disabled=!0),this.selected.tabIndex=-1,this.el.multiple&&z.each(this.tags,function(M,N){N.lastElementChild.tabIndex=-1}),this.disabled=!0,z.addClass(this.container,"selectr-disabled")},K.prototype.reset=function(){this.disabled||(this.clear(),this.setSelected(!0),z.each(this.defaultSelected,function(L,M){this.select(M)},this),this.emit("selectr.reset"))},K.prototype.clear=function(L){if(!this.el.multiple)-1<this.selectedIndex&&this.deselect(this.selectedIndex,L);else if(this.selectedIndexes.length){var M=this.selectedIndexes.slice();z.each(M,function(N,O){this.deselect(O)},this)}this.emit("selectr.clear")},K.prototype.serialise=function(L){var M=[];return z.each(this.options,function(N,O){var P={value:O.value,text:O.textContent};O.selected&&(P.selected=!0),O.disabled&&(P.disabled=!0),M[N]=P}),L?JSON.stringify(M):M},K.prototype.serialize=function(L){return this.serialise(L)},K.prototype.setPlaceholder=function(L){L=L||this.config.placeholder||this.el.getAttribute("placeholder"),this.options.length||(L="No options available"),this.placeEl.innerHTML=L},K.prototype.paginate=function(){if(this.items.length){var L=this;return this.pages=this.items.map(function(M,N){return 0==N%L.config.pagination?L.items.slice(N,N+L.config.pagination):null}).filter(function(M){return M}),this.pages}},K.prototype.setMessage=function(L,M){M&&this.close(),z.addClass(this.container,"notice"),this.notice.textContent=L},K.prototype.removeMessage=function(){z.removeClass(this.container,"notice"),this.notice.innerHTML=""},K.prototype.invert=function(){var L=z.rect(this.selected),M=this.tree.parentNode.offsetHeight,N=window.innerHeight,O=L.top+L.height+M>N;O?(z.addClass(this.container,"inverted"),this.isInverted=!0):(z.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=z.rect(this.tree)},K.prototype.getOptionByIndex=function(L){return this.options[L]},K.prototype.getOptionByValue=function(L){for(var M=!1,N=0,O=this.options.length;N<O;N++)if(this.options[N].value.trim()===L.toString().trim()){M=this.options[N];break}return M},K});
(function(m,n){var q="Selectr";"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?module.exports=n(q):m[q]=n(q)})(this,function(){"use strict";function n(L,M){return L.hasOwnProperty(M)&&(!0===L[M]||L[M].length)}function q(L,M,N){L.parentNode?!L.parentNode.parentNode&&M.appendChild(L.parentNode):M.appendChild(L),z.removeClass(L,"excluded"),N||(L.innerHTML=L.textContent)}var s={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..."},u=function(){};u.prototype={on:function(L,M){this._events=this._events||{},this._events[L]=this._events[L]||[],this._events[L].push(M)},off:function(L,M){this._events=this._events||{},!1==L in this._events||this._events[L].splice(this._events[L].indexOf(M),1)},emit:function(L){if(this._events=this._events||{},!1!=L in this._events)for(var M=0;M<this._events[L].length;M++)this._events[L][M].apply(this,Array.prototype.slice.call(arguments,1))}},u.mixin=function(L){for(var M=["on","off","emit"],N=0;N<M.length;N++)"function"==typeof L?L.prototype[M[N]]=u.prototype[M[N]]:L[M[N]]=u.prototype[M[N]];return L};var z={extend:function(L,M){M=M||{};for(var N in L)L.hasOwnProperty(N)&&(M.hasOwnProperty(N)||(M[N]=L[N]));return M},each:function(L,M,N){if("[object Object]"===Object.prototype.toString.call(L))for(var O in L)Object.prototype.hasOwnProperty.call(L,O)&&M.call(N,O,L[O],L);else for(var P=0,Q=L.length;P<Q;P++)M.call(N,P,L[P],L)},createElement:function(L,M){var N=document,O=N.createElement(L);if(M&&"[object Object]"===Object.prototype.toString.call(M)){for(var P in M)if(P in O)O[P]=M[P];else if("html"===P)O.innerHTML=M[P];else if("text"===P){var Q=N.createTextNode(M[P]);O.appendChild(Q)}else O.setAttribute(P,M[P])}return O},hasClass:function(L,M){if(L)return L.classList?L.classList.contains(M):!!L.className&&!!L.className.match(new RegExp("(\\s|^)"+M+"(\\s|$)"))},addClass:function(L,M){z.hasClass(L,M)||(L.classList?L.classList.add(M):L.className=L.className.trim()+" "+M)},removeClass:function(L,M){z.hasClass(L,M)&&(L.classList?L.classList.remove(M):L.className=L.className.replace(new RegExp("(^|\\s)"+M.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(L,M){return L&&L!==document.body&&(M(L)?L:z.closest(L.parentNode,M))},isInt:function(L){return"number"==typeof L&&isFinite(L)&&Math.floor(L)===L},debounce:function(L,M,N){var O;return function(){var P=this,Q=arguments,S=N&&!O;clearTimeout(O),O=setTimeout(function(){O=null,N||L.apply(P,Q)},M),S&&L.apply(P,Q)}},rect:function(L,M){var N=window,O=L.getBoundingClientRect(),P=M?N.pageXOffset:0,Q=M?N.pageYOffset:0;return{bottom:O.bottom+Q,height:O.height,left:O.left+P,right:O.right+P,top:O.top+Q,width:O.width}},includes:function(L,M){return-1<L.indexOf(M)},startsWith:function(L,M){return L.substr(0,M.length)===M},truncate:function(L){for(;L.firstChild;)L.removeChild(L.firstChild)}},A=function(){if(this.items.length){var L=document.createDocumentFragment();if(this.config.pagination){var M=this.pages.slice(0,this.pageIndex);z.each(M,function(N,O){z.each(O,function(P,Q){q(Q,L,this.customOption)},this)},this)}else z.each(this.items,function(N,O){q(O,L,this.customOption)},this);L.childElementCount&&(z.removeClass(this.items[this.navIndex],"active"),this.navIndex=(L.querySelector(".selectr-option.selected")||L.querySelector(".selectr-option")).idx,z.addClass(this.items[this.navIndex],"active")),this.tree.appendChild(L)}},B=function(L){var M=L.target;!this.container.contains(M)&&(this.opened||z.hasClass(this.container,"notice"))&&this.close()},C=function(L,M){M=M||L;var N=this.customOption?this.config.renderOption(M):L.textContent,O=z.createElement("li",{class:"selectr-option",html:N,role:"treeitem","aria-selected":!1});return O.idx=L.idx,this.items.push(O),L.defaultSelected&&this.defaultSelected.push(L.idx),L.disabled&&(O.disabled=!0,z.addClass(O,"disabled")),O},D=function(){this.requiresPagination=this.config.pagination&&0<this.config.pagination,n(this.config,"width")&&(z.isInt(this.config.width)?this.width=this.config.width+"px":"auto"===this.config.width?this.width="100%":z.includes(this.config.width,"%")&&(this.width=this.config.width)),this.container=z.createElement("div",{class:"selectr-container"}),this.config.customClass&&z.addClass(this.container,this.config.customClass),this.mobileDevice?z.addClass(this.container,"selectr-mobile"):z.addClass(this.container,"selectr-desktop"),this.el.tabIndex=-1,this.config.nativeDropdown||this.mobileDevice?z.addClass(this.el,"selectr-visible"):z.addClass(this.el,"selectr-hidden"),this.selected=z.createElement("div",{class:"selectr-selected",disabled:this.disabled,tabIndex:0,"aria-expanded":!1}),this.label=z.createElement(this.el.multiple?"ul":"span",{class:"selectr-label"});var L=z.createElement("div",{class:"selectr-options-container"});if(this.tree=z.createElement("ul",{class:"selectr-options",role:"tree","aria-hidden":!0,"aria-expanded":!1}),this.notice=z.createElement("div",{class:"selectr-notice"}),this.el.setAttribute("aria-hidden",!0),this.disabled&&(this.el.disabled=!0),this.el.multiple&&(z.addClass(this.label,"selectr-tags"),z.addClass(this.container,"multiple"),this.tags=[],this.selectedValues=this.getSelectedProperties("value"),this.selectedIndexes=this.getSelectedProperties("idx")),this.selected.appendChild(this.label),this.config.clearable&&(this.selectClear=z.createElement("button",{class:"selectr-clear",type:"button"}),this.container.appendChild(this.selectClear),z.addClass(this.container,"clearable")),this.config.taggable){var M=z.createElement("li",{class:"input-tag"});this.input=z.createElement("input",{class:"selectr-tag-input",placeholder:this.config.tagPlaceholder,tagIndex:0,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),M.appendChild(this.input),this.label.appendChild(M),z.addClass(this.container,"taggable"),this.tagSeperators=[","],this.config.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(this.config.tagSeperators))}this.config.searchable&&(this.input=z.createElement("input",{class:"selectr-input",tagIndex:-1,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),this.inputClear=z.createElement("button",{class:"selectr-input-clear",type:"button"}),this.inputContainer=z.createElement("div",{class:"selectr-input-container"}),this.inputContainer.appendChild(this.input),this.inputContainer.appendChild(this.inputClear),L.appendChild(this.inputContainer)),L.appendChild(this.notice),L.appendChild(this.tree),this.items=[],this.options=[],this.el.options.length&&(this.options=[].slice.call(this.el.options));var N=!1,O=0;if(this.el.children.length&&z.each(this.el.children,function(T,U){"OPTGROUP"===U.nodeName?(N=z.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+U.label+"</li>"}),z.each(U.children,function(V,W){W.idx=O,N.appendChild(C.call(this,W,N)),O++},this)):(U.idx=O,C.call(this,U),O++)},this),this.config.data&&Array.isArray(this.config.data)){this.data=[];var Q,P=!1;N=!1,O=0,z.each(this.config.data,function(T,U){n(U,"children")?(P=z.createElement("optgroup",{label:U.text}),N=z.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+U.text+"</li>"}),z.each(U.children,function(V,W){Q=new Option(W.text,W.value,!1,W.hasOwnProperty("selected")&&!0===W.selected),Q.disabled=n(W,"disabled"),this.options.push(Q),P.appendChild(Q),Q.idx=O,N.appendChild(C.call(this,Q,W)),this.data[O]=W,O++},this),this.el.appendChild(P)):(Q=new Option(U.text,U.value,!1,U.hasOwnProperty("selected")&&!0===U.selected),Q.disabled=n(U,"disabled"),this.options.push(Q),Q.idx=O,C.call(this,Q,U),this.data[O]=U,O++)},this)}this.setSelected(!0);var R;this.navIndex=0;for(var S=0;S<this.items.length;S++)if(R=this.items[S],!z.hasClass(R,"disabled")){z.addClass(R,"active"),this.navIndex=S;break}this.requiresPagination&&(this.pageIndex=1,this.paginate()),this.container.appendChild(this.selected),this.container.appendChild(L),this.placeEl=z.createElement("div",{class:"selectr-placeholder"}),this.setPlaceholder(),this.selected.appendChild(this.placeEl),this.disabled&&this.disable(),this.el.parentNode.insertBefore(this.container,this.el),this.container.appendChild(this.el)},E=function(L){if(L=L||window.event,!this.items.length||!this.opened||!z.includes([13,38,40],L.which))return void(this.navigating=!1);if(L.preventDefault(),13===L.which)return this.config.taggable&&0<this.input.value.length?!1:this.change(this.navIndex);var M,N=this.items[this.navIndex],O=this.navIndex;switch(L.which){case 38:M=0,0<this.navIndex&&this.navIndex--;break;case 40:M=1,this.navIndex<this.items.length-1&&this.navIndex++;}for(this.navigating=!0;z.hasClass(this.items[this.navIndex],"disabled")||z.hasClass(this.items[this.navIndex],"excluded");){if(0<this.navIndex&&this.navIndex<this.items.length-1)M?this.navIndex++:this.navIndex--;else{this.navIndex=O;break}if(this.searching)if(this.navIndex>this.tree.lastElementChild.idx){this.navIndex=this.tree.lastElementChild.idx;break}else if(this.navIndex<this.tree.firstElementChild.idx){this.navIndex=this.tree.firstElementChild.idx;break}}var P=z.rect(this.items[this.navIndex]);M?(0===this.navIndex?this.tree.scrollTop=0:P.top+P.height>this.optsRect.top+this.optsRect.height&&(this.tree.scrollTop+=P.top+P.height-(this.optsRect.top+this.optsRect.height)),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&H.call(this)):0===this.navIndex?this.tree.scrollTop=0:0>P.top-this.optsRect.top&&(this.tree.scrollTop+=P.top-this.optsRect.top),N&&z.removeClass(N,"active"),z.addClass(this.items[this.navIndex],"active")},F=function(L){var N,M=this,O=document.createDocumentFragment(),P=this.options[L.idx],Q=this.data?this.data[L.idx]:P,R=this.customSelected?this.config.renderSelection(Q):P.textContent,S=z.createElement("li",{class:"selectr-tag",html:R}),T=z.createElement("button",{class:"selectr-tag-remove",type:"button"});if(S.appendChild(T),S.idx=L.idx,S.tag=P.value,this.tags.push(S),this.config.sortSelected){var U=this.tags.slice();N=function(V,W){V.replace(/(\d+)|(\D+)/g,function(X,Y,Z){W.push([Y||Infinity,Z||""])})},U.sort(function(V,W){var Z,$,X=[],Y=[];for(!0===M.config.sortSelected?(Z=V.tag,$=W.tag):"text"===M.config.sortSelected&&(Z=V.textContent,$=W.textContent),N(Z,X),N($,Y);X.length&&Y.length;){var _=X.shift(),aa=Y.shift(),ba=_[0]-aa[0]||_[1].localeCompare(aa[1]);if(ba)return ba}return X.length-Y.length}),z.each(U,function(V,W){O.appendChild(W)}),this.label.innerHTML=""}else O.appendChild(S);this.config.taggable?this.label.insertBefore(O,this.input.parentNode):this.label.appendChild(O)},G=function(L){var M=!1;z.each(this.tags,function(N,O){O.idx===L.idx&&(M=O)},this),M&&(this.label.removeChild(M),this.tags.splice(this.tags.indexOf(M),1))},H=function(){var L=this.tree,M=L.scrollTop,N=L.scrollHeight,O=L.offsetHeight;if(M>=N-O&&this.pageIndex<this.pages.length){var Q=document.createDocumentFragment();z.each(this.pages[this.pageIndex],function(R,S){q(S,Q,this.customOption)},this),L.appendChild(Q),this.pageIndex++,this.emit("selectr.paginate",{items:this.items.length,total:this.data.length,page:this.pageIndex,pages:this.pages.length})}},I=function(){(this.config.searchable||this.config.taggable)&&(this.input.value=null,this.searching=!1,this.config.searchable&&z.removeClass(this.inputContainer,"active"),z.hasClass(this.container,"notice")&&(z.removeClass(this.container,"notice"),z.addClass(this.container,"open"),this.input.focus()),z.each(this.items,function(L,M){z.removeClass(M,"excluded"),this.customOption||(M.innerHTML=M.textContent)},this))},J=function(L,M){var N=new RegExp(L,"i").exec(M.textContent);return!!N&&M.textContent.replace(N[0],"<span class='selectr-match'>"+N[0]+"</span>")},K=function(L,M){if(M=M||{},!L)throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");if(this.el=L,"string"==typeof L&&(this.el=document.querySelector(L)),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(M)};return K.prototype.render=function(L){if(!this.rendered){this.config=z.extend(s,L),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,u.mixin(this),D.call(this),this.bindEvents(),this.update(),this.optsRect=z.rect(this.tree),this.rendered=!0,this.el.multiple||(this.el.selectedIndex=this.selectedIndex);var M=this;setTimeout(function(){M.emit("selectr.init")},20)}},K.prototype.getSelected=function(){var L=this.el.querySelectorAll("option:checked");return L},K.prototype.getSelectedProperties=function(L){var M=this.getSelected(),N=[].slice.call(M).map(function(O){return O[L]}).filter(function(O){return null!==O&&void 0!==O});return N},K.prototype.bindEvents=function(){var L=this;if(this.events={},this.events.dismiss=B.bind(this),this.events.navigate=E.bind(this),this.events.reset=this.reset.bind(this),this.config.nativeDropdown||this.mobileDevice){this.container.addEventListener("touchstart",function(P){P.changedTouches[0].target===L.el&&L.toggle()}),this.container.addEventListener("click",function(P){P.target===L.el&&L.toggle()});var M=function(P,Q){for(var T,R=[],S=P.slice(0),U=0;U<Q.length;U++)T=S.indexOf(Q[U]),-1<T?S.splice(T,1):R.push(Q[U]);return[R,S]};this.el.addEventListener("change",function(){if(L.el.multiple){var Q=L.getSelectedProperties("idx"),R=M(L.selectedIndexes,Q);z.each(R[0],function(S,T){L.select(T)},L),z.each(R[1],function(S,T){L.deselect(T)},L)}else-1<L.el.selectedIndex&&L.select(L.el.selectedIndex)})}if(this.container.addEventListener("keydown",function(P){"Escape"===P.key&&L.close(),"Enter"===P.key&&L.selected===document.activeElement&&"undefined"!=typeof L.el.form.submit&&L.el.form.submit(),(" "===P.key||"ArrowUp"===P.key||"ArrowDown"===P.key)&&L.selected===document.activeElement&&(setTimeout(function(){L.toggle()},200),L.config.nativeDropdown&&setTimeout(function(){L.el.focus()},200))}),this.selected.addEventListener("click",function(P){L.disabled||L.toggle(),P.preventDefault()}),this.config.nativeKeyboard){var N="";this.selected.addEventListener("keydown",function(P){if(!(L.disabled||L.selected!==document.activeElement||P.altKey||P.ctrlKey||P.metaKey)){if(" "===P.key||!L.opened&&-1<["Enter","ArrowUp","ArrowDown"].indexOf(P.key))return L.toggle(),P.preventDefault(),void P.stopPropagation();if(2>=P.key.length&&String[String.fromCodePoint?"fromCodePoint":"fromCharCode"](P.key[String.codePointAt?"codePointAt":"charCodeAt"](0))===P.key){if(L.config.multiple)L.open(),L.config.searchable&&(L.input.value=P.key,L.input.focus(),L.search(null,!0));else{null,N+=P.key;var Q=L.search(N,!0);Q&&Q.length&&(L.clear(),L.setValue(Q[0].value)),setTimeout(function(){N=""},1e3)}return P.preventDefault(),void P.stopPropagation()}}}),this.container.addEventListener("keyup",function(P){L.opened&&"Escape"===P.key&&(L.close(),P.stopPropagation(),L.selected.focus())})}this.label.addEventListener("click",function(P){z.hasClass(P.target,"selectr-tag-remove")&&L.deselect(P.target.parentNode.idx)}),this.selectClear&&this.selectClear.addEventListener("click",this.clear.bind(this)),this.tree.addEventListener("mousedown",function(P){P.preventDefault()}),this.tree.addEventListener("click",function(P){var Q=z.closest(P.target,function(R){return R&&z.hasClass(R,"selectr-option")});Q&&!z.hasClass(Q,"disabled")&&(z.hasClass(Q,"selected")?(L.el.multiple||!L.el.multiple&&L.config.allowDeselect)&&L.deselect(Q.idx):L.select(Q.idx),L.opened&&!L.el.multiple&&L.close()),P.preventDefault(),P.stopPropagation()}),this.tree.addEventListener("mouseover",function(P){z.hasClass(P.target,"selectr-option")&&!z.hasClass(P.target,"disabled")&&(z.removeClass(L.items[L.navIndex],"active"),z.addClass(P.target,"active"),L.navIndex=[].slice.call(L.items).indexOf(P.target))}),this.config.searchable&&(this.input.addEventListener("focus",function(){L.searching=!0}),this.input.addEventListener("blur",function(){L.searching=!1}),this.input.addEventListener("keyup",function(){L.search(),L.config.taggable||(this.value.length?z.addClass(this.parentNode,"active"):z.removeClass(this.parentNode,"active"))}),this.inputClear.addEventListener("click",function(){L.input.value=null,I.call(L),L.tree.childElementCount||A.call(L)})),this.config.taggable&&this.input.addEventListener("keyup",function(P){if(L.search(),L.config.taggable&&this.value.length){var Q=this.value.trim();if(13===P.which||z.includes(L.tagSeperators,P.key)){z.each(L.tagSeperators,function(S,T){Q=Q.replace(T,"")});var R=L.add({value:Q,text:Q,selected:!0},!0);R?(L.close(),I.call(L)):(this.value="",L.setMessage("That tag is already in use."))}}}),this.update=z.debounce(function(){L.opened&&L.config.closeOnScroll&&L.close(),L.width&&(L.container.style.width=L.width),L.invert()},50),this.requiresPagination&&(this.paginateItems=z.debounce(function(){H.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)}))},K.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,-1<this.selectedIndex&&this.select(this.selectedIndex)),this.config.multiple&&"select-one"===this.originalType&&!this.config.data&&this.el.options[0].selected&&!this.el.options[0].defaultSelected&&(this.el.options[0].selected=!1),z.each(this.options,function(N,O){O.selected&&O.defaultSelected&&this.select(O.idx)},this),this.config.selectedValue&&this.setValue(this.config.selectedValue),this.config.data){!this.el.multiple&&this.config.defaultSelected&&0>this.el.selectedIndex&&this.select(0);var M=0;z.each(this.config.data,function(N,O){n(O,"children")?z.each(O.children,function(P,Q){Q.hasOwnProperty("selected")&&!0===Q.selected&&this.select(M),M++},this):(O.hasOwnProperty("selected")&&!0===O.selected&&this.select(M),M++)},this)}},K.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),z.removeClass(this.el,"selectr-hidden"),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1)},K.prototype.change=function(L){var M=this.items[L],N=this.options[L];N.disabled||(N.selected&&z.hasClass(M,"selected")?this.deselect(L):this.select(L),this.opened&&!this.el.multiple&&this.close())},K.prototype.select=function(L){var M=this.items[L],N=[].slice.call(this.el.options),O=this.options[L];if(this.el.multiple){if(z.includes(this.selectedIndexes,L))return!1;if(this.config.maxSelections&&this.tags.length===this.config.maxSelections)return this.setMessage("A maximum of "+this.config.maxSelections+" items can be selected.",!0),!1;this.selectedValues.push(O.value),this.selectedIndexes.push(L),F.call(this,M)}else{var P=this.data?this.data[L]:O;this.label.innerHTML=this.customSelected?this.config.renderSelection(P):O.textContent,this.selectedValue=O.value,this.selectedIndex=L,z.each(this.options,function(R,S){var T=this.items[R];R!==L&&(T&&z.removeClass(T,"selected"),S.selected=!1,S.removeAttribute("selected"))},this)}if(z.includes(N,O)||this.el.add(O),M.setAttribute("aria-selected",!0),z.addClass(M,"selected"),z.addClass(this.container,"has-selected"),O.selected=!0,O.setAttribute("selected",""),this.emit("selectr.change",O),this.emit("selectr.select",O),"createEvent"in document){var Q=document.createEvent("HTMLEvents");Q.initEvent("change",!0,!0),this.el.dispatchEvent(Q)}else this.el.fireEvent("onchange")},K.prototype.deselect=function(L,M){var N=this.items[L],O=this.options[L];if(this.el.multiple){var P=this.selectedIndexes.indexOf(L);this.selectedIndexes.splice(P,1);var Q=this.selectedValues.indexOf(O.value);this.selectedValues.splice(Q,1),G.call(this,N),this.tags.length||z.removeClass(this.container,"has-selected")}else{if(!M&&!this.config.clearable&&!this.config.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=this.selectedIndex=-1,z.removeClass(this.container,"has-selected")}if(this.items[L].setAttribute("aria-selected",!1),z.removeClass(this.items[L],"selected"),O.selected=!1,O.removeAttribute("selected"),this.emit("selectr.change",null),this.emit("selectr.deselect",O),"createEvent"in document){var R=document.createEvent("HTMLEvents");R.initEvent("change",!0,!0),this.el.dispatchEvent(R)}else this.el.fireEvent("onchange")},K.prototype.setValue=function(L){var M=Array.isArray(L);return M||(L=L.toString().trim()),!this.el.multiple&&M?!1:void z.each(this.options,function(N,O){(M&&z.includes(L,O.value.toString())||O.value===L)&&this.change(O.idx)},this)},K.prototype.getValue=function(L,M){var N;if(this.el.multiple)L?this.selectedIndexes.length&&(N={},N.values=[],z.each(this.selectedIndexes,function(P,Q){var R=this.options[Q];N.values[P]={value:R.value,text:R.textContent}},this)):N=this.selectedValues.slice();else if(L){var O=this.options[this.selectedIndex];N={value:O.value,text:O.textContent}}else N=this.selectedValue;return L&&M&&(N=JSON.stringify(N)),N},K.prototype.add=function(L,M){if(L){if(this.data=this.data||[],this.items=this.items||[],this.options=this.options||[],Array.isArray(L))z.each(L,function(P,Q){this.add(Q,M)},this);else if("[object Object]"===Object.prototype.toString.call(L)){if(M){var N=!1;if(z.each(this.options,function(P,Q){Q.value.toLowerCase()===L.value.toLowerCase()&&(N=!0)}),N)return!1}var O=z.createElement("option",L);return this.data.push(L),this.options.push(O),O.idx=0<this.options.length?this.options.length-1:0,C.call(this,O),L.selected&&this.select(O.idx),this.setPlaceholder(),O}return this.config.pagination&&this.paginate(),!0}},K.prototype.remove=function(L){var M=[];if(Array.isArray(L)?z.each(L,function(O,P){z.isInt(P)?M.push(this.getOptionByIndex(P)):"string"==typeof L&&M.push(this.getOptionByValue(P))},this):z.isInt(L)?M.push(this.getOptionByIndex(L)):"string"==typeof L&&M.push(this.getOptionByValue(L)),M.length){var N;z.each(M,function(O,P){N=P.idx,this.el.remove(P),this.options.splice(N,1);var Q=this.items[N].parentNode;Q&&Q.removeChild(this.items[N]),this.items.splice(N,1),z.each(this.options,function(R,S){S.idx=R,this.items[R].idx=R},this)},this),this.setPlaceholder(),this.config.pagination&&this.paginate()}},K.prototype.removeAll=function(){this.clear(!0),z.each(this.el.options,function(L,M){this.el.remove(M)},this),z.truncate(this.tree),this.items=[],this.options=[],this.data=[],this.navIndex=0,this.requiresPagination&&(this.requiresPagination=!1,this.pageIndex=1,this.pages=[]),this.setPlaceholder()},K.prototype.search=function(L,M){if(!this.navigating){var N=!1;L||(L=this.input.value,N=!0,this.removeMessage(),z.truncate(this.tree));var O=[],P=document.createDocumentFragment();if(L=L.trim().toLowerCase(),0<L.length){var Q=M?z.startsWith:z.includes;if(z.each(this.options,function(T,U){var V=this.items[U.idx],W=Q(U.textContent.trim().toLowerCase(),L);W&&!U.disabled?(O.push({text:U.textContent,value:U.value}),N&&(q(V,P,this.customOption),z.removeClass(V,"excluded"),!this.customOption&&(V.innerHTML=J(L,U)))):N&&z.addClass(V,"excluded")},this),N){if(!P.childElementCount)this.config.taggable||this.setMessage("no results.");else{var R=this.items[this.navIndex],S=P.querySelector(".selectr-option:not(.excluded)");z.removeClass(R,"active"),this.navIndex=S.idx,z.addClass(S,"active")}this.tree.appendChild(P)}}else A.call(this);return O}},K.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())},K.prototype.open=function(){var L=this;return!!this.options.length&&(this.opened||this.emit("selectr.open"),this.opened=!0,this.mobileDevice||this.config.nativeDropdown?(z.addClass(this.container,"native-open"),void(this.config.data&&z.each(this.options,function(M,N){this.el.add(N)},this))):void(z.addClass(this.container,"open"),A.call(this),this.invert(),this.tree.scrollTop=0,z.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(){L.input.focus(),L.input.tabIndex=0},10)))},K.prototype.close=function(){if(this.opened&&this.emit("selectr.close"),this.opened=!1,this.navigating=!1,this.mobileDevice||this.config.nativeDropdown)return void z.removeClass(this.container,"native-open");var L=z.hasClass(this.container,"notice");this.config.searchable&&!L&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),L&&(z.removeClass(this.container,"notice"),this.notice.textContent=""),z.removeClass(this.container,"open"),z.removeClass(this.container,"native-open"),this.selected.setAttribute("aria-expanded",!1),this.tree.setAttribute("aria-hidden",!0),this.tree.setAttribute("aria-expanded",!1),z.truncate(this.tree),I.call(this),this.selected.focus()},K.prototype.enable=function(){this.disabled=!1,this.el.disabled=!1,this.selected.tabIndex=this.originalIndex,this.el.multiple&&z.each(this.tags,function(L,M){M.lastElementChild.tabIndex=0}),z.removeClass(this.container,"selectr-disabled")},K.prototype.disable=function(L){L||(this.el.disabled=!0),this.selected.tabIndex=-1,this.el.multiple&&z.each(this.tags,function(M,N){N.lastElementChild.tabIndex=-1}),this.disabled=!0,z.addClass(this.container,"selectr-disabled")},K.prototype.reset=function(){this.disabled||(this.clear(),this.setSelected(!0),z.each(this.defaultSelected,function(L,M){this.select(M)},this),this.emit("selectr.reset"))},K.prototype.clear=function(L){if(!this.el.multiple)-1<this.selectedIndex&&this.deselect(this.selectedIndex,L);else if(this.selectedIndexes.length){var M=this.selectedIndexes.slice();z.each(M,function(N,O){this.deselect(O)},this)}this.emit("selectr.clear")},K.prototype.serialise=function(L){var M=[];return z.each(this.options,function(N,O){var P={value:O.value,text:O.textContent};O.selected&&(P.selected=!0),O.disabled&&(P.disabled=!0),M[N]=P}),L?JSON.stringify(M):M},K.prototype.serialize=function(L){return this.serialise(L)},K.prototype.setPlaceholder=function(L){L=L||this.config.placeholder||this.el.getAttribute("placeholder"),this.options.length||(L="No options available"),this.placeEl.innerHTML=L},K.prototype.paginate=function(){if(this.items.length){var L=this;return this.pages=this.items.map(function(M,N){return 0==N%L.config.pagination?L.items.slice(N,N+L.config.pagination):null}).filter(function(M){return M}),this.pages}},K.prototype.setMessage=function(L,M){M&&this.close(),z.addClass(this.container,"notice"),this.notice.textContent=L},K.prototype.removeMessage=function(){z.removeClass(this.container,"notice"),this.notice.innerHTML=""},K.prototype.invert=function(){var L=z.rect(this.selected),M=this.tree.parentNode.offsetHeight,N=window.innerHeight,O=L.top+L.height+M>N;O?(z.addClass(this.container,"inverted"),this.isInverted=!0):(z.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=z.rect(this.tree)},K.prototype.getOptionByIndex=function(L){return this.options[L]},K.prototype.getOptionByValue=function(L){for(var M=!1,N=0,O=this.options.length;N<O;N++)if(this.options[N].value.trim()===L.toString().trim()){M=this.options[N];break}return M},K});
{
"name": "mobius1-selectr",
"version": "2.4.4",
"version": "2.4.5",
"description": "A lightweight, dependency-free, mobile-friendly javascript select box replacement.",

@@ -5,0 +5,0 @@ "main": "dist/selectr.min.js",

@@ -14,3 +14,3 @@ # Selectr

Don't forget to check the [wiki](https://github.com/Mobius1/Selectr/wiki) out and view some [demos](https://s.codepen.io/Mobius1/debug/QgdpLN).
Don't forget to check the [wiki](https://github.com/Mobius1/Selectr/wiki) out and view some [demos](https://s.codepen.io/Mobius1/pen/QgdpLN).

@@ -33,3 +33,3 @@ ---

[Documentation](https://github.com/Mobius1/Selectr/wiki) | [Demo](https://s.codepen.io/Mobius1/debug/QgdpLN)
[Documentation](https://github.com/Mobius1/Selectr/wiki) | [Demo](https://s.codepen.io/Mobius1/pen/QgdpLN)

@@ -36,0 +36,0 @@ ---

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc