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.5 to 2.4.6

2

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

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

/*
Selectr 2.4.5
Selectr 2.4.6
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),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});
(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<this._events[K].length;L++)this._events[K][L].apply(this,Array.prototype.slice.call(arguments,1))}},s.mixin=function(K){for(var L=["on","off","emit"],M=0;M<L.length;M++)"function"==typeof K?K.prototype[L[M]]=s.prototype[L[M]]:K[L[M]]=s.prototype[L[M]];return K};var u={extend:function(K,L){for(var M in L)if(L.hasOwnProperty(M)){var N=L[M];N&&"[object Object]"===Object.prototype.toString.call(N)?(K[M]=K[M]||{},u.extend(K[M],N)):K[M]=N}return K},each:function(K,L,M){if("[object Object]"===Object.prototype.toString.call(K))for(var N in K)Object.prototype.hasOwnProperty.call(K,N)&&L.call(M,N,K[N],K);else for(var O=0,P=K.length;O<P;O++)L.call(M,O,K[O],K)},createElement:function(K,L){var M=document,N=M.createElement(K);if(L&&"[object Object]"===Object.prototype.toString.call(L)){for(var O in L)if(O in N)N[O]=L[O];else if("html"===O)N.innerHTML=L[O];else if("text"===O){var P=M.createTextNode(L[O]);N.appendChild(P)}else N.setAttribute(O,L[O])}return N},hasClass:function(K,L){if(K)return K.classList?K.classList.contains(L):!!K.className&&!!K.className.match(new RegExp("(\\s|^)"+L+"(\\s|$)"))},addClass:function(K,L){u.hasClass(K,L)||(K.classList?K.classList.add(L):K.className=K.className.trim()+" "+L)},removeClass:function(K,L){u.hasClass(K,L)&&(K.classList?K.classList.remove(L):K.className=K.className.replace(new RegExp("(^|\\s)"+L.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(K,L){return K&&K!==document.body&&(L(K)?K:u.closest(K.parentNode,L))},isInt:function(K){return"number"==typeof K&&isFinite(K)&&Math.floor(K)===K},debounce:function(K,L,M){var N;return function(){var O=this,P=arguments,R=M&&!N;clearTimeout(N),N=setTimeout(function(){N=null,M||K.apply(O,P)},L),R&&K.apply(O,P)}},rect:function(K,L){var M=window,N=K.getBoundingClientRect(),O=L?M.pageXOffset:0,P=L?M.pageYOffset:0;return{bottom:N.bottom+P,height:N.height,left:N.left+O,right:N.right+O,top:N.top+P,width:N.width}},includes:function(K,L){return-1<K.indexOf(L)},startsWith:function(K,L){return K.substr(0,L.length)===L},truncate:function(K){for(;K.firstChild;)K.removeChild(K.firstChild)}},z=function(){if(this.items.length){var K=document.createDocumentFragment();if(this.config.pagination){var L=this.pages.slice(0,this.pageIndex);u.each(L,function(M,N){u.each(N,function(O,P){p(P,K,this.customOption)},this)},this)}else u.each(this.items,function(M,N){p(N,K,this.customOption)},this);K.childElementCount&&(u.removeClass(this.items[this.navIndex],"active"),this.navIndex=(K.querySelector(".selectr-option.selected")||K.querySelector(".selectr-option")).idx,u.addClass(this.items[this.navIndex],"active")),this.tree.appendChild(K)}},A=function(K){var L=K.target;!this.container.contains(L)&&(this.opened||u.hasClass(this.container,"notice"))&&this.close()},B=function(K,L){L=L||K;var M=this.customOption?this.config.renderOption(L):K.textContent,N=u.createElement("li",{class:"selectr-option",html:M,role:"treeitem","aria-selected":!1});return N.idx=K.idx,this.items.push(N),K.defaultSelected&&this.defaultSelected.push(K.idx),K.disabled&&(N.disabled=!0,u.addClass(N,"disabled")),N},C=function(){this.requiresPagination=this.config.pagination&&0<this.config.pagination,n(this.config,"width")&&(u.isInt(this.config.width)?this.width=this.config.width+"px":"auto"===this.config.width?this.width="100%":u.includes(this.config.width,"%")&&(this.width=this.config.width)),this.container=u.createElement("div",{class:"selectr-container"}),this.config.customClass&&u.addClass(this.container,this.config.customClass),this.mobileDevice?u.addClass(this.container,"selectr-mobile"):u.addClass(this.container,"selectr-desktop"),this.el.tabIndex=-1,this.config.nativeDropdown||this.mobileDevice?u.addClass(this.el,"selectr-visible"):u.addClass(this.el,"selectr-hidden"),this.selected=u.createElement("div",{class:"selectr-selected",disabled:this.disabled,tabIndex:0,"aria-expanded":!1}),this.label=u.createElement(this.el.multiple?"ul":"span",{class:"selectr-label"});var K=u.createElement("div",{class:"selectr-options-container"});if(this.tree=u.createElement("ul",{class:"selectr-options",role:"tree","aria-hidden":!0,"aria-expanded":!1}),this.notice=u.createElement("div",{class:"selectr-notice"}),this.el.setAttribute("aria-hidden",!0),this.disabled&&(this.el.disabled=!0),this.el.multiple&&(u.addClass(this.label,"selectr-tags"),u.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=u.createElement("button",{class:"selectr-clear",type:"button"}),this.container.appendChild(this.selectClear),u.addClass(this.container,"clearable")),this.config.taggable){var L=u.createElement("li",{class:"input-tag"});this.input=u.createElement("input",{class:"selectr-tag-input",placeholder:this.config.tagPlaceholder,tagIndex:0,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),L.appendChild(this.input),this.label.appendChild(L),u.addClass(this.container,"taggable"),this.tagSeperators=[","],this.config.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(this.config.tagSeperators))}this.config.searchable&&(this.input=u.createElement("input",{class:"selectr-input",tagIndex:-1,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),this.inputClear=u.createElement("button",{class:"selectr-input-clear",type:"button"}),this.inputContainer=u.createElement("div",{class:"selectr-input-container"}),this.inputContainer.appendChild(this.input),this.inputContainer.appendChild(this.inputClear),K.appendChild(this.inputContainer)),K.appendChild(this.notice),K.appendChild(this.tree),this.items=[],this.options=[],this.el.options.length&&(this.options=[].slice.call(this.el.options));var M=!1,N=0;if(this.el.children.length&&u.each(this.el.children,function(S,T){"OPTGROUP"===T.nodeName?(M=u.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+T.label+"</li>"}),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:"<li class='selectr-optgroup--label'>"+T.text+"</li>"}),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;R<this.items.length;R++)if(Q=this.items[R],!u.hasClass(Q,"disabled")){u.addClass(Q,"active"),this.navIndex=R;break}this.requiresPagination&&(this.pageIndex=1,this.paginate()),this.container.appendChild(this.selected),this.container.appendChild(K),this.placeEl=u.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)},D=function(K){if(K=K||window.event,!this.items.length||!this.opened||!u.includes([13,38,40],K.which))return void(this.navigating=!1);if(K.preventDefault(),13===K.which)return this.config.taggable&&0<this.input.value.length?!1:this.change(this.navIndex);var L,M=this.items[this.navIndex],N=this.navIndex;switch(K.which){case 38:L=0,0<this.navIndex&&this.navIndex--;break;case 40:L=1,this.navIndex<this.items.length-1&&this.navIndex++;}for(this.navigating=!0;u.hasClass(this.items[this.navIndex],"disabled")||u.hasClass(this.items[this.navIndex],"excluded");){if(0<this.navIndex&&this.navIndex<this.items.length-1)L?this.navIndex++:this.navIndex--;else{this.navIndex=N;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 O=u.rect(this.items[this.navIndex]);L?(0===this.navIndex?this.tree.scrollTop=0:O.top+O.height>this.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<this.pages.length){var P=document.createDocumentFragment();u.each(this.pages[this.pageIndex],function(Q,R){p(R,P,this.customOption)},this),K.appendChild(P),this.pageIndex++,this.emit("selectr.paginate",{items:this.items.length,total:this.data.length,page:this.pageIndex,pages:this.pages.length})}},H=function(){(this.config.searchable||this.config.taggable)&&(this.input.value=null,this.searching=!1,this.config.searchable&&u.removeClass(this.inputContainer,"active"),u.hasClass(this.container,"notice")&&(u.removeClass(this.container,"notice"),u.addClass(this.container,"open"),this.input.focus()),u.each(this.items,function(K,L){u.removeClass(L,"excluded"),this.customOption||(L.innerHTML=L.textContent)},this))},I=function(K,L){var M=new RegExp(K,"i").exec(L.textContent);return!!M&&L.textContent.replace(M[0],"<span class='selectr-match'>"+M[0]+"</span>")},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<P.length;T++)S=R.indexOf(P[T]),-1<S?R.splice(S,1):Q.push(P[T]);return[Q,R]};this.el.addEventListener("change",function(){if(K.el.multiple){var P=K.getSelectedProperties("idx"),Q=L(K.selectedIndexes,P);u.each(Q[0],function(R,S){K.select(S)},K),u.each(Q[1],function(R,S){K.deselect(S)},K)}else-1<K.el.selectedIndex&&K.select(K.el.selectedIndex)})}if(this.container.addEventListener("keydown",function(O){"Escape"===O.key&&K.close(),"Enter"===O.key&&K.selected===document.activeElement&&"undefined"!=typeof K.el.form.submit&&K.el.form.submit(),(" "===O.key||"ArrowUp"===O.key||"ArrowDown"===O.key)&&K.selected===document.activeElement&&(setTimeout(function(){K.toggle()},200),K.config.nativeDropdown&&setTimeout(function(){K.el.focus()},200))}),this.selected.addEventListener("click",function(O){K.disabled||K.toggle(),O.preventDefault()}),this.config.nativeKeyboard){var M="";this.selected.addEventListener("keydown",function(O){if(!(K.disabled||K.selected!==document.activeElement||O.altKey||O.ctrlKey||O.metaKey)){if(" "===O.key||!K.opened&&-1<["Enter","ArrowUp","ArrowDown"].indexOf(O.key))return K.toggle(),O.preventDefault(),void O.stopPropagation();if(2>=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,-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),u.each(this.options,function(M,N){N.selected&&N.defaultSelected&&this.select(N.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 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=0<this.options.length?this.options.length-1:0,B.call(this,N),K.selected&&this.select(N.idx),this.setPlaceholder(),N}return this.config.pagination&&this.paginate(),!0}},J.prototype.remove=function(K){var L=[];if(Array.isArray(K)?u.each(K,function(N,O){u.isInt(O)?L.push(this.getOptionByIndex(O)):"string"==typeof K&&L.push(this.getOptionByValue(O))},this):u.isInt(K)?L.push(this.getOptionByIndex(K)):"string"==typeof K&&L.push(this.getOptionByValue(K)),L.length){var M;u.each(L,function(N,O){M=O.idx,this.el.remove(O),this.options.splice(M,1);var P=this.items[M].parentNode;P&&P.removeChild(this.items[M]),this.items.splice(M,1),u.each(this.options,function(Q,R){R.idx=Q,this.items[Q].idx=Q},this)},this),this.setPlaceholder(),this.config.pagination&&this.paginate()}},J.prototype.removeAll=function(){this.clear(!0),u.each(this.el.options,function(K,L){this.el.remove(L)},this),u.truncate(this.tree),this.items=[],this.options=[],this.data=[],this.navIndex=0,this.requiresPagination&&(this.requiresPagination=!1,this.pageIndex=1,this.pages=[]),this.setPlaceholder()},J.prototype.search=function(K,L){if(!this.navigating){var M=!1;K||(K=this.input.value,M=!0,this.removeMessage(),u.truncate(this.tree));var N=[],O=document.createDocumentFragment();if(K=K.trim().toLowerCase(),0<K.length){var P=L?u.startsWith:u.includes;if(u.each(this.options,function(S,T){var U=this.items[T.idx],V=P(T.textContent.trim().toLowerCase(),K);V&&!T.disabled?(N.push({text:T.textContent,value:T.value}),M&&(p(U,O,this.customOption),u.removeClass(U,"excluded"),!this.customOption&&(U.innerHTML=I(K,T)))):M&&u.addClass(U,"excluded")},this),M){if(!O.childElementCount)this.config.taggable||this.setMessage(this.config.messages.noResults);else{var Q=this.items[this.navIndex],R=O.querySelector(".selectr-option:not(.excluded)");u.removeClass(Q,"active"),this.navIndex=R.idx,u.addClass(R,"active")}this.tree.appendChild(O)}}else z.call(this);return N}},J.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())},J.prototype.open=function(){var K=this;return!!this.options.length&&(this.opened||this.emit("selectr.open"),this.opened=!0,this.mobileDevice||this.config.nativeDropdown?(u.addClass(this.container,"native-open"),void(this.config.data&&u.each(this.options,function(L,M){this.el.add(M)},this))):void(u.addClass(this.container,"open"),z.call(this),this.invert(),this.tree.scrollTop=0,u.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(){K.input.focus(),K.input.tabIndex=0},10)))},J.prototype.close=function(){if(this.opened&&this.emit("selectr.close"),this.opened=!1,this.navigating=!1,this.mobileDevice||this.config.nativeDropdown)return void u.removeClass(this.container,"native-open");var K=u.hasClass(this.container,"notice");this.config.searchable&&!K&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),K&&(u.removeClass(this.container,"notice"),this.notice.textContent=""),u.removeClass(this.container,"open"),u.removeClass(this.container,"native-open"),this.selected.setAttribute("aria-expanded",!1),this.tree.setAttribute("aria-hidden",!0),this.tree.setAttribute("aria-expanded",!1),u.truncate(this.tree),H.call(this),this.selected.focus()},J.prototype.enable=function(){this.disabled=!1,this.el.disabled=!1,this.selected.tabIndex=this.originalIndex,this.el.multiple&&u.each(this.tags,function(K,L){L.lastElementChild.tabIndex=0}),u.removeClass(this.container,"selectr-disabled")},J.prototype.disable=function(K){K||(this.el.disabled=!0),this.selected.tabIndex=-1,this.el.multiple&&u.each(this.tags,function(L,M){M.lastElementChild.tabIndex=-1}),this.disabled=!0,u.addClass(this.container,"selectr-disabled")},J.prototype.reset=function(){this.disabled||(this.clear(),this.setSelected(!0),u.each(this.defaultSelected,function(K,L){this.select(L)},this),this.emit("selectr.reset"))},J.prototype.clear=function(K){if(!this.el.multiple)-1<this.selectedIndex&&this.deselect(this.selectedIndex,K);else if(this.selectedIndexes.length){var L=this.selectedIndexes.slice();u.each(L,function(M,N){this.deselect(N)},this)}this.emit("selectr.clear")},J.prototype.serialise=function(K){var L=[];return u.each(this.options,function(M,N){var O={value:N.value,text:N.textContent};N.selected&&(O.selected=!0),N.disabled&&(O.disabled=!0),L[M]=O}),K?JSON.stringify(L):L},J.prototype.serialize=function(K){return this.serialise(K)},J.prototype.setPlaceholder=function(K){K=K||this.config.placeholder||this.el.getAttribute("placeholder"),this.options.length||(K="No options available"),this.placeEl.innerHTML=K},J.prototype.paginate=function(){if(this.items.length){var K=this;return this.pages=this.items.map(function(L,M){return 0==M%K.config.pagination?K.items.slice(M,M+K.config.pagination):null}).filter(function(L){return L}),this.pages}},J.prototype.setMessage=function(K,L){L&&this.close(),u.addClass(this.container,"notice"),this.notice.textContent=K},J.prototype.removeMessage=function(){u.removeClass(this.container,"notice"),this.notice.innerHTML=""},J.prototype.invert=function(){var K=u.rect(this.selected),L=this.tree.parentNode.offsetHeight,M=window.innerHeight,N=K.top+K.height+L>M;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<N;M++)if(this.options[M].value.trim()===K.toString().trim()){L=this.options[M];break}return L},J});
{
"name": "mobius1-selectr",
"version": "2.4.5",
"version": "2.4.6",
"description": "A lightweight, dependency-free, mobile-friendly javascript select box replacement.",

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

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