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.6 to 2.4.7

2

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

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

/*
Selectr 2.4.6
Selectr 2.4.7
http://mobius.ovh/docs/selectr

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

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