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.2.0 to 2.2.1

2

bower.json
{
"name": "mobius1-selectr",
"version": "2.2.0",
"version": "2.2.1",
"ignore": [

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

/*!
* Selectr 2.2.0
* Selectr 2.2.1
* http://mobius.ovh/docs/selectr

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

*/
!function(e,t){"function"==typeof define&&define.amd?define([],t("Selectr")):"object"==typeof exports?module.exports=t("Selectr"):e.Selectr=t("Selectr")}(this,function(e){"use strict";var t={width:"auto",disabled:!1,searchable:!0,clearable:!1,sortSelected:!1,allowDeselect:!1,closeOnScroll:!1,nativeDropdown:!1,placeholder:"Select an option...",taggable:!1,tagPlaceholder:"Enter a tag..."},i=function(){};i.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){this._events=this._events||{},e in this._events!=!1&&this._events[e].splice(this._events[e].indexOf(t),1)},emit:function(e){if(this._events=this._events||{},e in this._events!=!1)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}},i.mixin=function(e){for(var t=["on","off","emit"],s=0;s<t.length;s++)"function"==typeof e?e.prototype[t[s]]=i.prototype[t[s]]:e[t[s]]=i.prototype[t[s]];return e};var s={extend:function(e,t){t=t||{};var i;for(i in e)e.hasOwnProperty(i)&&(t.hasOwnProperty(i)||(t[i]=e[i]));return t},each:function(e,t,i){if("[object Object]"===Object.prototype.toString.call(e))for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(i,s,e[s],e);else for(var n=0,a=e.length;n<a;n++)t.call(i,n,e[n],e)},createElement:function(e,t){var i=document,n=i.createElement(e);if(t&&s.isObject(t)){var a;for(a in t)if(a in n)n[a]=t[a];else if("html"===a)n.innerHTML=t[a];else if("text"===a){var l=i.createTextNode(t[a]);n.appendChild(l)}else n.setAttribute(a,t[a])}return n},hasClass:function(e,t){return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){s.hasClass(e,t)||(e.classList?e.classList.add(t):e.className=e.className.trim()+" "+t)},removeClass:function(e,t){s.hasClass(e,t)&&(e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(e,t){return e&&e!==document.body&&(t(e)?e:s.closest(e.parentNode,t))},on:function(e,t,i,s){e.addEventListener(t,function(e){s=s||this,i.call(s,e)},!1)},off:function(e,t,i){e.removeEventListener(t,i)},isObject:function(e){return"[object Object]"===Object.prototype.toString.call(e)},isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},isInt:function(e){return!isNaN(e)&&function(e){return(e||0)===e}(parseFloat(e))},debounce:function(e,t,i){var s;return function(){var n=this,a=arguments,l=function(){s=null,i||e.apply(n,a)},o=i&&!s;clearTimeout(s),s=setTimeout(l,t),o&&e.apply(n,a)}},getRect:function(e,t){var i=window,s=e.getBoundingClientRect(),n=t?i.pageXOffset:0,a=t?i.pageYOffset:0;return{bottom:s.bottom+a,height:s.height,left:s.left+n,right:s.right+n,top:s.top+a,width:s.width}},preventDefault:function(e){if((e=e||window.event).preventDefault)return e.preventDefault()},includes:function(e,t){return e.indexOf(t)>-1}},n=function(e){var t=!1;if(e&&"string"==typeof e){var i=document;switch(e.charAt(0)){case".":t=i.getElementsByClassName(e.substr(1))[0];break;case"#":t=i.getElementById(e.substr(1));break;default:t=i.getElementsByTagName(e)[0]}}return t},a=function(e,t){return e.hasOwnProperty(t)&&(!0===e[t]||e[t].length)},l=function(e){this.el.multiple||(this.config.data&&this.el.selectedIndex<0&&m.call(this,this.items[0]),this.el.selectedIndex>-1&&m.call(this,this.items[this.el.selectedIndex])),this.config.selectedValue&&this.setValue(this.config.selectedValue),e&&this.config.data&&s.each(this.config.data,function(e,t){s.each(this.options,function(e,i){i.value===t.value&&a(t,"selected")&&(i.selected=!0,i.setAttribute("selected",""))},this)},this)},o=function(){var e=s.getRect(this.selected),t=this.tree.parentNode.offsetHeight,i=window.innerHeight;e.top+e.height+t>i?(s.addClass(this.container,"inverted"),this.isInverted=!0):(s.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=s.getRect(this.tree)},h=function(){if(this.items.length){var e=document.createDocumentFragment();if(this.config.pagination){var t=this.pages.slice(0,this.pageIndex);s.each(t,function(t,i){s.each(i,function(t,i){i.parentNode?i.parentNode.parentNode||e.appendChild(i.parentNode):e.appendChild(i),s.removeClass(i,"excluded"),this.customOption||(i.innerHTML=i.textContent)},this)},this)}else s.each(this.items,function(t,i){i.parentNode?i.parentNode.parentNode||e.appendChild(i.parentNode):e.appendChild(i),s.removeClass(i,"excluded"),this.customOption||(i.innerHTML=i.textContent)},this);this.tree.appendChild(e)}},c=function(){for(;this.tree.firstChild;)this.tree.removeChild(this.tree.firstChild)},r=function(e){var t=e.target;this.container.contains(t)||!this.opened&&!this.container.classList.contains("notice")||this.close()},d=function(){if(this.requiresPagination=this.config.pagination&&this.config.pagination>0,a(this.config,"width")){var e=0;s.isInt(this.config.width)?e=this.config.width+"px":"auto"===this.config.width?e="100%":s.includes(this.config.width,"%")&&(e=this.config.width),this.width=e}this.container=s.createElement("div",{class:"selectr-container"}),this.config.customClass&&s.addClass(this.container,this.config.customClass),this.mobileDevice&&s.addClass(this.container,"selectr-mobile"),this.el.tabIndex=-1,this.config.nativeDropdown||this.mobileDevice?this.el.classList.add("selectr-visible"):this.el.classList.add("selectr-hidden"),this.selected=s.createElement("div",{class:"selectr-selected",disabled:this.disabled,tabIndex:this.el.tabIndex,"aria-expanded":!1}),this.label=s.createElement(this.el.multiple?"ul":"span",{class:"selectr-label"});var t=s.createElement("div",{class:"selectr-options-container"});if(this.tree=s.createElement("ul",{class:"selectr-options",role:"tree","aria-hidden":!0,"aria-expanded":!1}),this.notice=s.createElement("div",{class:"selectr-notice"}),this.el.setAttribute("aria-hidden",!0),this.disabled&&(this.el.disabled=!0),this.el.multiple&&(s.addClass(this.label,"selectr-tags"),s.addClass(this.container,"multiple"),this.tags=[],this.selectedValues=[],this.selectedIndexes=[]),this.selected.appendChild(this.label),(this.el.multiple&&this.config.clearable||!this.el.multiple&&this.config.allowDeselect)&&(this.selectClear=s.createElement("button",{class:"selectr-clear",type:"button"}),this.container.appendChild(this.selectClear),s.addClass(this.container,"clearable")),this.config.taggable){var i=s.createElement("li",{class:"input-tag"});this.input=s.createElement("input",{class:"selectr-tag-input",placeholder:this.config.tagPlaceholder,tagIndex:0,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),i.appendChild(this.input),this.label.appendChild(i),s.addClass(this.container,"taggable"),this.tagSeperators=[","],this.config.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(this.config.tagSeperators))}this.config.searchable&&(this.input=s.createElement("input",{class:"selectr-input",tagIndex:-1,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),this.inputClear=s.createElement("button",{class:"selectr-input-clear",type:"button"}),this.inputContainer=s.createElement("div",{class:"selectr-input-container"}),this.inputContainer.appendChild(this.input),this.inputContainer.appendChild(this.inputClear),t.appendChild(this.inputContainer)),t.appendChild(this.notice),t.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&&s.each(this.el.children,function(e,t){"OPTGROUP"===t.nodeName?(n=s.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+t.label+"</li>"}),s.each(t.children,function(e,t){t.idx=o,n.appendChild(u.call(this,t,n)),o++},this)):(t.idx=o,u.call(this,t),o++)},this),this.config.data&&s.isArray(this.config.data)){this.data=[];var h,c=!1;n=!1,o=0,s.each(this.config.data,function(e,t){a(t,"children")?(c=s.createElement("optgroup",{label:t.text}),n=s.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+t.text+"</li>"}),s.each(t.children,function(e,t){(h=new Option(t.text,t.value,!1,a(t,"selected"))).disabled=a(t,"disabled"),this.options.push(h),c.appendChild(h),h.idx=o,n.appendChild(u.call(this,h,t)),this.data[o]=t,o++},this)):((h=new Option(t.text,t.value,!1,a(t,"selected"))).disabled=a(t,"disabled"),this.options.push(h),h.idx=o,u.call(this,h,t),this.data[o]=t,o++)},this)}l.call(this,!0);var r;this.navIndex=0;for(var d=0;d<this.items.length;d++)if(r=this.items[d],!s.hasClass(r,"disabled")){s.addClass(r,"active"),this.navIndex=d;break}if(this.requiresPagination){var f=this;this.pageIndex=1,this.pages=this.items.map(function(e,t){return t%f.config.pagination==0?f.items.slice(t,t+f.config.pagination):null}).filter(function(e){return e})}this.container.appendChild(this.selected),this.container.appendChild(t),this.placeEl=s.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),p.call(this)},p=function(){var e=this;this.events={},this.events.dismiss=r.bind(this),this.events.navigate=f.bind(this),this.events.reset=this.reset.bind(this),(this.config.nativeDropdown||this.mobileDevice)&&(this.ctrlDown=!1,this.mobileDevice?s.on(this.el,"change",function(e){if(this.el.multiple){var t=[];s.each(this.options,function(e,i){i.selected&&t.push(i.idx),v.call(this,this.items[i.idx])},this),s.each(t,function(e,t){m.call(this,this.items[t])},this)}},this):(s.on(document,"keydown",function(e){this.ctrlDown="Control"===e.key},this),s.on(document,"keyup",function(e){this.ctrlDown=!1},this),s.on(this.el,"click",function(e){this.el.multiple&&"OPTION"===e.target.nodeName&&(this.ctrlDown||this.clear(),console.log(e.target,e.target.idx,this.items[e.target.idx]),g.call(this,this.items[e.target.idx]),e.preventDefault())},this)),s.on(this.el,"change",function(e){this.el.multiple||this.el.selectedIndex>-1&&m.call(this,this.items[this.el.selectedIndex])},this)),s.on(this.container,"click",function(e){e.target===this.el&&this.toggle()},this),s.on(this.selected,"click",function(e){this.disabled||this.toggle(),s.preventDefault(e)},this),s.on(this.label,"click",function(e){var t=e.target;s.hasClass(t,"selectr-tag-remove")&&v.call(this,this.items[t.parentNode.idx])},this),(this.el.multiple&&this.config.clearable||!this.el.multiple&&this.config.allowDeselect)&&s.on(this.selectClear,"click",this.clear.bind(this)),s.on(this.tree,"mousedown",function(e){s.preventDefault(e)}),s.on(this.tree,"click",function(e){var t=s.closest(e.target,function(e){return e&&s.hasClass(e,"selectr-option")});t&&(s.hasClass(t,"disabled")||(s.hasClass(t,"selected")?v.call(this,t):m.call(this,t),this.opened&&!this.el.multiple&&this.close()))},this),s.on(document,"click",this.events.dismiss),s.on(document,"keydown",this.events.navigate),s.on(this.tree,"mouseover",function(e){var t=e.target;t.classList.contains("selectr-option")&&(t.classList.contains("disabled")||(this.items[this.navIndex].classList.remove("active"),t.classList.add("active"),this.navIndex=[].slice.call(this.items).indexOf(t)))},this),this.config.searchable&&(s.on(this.input,"keyup",function(e){this.search(),this.config.taggable||(this.input.value.length?s.addClass(this.input.parentNode,"active"):s.removeClass(this.input.parentNode,"active"))},this),s.on(this.inputClear,"click",function(e){this.input.value=null,y.call(this),this.tree.childElementCount||h.call(this)},this)),this.config.taggable&&s.on(this.input,"keyup",function(e){if(this.search(),this.config.taggable&&this.input.value.length){var t=this.input.value.trim();(13===e.which||s.includes(this.tagSeperators,e.key))&&(s.each(this.tagSeperators,function(e,i){t=t.replace(i,"")}),this.addOption({value:t,text:t,selected:!0},!0)?(this.close(),y.call(this)):(this.input.value="",this.setMessage("That tag is already in use.")))}},this),this.update=s.debounce(function(){e.opened&&e.config.closeOnScroll&&e.close(),e.width&&(e.container.style.width=e.width),o.call(e)},50),s.on(window,"resize",this.update),s.on(window,"scroll",this.update),this.requiresPagination&&(this.paginateItems=s.debounce(function(){C.call(this)},50),s.on(this.tree,"scroll",this.paginateItems.bind(this))),this.el.form&&s.on(this.el.form,"reset",this.events.reset)},u=function(e,t){t=t||e;var i=this.customOption?this.config.renderOption(t):e.textContent,n=s.createElement("li",{class:"selectr-option",html:i,role:"treeitem","aria-selected":!1});return n.idx=e.idx,this.items.push(n),e.selected&&e.defaultSelected&&s.addClass(n,"selected"),e.disabled&&(n.disabled=!0,s.addClass(n,"disabled")),n},f=function(e){var t=(e=e||window.event).which,i=[13,38,40];if(this.items.length&&this.opened&&s.includes(i,t))if(s.preventDefault(e),13!==t){var n,a=this.items[this.navIndex];switch(t){case 38:n=0,this.navIndex>0&&this.navIndex--;break;case 40:n=1,this.navIndex<this.items.length-1&&this.navIndex++}if(this.navigating=!0,this.items[this.navIndex].classList.contains("disabled")||this.items[this.navIndex].classList.contains("excluded"))for(;this.items[this.navIndex].classList.contains("disabled")||this.items[this.navIndex].classList.contains("excluded");)n?this.navIndex++:this.navIndex--;var l,o,h=this.items[this.navIndex],c=s.getRect(this.items[this.navIndex]),r=this.tree.scrollTop,d=this.optsRect.top;if(n){var p=c.top+c.height;o=r+(p-(l=d+this.optsRect.height)),0===this.navIndex?this.tree.scrollTop=0:p>l&&(this.tree.scrollTop=o),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&C.call(this)}else{var u=c.top;o=r+(u-(l=d)),0===this.navIndex?this.tree.scrollTop=0:u-l<0&&(this.tree.scrollTop=o)}a&&s.removeClass(a,"active"),s.addClass(h,"active")}else g.call(this,this.items[this.navIndex])},g=function(e){this.options[e.idx].disabled||(s.hasClass(e,"selected")?v.call(this,e):m.call(this,e),this.opened&&!this.el.multiple&&this.close())},m=function(e){var t=[].slice.call(this.el.options),i=this.options[e.idx];if(this.el.multiple){if(s.includes(this.selectedIndexes,e.idx))return!1;var n=this.config.maxSelections;if(n&&this.tags.length==n)return this.setMessage("A maximum of "+n+" items can be selected.",!0),!1;this.selectedValues.push(i.value),this.selectedIndexes.push(e.idx),b.call(this,e)}else{var a=this.data?this.data[e.idx]:i;this.label.innerHTML=this.customSelected?this.config.renderSelection(a):i.textContent,this.selectedValue=i.value,this.selectedIndex=e.idx,s.each(this.options,function(t,i){var n=this.items[t];t!==e.idx&&(n&&s.removeClass(n,"selected"),i.selected=!1,i.removeAttribute("selected"))},this)}s.includes(t,i)||this.el.add(i),e.setAttribute("aria-selected",!0),s.addClass(e,"selected"),s.addClass(this.container,"has-selected"),i.selected=!0,i.setAttribute("selected",""),this.emit("selectr.select",i),this.emit("selectr.change",i)},v=function(e){var t=this.options[e.idx];if(this.el.multiple){var i=this.selectedIndexes.indexOf(e.idx);this.selectedIndexes.splice(i,1);var n=this.selectedValues.indexOf(t.value);this.selectedValues.splice(n,1),x.call(this,e),this.tags.length||s.removeClass(this.container,"has-selected")}else{if(!this.config.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=-1,s.removeClass(this.container,"has-selected")}this.items[e.idx].setAttribute("aria-selected",!1),s.removeClass(this.items[e.idx],"selected"),t.selected=!1,t.removeAttribute("selected"),this.emit("selectr.deselect",t),this.emit("selectr.change",t)},b=function(e){var t=this,i=document.createDocumentFragment(),n=this.options[e.idx],a=this.data?this.data[e.idx]:n,l=this.customSelected?this.config.renderSelection(a):n.textContent,o=s.createElement("li",{class:"selectr-tag",html:l}),h=s.createElement("button",{class:"selectr-tag-remove",type:"button"});if(o.appendChild(h),o.idx=e.idx,o.tag=n.value,this.tags.push(o),this.config.sortSelected){var c=this.tags.slice();c.sort(function(e,i){var s,n,a=[],l=[];for(!0===t.config.sortSelected?(s=e.tag,n=i.tag):"text"===t.config.sortSelected&&(s=e.textContent,n=i.textContent),s.replace(/(\d+)|(\D+)/g,function(e,t,i){a.push([t||1/0,i||""])}),n.replace(/(\d+)|(\D+)/g,function(e,t,i){l.push([t||1/0,i||""])});a.length&&l.length;){var o=a.shift(),h=l.shift(),c=o[0]-h[0]||o[1].localeCompare(h[1]);if(c)return c}return a.length-l.length}),s.each(c,function(e,t){i.appendChild(t)}),this.label.innerHTML=""}else i.appendChild(o);this.config.taggable?this.label.insertBefore(i,this.input.parentNode):this.label.appendChild(i)},x=function(e){var t=!1;s.each(this.tags,function(i,s){s.idx===e.idx&&(t=s)},this),t&&(this.label.removeChild(t),this.tags.splice(this.tags.indexOf(t),1))},C=function(){var e=this.tree;if(e.scrollTop>=e.scrollHeight-e.offsetHeight&&this.pageIndex<this.pages.length){var t=document.createDocumentFragment();s.each(this.pages[this.pageIndex],function(e,i){i.parentNode?i.parentNode.parentNode||t.appendChild(i.parentNode):t.appendChild(i)},this),e.appendChild(t),this.pageIndex++,this.emit("selectr.paginate",{items:this.items.length,total:this.data.length,page:this.pageIndex,pages:this.pages.length})}},y=function(){(this.config.searchable||this.config.taggable)&&(this.input.value=null,this.searching=!1,this.config.searchable&&s.removeClass(this.inputContainer,"active"),s.hasClass(this.container,"notice")&&(s.removeClass(this.container,"notice"),s.addClass(this.container,"open"),this.input.focus()),s.each(this.items,function(e,t){s.removeClass(t,"excluded"),this.customOption||(t.innerHTML=t.textContent)},this))},w=function(e,t){var i=new RegExp(e,"i").exec(t.textContent);return!!i&&t.textContent.replace(i[0],"<span class='selectr-match'>"+i[0]+"</span>")},I=function(e,t){if(t=t||{},!e)throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");if(this.el=e,"string"==typeof e&&(this.el=n(e)),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(t)};return I.prototype.render=function(e){if(!this.rendered){this.config=s.extend(t,e),this.originalType=this.el.type,this.originalIndex=this.el.tabIndex,this.originalOptionCount=this.el.options.length,(this.config.multiple||this.config.taggable)&&(this.el.multiple=!0),this.disabled=a(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,i.mixin(this),d.call(this),this.update(),this.optsRect=s.getRect(this.tree),this.rendered=!0;var n=this;setTimeout(function(){n.emit("selectr.init")},20)}},I.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),s.removeClass(this.el,"selectr-hidden"),this.el.form&&s.off(this.el.form,"reset",this.events.reset),s.off(document,"click",this.events.dismiss),s.off(document,"keydown",this.events.navigate),s.off(window,"resize",this.update),s.off(window,"scroll",this.update),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1)},I.prototype.setValue=function(e){var t=s.isArray(e);if(t||(e=e.toString().trim()),!this.el.multiple&&t)return!1;s.each(this.options,function(i,n){(t&&s.includes(e.toString(),n.value)||n.value===e)&&g.call(this,this.items[n.idx])},this)},I.prototype.getValue=function(e,t){var i;if(this.el.multiple)e?this.selectedIndexes.length&&((i={}).values=[],s.each(this.selectedIndexes,function(e,t){var s=this.options[t];i.values[e]={value:s.value,text:s.textContent}},this)):i=this.selectedValues.slice();else if(e){var n=this.options[this.selectedIndex];i={value:n.value,text:n.textContent}}else i=this.selectedValue;return e&&t&&(i=JSON.stringify(i)),i},I.prototype.addOption=function(e,t){if(e){if(s.isArray(e))s.each(e,function(e,t){this.addOption(t)},this);else if(s.isObject(e)){if(t){var i=!1;if(s.each(this.options,function(t,s){s.value.toLowerCase()===e.value.toLowerCase()&&(i=!0)}),i)return!1}var n=s.createElement("option",e);this.data&&this.data.push(e),this.options.push(n),n.idx=this.options.length-1;var a=u.call(this,n);return e.selected&&m.call(this,a),n}if(this.setPlaceholder(),this.requiresPagination){var l=this;this.pages=this.items.map(function(e,t){return t%l.config.pagination==0?l.items.slice(t,t+l.config.pagination):null}).filter(function(e){return e})}return!0}},I.prototype.search=function(e){e=e||this.input.value;var t=document.createDocumentFragment();this.removeMessage(),c.call(this),e.length>1?(s.each(this.options,function(i,n){var a=this.items[n.idx];s.includes(n.textContent.toLowerCase(),e.toLowerCase())&&!n.disabled?(a.parentNode?a.parentNode.parentNode||t.appendChild(a.parentNode):t.appendChild(a),s.removeClass(a,"excluded"),this.customOption||(a.innerHTML=w(e,n))):s.addClass(a,"excluded")},this),t.childElementCount||this.setMessage("no results.")):h.call(this),this.tree.appendChild(t)},I.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())},I.prototype.open=function(){var e=this;if(this.opened||this.emit("selectr.open"),this.opened=!0,this.mobileDevice||this.config.nativeDropdown)return s.addClass(this.container,"native-open"),void(this.config.data&&s.each(this.options,function(e,t){this.el.add(t)},this));s.addClass(this.container,"open"),h.call(this),o.call(this),this.tree.scrollHeight<=this.optsRect.height&&this.requiresPagination&&C.call(this),s.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(){e.input.focus(),e.input.tabIndex=0},10)},I.prototype.close=function(){if(this.opened&&this.emit("selectr.close"),this.opened=!1,this.mobileDevice||this.config.nativeDropdown)s.removeClass(this.container,"native-open");else{var e=s.hasClass(this.container,"notice");this.config.searchable&&!e&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),e&&(s.removeClass(this.container,"notice"),this.notice.textContent=""),s.removeClass(this.container,"open"),s.removeClass(this.container,"native-open"),this.selected.setAttribute("aria-expanded",!1),this.tree.setAttribute("aria-hidden",!0),this.tree.setAttribute("aria-expanded",!1),c.call(this),y.call(this)}},I.prototype.enable=function(){this.disabled=!1,this.el.disabled=!1,this.selected.tabIndex=this.originalIndex,s.each(this.tags,function(e,t){t.lastElementChild.tabIndex=0}),s.removeClass(this.container,"selectr-disabled")},I.prototype.disable=function(e){e||(this.el.disabled=!0),this.selected.tabIndex=-1,s.each(this.tags,function(e,t){t.lastElementChild.tabIndex=-1}),this.disabled=!0,s.addClass(this.container,"selectr-disabled")},I.prototype.reset=function(){this.disabled||(this.clear(),l.call(this,!0),s.each(this.el.options,function(e,t){t.selected&&m.call(this,this.items[t.idx])},this),this.emit("selectr.reset"))},I.prototype.clear=function(){if(this.el.multiple){var e=this.selectedIndexes.slice();s.each(e,function(e,t){v.call(this,this.items[t])},this)}else v.call(this,this.items[this.el.selectedIndex]);this.emit("selectr.clear")},I.prototype.serialise=function(e){var t=[];return s.each(this.options,function(e,i){var s={value:i.value,text:i.textContent};i.selected&&(s.selected=!0),i.disabled&&(s.disabled=!0),t[e]=s}),e?JSON.stringify(t):t},I.prototype.serialize=function(e){return this.serialise(e)},I.prototype.setPlaceholder=function(e){e=e||this.config.placeholder||this.el.getAttribute("placeholder"),this.options.length||(e="No options available"),this.placeEl.innerHTML=e},I.prototype.setMessage=function(e,t){t&&this.close(),s.addClass(this.container,"notice"),this.notice.textContent=e},I.prototype.removeMessage=function(){s.removeClass(this.container,"notice"),this.notice.innerHTML=""},I});
!function(e,t){"function"==typeof define&&define.amd?define([],t("Selectr")):"object"==typeof exports?module.exports=t("Selectr"):e.Selectr=t("Selectr")}(this,function(e){"use strict";var t={width:"auto",disabled:!1,searchable:!0,clearable:!1,sortSelected:!1,allowDeselect:!1,closeOnScroll:!1,nativeDropdown:!1,placeholder:"Select an option...",taggable:!1,tagPlaceholder:"Enter a tag..."},i=function(){};i.prototype={on:function(e,t){this._events=this._events||{},this._events[e]=this._events[e]||[],this._events[e].push(t)},off:function(e,t){this._events=this._events||{},e in this._events!=!1&&this._events[e].splice(this._events[e].indexOf(t),1)},emit:function(e){if(this._events=this._events||{},e in this._events!=!1)for(var t=0;t<this._events[e].length;t++)this._events[e][t].apply(this,Array.prototype.slice.call(arguments,1))}},i.mixin=function(e){for(var t=["on","off","emit"],s=0;s<t.length;s++)"function"==typeof e?e.prototype[t[s]]=i.prototype[t[s]]:e[t[s]]=i.prototype[t[s]];return e};var s={extend:function(e,t){t=t||{};var i;for(i in e)e.hasOwnProperty(i)&&(t.hasOwnProperty(i)||(t[i]=e[i]));return t},each:function(e,t,i){if("[object Object]"===Object.prototype.toString.call(e))for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(i,s,e[s],e);else for(var n=0,a=e.length;n<a;n++)t.call(i,n,e[n],e)},createElement:function(e,t){var i=document,n=i.createElement(e);if(t&&s.isObject(t)){var a;for(a in t)if(a in n)n[a]=t[a];else if("html"===a)n.innerHTML=t[a];else if("text"===a){var l=i.createTextNode(t[a]);n.appendChild(l)}else n.setAttribute(a,t[a])}return n},hasClass:function(e,t){return e.classList?e.classList.contains(t):!!e.className&&!!e.className.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))},addClass:function(e,t){s.hasClass(e,t)||(e.classList?e.classList.add(t):e.className=e.className.trim()+" "+t)},removeClass:function(e,t){s.hasClass(e,t)&&(e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp("(^|\\s)"+t.split(" ").join("|")+"(\\s|$)","gi")," "))},closest:function(e,t){return e&&e!==document.body&&(t(e)?e:s.closest(e.parentNode,t))},on:function(e,t,i,s){e.addEventListener(t,function(e){s=s||this,i.call(s,e)},!1)},off:function(e,t,i){e.removeEventListener(t,i)},isObject:function(e){return"[object Object]"===Object.prototype.toString.call(e)},isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},isInt:function(e){return!isNaN(e)&&function(e){return(e||0)===e}(parseFloat(e))},debounce:function(e,t,i){var s;return function(){var n=this,a=arguments,l=function(){s=null,i||e.apply(n,a)},o=i&&!s;clearTimeout(s),s=setTimeout(l,t),o&&e.apply(n,a)}},getRect:function(e,t){var i=window,s=e.getBoundingClientRect(),n=t?i.pageXOffset:0,a=t?i.pageYOffset:0;return{bottom:s.bottom+a,height:s.height,left:s.left+n,right:s.right+n,top:s.top+a,width:s.width}},preventDefault:function(e){if((e=e||window.event).preventDefault)return e.preventDefault()},includes:function(e,t){return e.indexOf(t)>-1}},n=function(e){var t=!1;if(e&&"string"==typeof e){var i=document;switch(e.charAt(0)){case".":t=i.getElementsByClassName(e.substr(1))[0];break;case"#":t=i.getElementById(e.substr(1));break;default:t=i.getElementsByTagName(e)[0]}}return t},a=function(e,t){return e.hasOwnProperty(t)&&(!0===e[t]||e[t].length)},l=function(e){return e.hasOwnProperty("selected")&&!0===e.selected},o=function(e){this.el.multiple||(this.config.data&&this.el.selectedIndex<0&&v.call(this,this.items[0]),this.el.selectedIndex>-1&&v.call(this,this.items[this.el.selectedIndex])),this.config.selectedValue&&this.setValue(this.config.selectedValue),this.config.data&&s.each(this.config.data,function(e,t){s.each(this.options,function(e,i){i.value===t.value&&l(t)&&v.call(this,this.items[i.idx])},this)},this)},h=function(){var e=s.getRect(this.selected),t=this.tree.parentNode.offsetHeight,i=window.innerHeight;e.top+e.height+t>i?(s.addClass(this.container,"inverted"),this.isInverted=!0):(s.removeClass(this.container,"inverted"),this.isInverted=!1),this.optsRect=s.getRect(this.tree)},c=function(){if(this.items.length){var e=document.createDocumentFragment();if(this.config.pagination){var t=this.pages.slice(0,this.pageIndex);s.each(t,function(t,i){s.each(i,function(t,i){i.parentNode?i.parentNode.parentNode||e.appendChild(i.parentNode):e.appendChild(i),s.removeClass(i,"excluded"),this.customOption||(i.innerHTML=i.textContent)},this)},this)}else s.each(this.items,function(t,i){i.parentNode?i.parentNode.parentNode||e.appendChild(i.parentNode):e.appendChild(i),s.removeClass(i,"excluded"),this.customOption||(i.innerHTML=i.textContent)},this);this.tree.appendChild(e)}},r=function(){for(;this.tree.firstChild;)this.tree.removeChild(this.tree.firstChild)},d=function(e){var t=e.target;this.container.contains(t)||!this.opened&&!this.container.classList.contains("notice")||this.close()},p=function(){if(this.requiresPagination=this.config.pagination&&this.config.pagination>0,a(this.config,"width")){var e=0;s.isInt(this.config.width)?e=this.config.width+"px":"auto"===this.config.width?e="100%":s.includes(this.config.width,"%")&&(e=this.config.width),this.width=e}this.container=s.createElement("div",{class:"selectr-container"}),this.config.customClass&&s.addClass(this.container,this.config.customClass),this.mobileDevice&&s.addClass(this.container,"selectr-mobile"),this.el.tabIndex=-1,this.config.nativeDropdown||this.mobileDevice?this.el.classList.add("selectr-visible"):this.el.classList.add("selectr-hidden"),this.selected=s.createElement("div",{class:"selectr-selected",disabled:this.disabled,tabIndex:this.el.tabIndex,"aria-expanded":!1}),this.label=s.createElement(this.el.multiple?"ul":"span",{class:"selectr-label"});var t=s.createElement("div",{class:"selectr-options-container"});if(this.tree=s.createElement("ul",{class:"selectr-options",role:"tree","aria-hidden":!0,"aria-expanded":!1}),this.notice=s.createElement("div",{class:"selectr-notice"}),this.el.setAttribute("aria-hidden",!0),this.disabled&&(this.el.disabled=!0),this.el.multiple&&(s.addClass(this.label,"selectr-tags"),s.addClass(this.container,"multiple"),this.tags=[],this.selectedValues=[],this.selectedIndexes=[]),this.selected.appendChild(this.label),(this.el.multiple&&this.config.clearable||!this.el.multiple&&this.config.allowDeselect)&&(this.selectClear=s.createElement("button",{class:"selectr-clear",type:"button"}),this.container.appendChild(this.selectClear),s.addClass(this.container,"clearable")),this.config.taggable){var i=s.createElement("li",{class:"input-tag"});this.input=s.createElement("input",{class:"selectr-tag-input",placeholder:this.config.tagPlaceholder,tagIndex:0,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),i.appendChild(this.input),this.label.appendChild(i),s.addClass(this.container,"taggable"),this.tagSeperators=[","],this.config.tagSeperators&&(this.tagSeperators=this.tagSeperators.concat(this.config.tagSeperators))}this.config.searchable&&(this.input=s.createElement("input",{class:"selectr-input",tagIndex:-1,autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",role:"textbox",type:"search"}),this.inputClear=s.createElement("button",{class:"selectr-input-clear",type:"button"}),this.inputContainer=s.createElement("div",{class:"selectr-input-container"}),this.inputContainer.appendChild(this.input),this.inputContainer.appendChild(this.inputClear),t.appendChild(this.inputContainer)),t.appendChild(this.notice),t.appendChild(this.tree),this.items=[],this.options=[],this.el.options.length&&(this.options=[].slice.call(this.el.options));var n=!1,h=0;if(this.el.children.length&&s.each(this.el.children,function(e,t){"OPTGROUP"===t.nodeName?(n=s.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+t.label+"</li>"}),s.each(t.children,function(e,t){t.idx=h,n.appendChild(f.call(this,t,n)),h++},this)):(t.idx=h,f.call(this,t),h++)},this),this.config.data&&s.isArray(this.config.data)){this.data=[];var c,r=!1;n=!1,h=0,s.each(this.config.data,function(e,t){a(t,"children")?(r=s.createElement("optgroup",{label:t.text}),n=s.createElement("ul",{class:"selectr-optgroup",role:"group",html:"<li class='selectr-optgroup--label'>"+t.text+"</li>"}),s.each(t.children,function(e,t){(c=new Option(t.text,t.value,!1,l(t))).disabled=a(t,"disabled"),this.options.push(c),r.appendChild(c),c.idx=h,n.appendChild(f.call(this,c,t)),this.data[h]=t,h++},this)):((c=new Option(t.text,t.value,!1,l(t))).disabled=a(t,"disabled"),this.options.push(c),c.idx=h,f.call(this,c,t),this.data[h]=t,h++)},this)}o.call(this,!0);var d;this.navIndex=0;for(var p=0;p<this.items.length;p++)if(d=this.items[p],!s.hasClass(d,"disabled")){s.addClass(d,"active"),this.navIndex=p;break}if(this.requiresPagination){var g=this;this.pageIndex=1,this.pages=this.items.map(function(e,t){return t%g.config.pagination==0?g.items.slice(t,t+g.config.pagination):null}).filter(function(e){return e})}this.container.appendChild(this.selected),this.container.appendChild(t),this.placeEl=s.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),u.call(this)},u=function(){var e=this;this.events={},this.events.dismiss=d.bind(this),this.events.navigate=g.bind(this),this.events.reset=this.reset.bind(this),(this.config.nativeDropdown||this.mobileDevice)&&(this.ctrlDown=!1,this.mobileDevice?s.on(this.el,"change",function(e){if(this.el.multiple){var t=[];s.each(this.options,function(e,i){i.selected&&t.push(i.idx),b.call(this,this.items[i.idx])},this),s.each(t,function(e,t){v.call(this,this.items[t])},this)}},this):(s.on(document,"keydown",function(e){this.ctrlDown="Control"===e.key},this),s.on(document,"keyup",function(e){this.ctrlDown=!1},this),s.on(this.el,"click",function(e){this.el.multiple&&"OPTION"===e.target.nodeName&&(this.ctrlDown||this.clear(),m.call(this,this.items[e.target.idx]),e.preventDefault())},this)),s.on(this.el,"change",function(e){this.el.multiple||this.el.selectedIndex>-1&&v.call(this,this.items[this.el.selectedIndex])},this)),s.on(this.container,"click",function(e){e.target===this.el&&this.toggle()},this),s.on(this.selected,"click",function(e){this.disabled||this.toggle(),s.preventDefault(e)},this),s.on(this.label,"click",function(e){var t=e.target;s.hasClass(t,"selectr-tag-remove")&&b.call(this,this.items[t.parentNode.idx])},this),(this.el.multiple&&this.config.clearable||!this.el.multiple&&this.config.allowDeselect)&&s.on(this.selectClear,"click",this.clear.bind(this)),s.on(this.tree,"mousedown",function(e){s.preventDefault(e)}),s.on(this.tree,"click",function(e){var t=s.closest(e.target,function(e){return e&&s.hasClass(e,"selectr-option")});t&&(s.hasClass(t,"disabled")||(s.hasClass(t,"selected")?b.call(this,t):v.call(this,t),this.opened&&!this.el.multiple&&this.close()))},this),s.on(document,"click",this.events.dismiss),s.on(document,"keydown",this.events.navigate),s.on(this.tree,"mouseover",function(e){var t=e.target;t.classList.contains("selectr-option")&&(t.classList.contains("disabled")||(this.items[this.navIndex].classList.remove("active"),t.classList.add("active"),this.navIndex=[].slice.call(this.items).indexOf(t)))},this),this.config.searchable&&(s.on(this.input,"keyup",function(e){this.search(),this.config.taggable||(this.input.value.length?s.addClass(this.input.parentNode,"active"):s.removeClass(this.input.parentNode,"active"))},this),s.on(this.inputClear,"click",function(e){this.input.value=null,w.call(this),this.tree.childElementCount||c.call(this)},this)),this.config.taggable&&s.on(this.input,"keyup",function(e){if(this.search(),this.config.taggable&&this.input.value.length){var t=this.input.value.trim();(13===e.which||s.includes(this.tagSeperators,e.key))&&(s.each(this.tagSeperators,function(e,i){t=t.replace(i,"")}),this.addOption({value:t,text:t,selected:!0},!0)?(this.close(),w.call(this)):(this.input.value="",this.setMessage("That tag is already in use.")))}},this),this.update=s.debounce(function(){e.opened&&e.config.closeOnScroll&&e.close(),e.width&&(e.container.style.width=e.width),h.call(e)},50),s.on(window,"resize",this.update),s.on(window,"scroll",this.update),this.requiresPagination&&(this.paginateItems=s.debounce(function(){y.call(this)},50),s.on(this.tree,"scroll",this.paginateItems.bind(this))),this.el.form&&s.on(this.el.form,"reset",this.events.reset)},f=function(e,t){t=t||e;var i=this.customOption?this.config.renderOption(t):e.textContent,n=s.createElement("li",{class:"selectr-option",html:i,role:"treeitem","aria-selected":!1});return n.idx=e.idx,this.items.push(n),e.selected&&s.addClass(n,"selected"),e.disabled&&(n.disabled=!0,s.addClass(n,"disabled")),n},g=function(e){var t=(e=e||window.event).which,i=[13,38,40];if(this.items.length&&this.opened&&s.includes(i,t))if(s.preventDefault(e),13!==t){var n,a=this.items[this.navIndex];switch(t){case 38:n=0,this.navIndex>0&&this.navIndex--;break;case 40:n=1,this.navIndex<this.items.length-1&&this.navIndex++}if(this.navigating=!0,this.items[this.navIndex].classList.contains("disabled")||this.items[this.navIndex].classList.contains("excluded"))for(;this.items[this.navIndex].classList.contains("disabled")||this.items[this.navIndex].classList.contains("excluded");)n?this.navIndex++:this.navIndex--;var l,o,h=this.items[this.navIndex],c=s.getRect(this.items[this.navIndex]),r=this.tree.scrollTop,d=this.optsRect.top;if(n){var p=c.top+c.height;o=r+(p-(l=d+this.optsRect.height)),0===this.navIndex?this.tree.scrollTop=0:p>l&&(this.tree.scrollTop=o),this.navIndex===this.tree.childElementCount-1&&this.requiresPagination&&y.call(this)}else{var u=c.top;o=r+(u-(l=d)),0===this.navIndex?this.tree.scrollTop=0:u-l<0&&(this.tree.scrollTop=o)}a&&s.removeClass(a,"active"),s.addClass(h,"active")}else m.call(this,this.items[this.navIndex])},m=function(e){this.options[e.idx].disabled||(s.hasClass(e,"selected")?b.call(this,e):v.call(this,e),this.opened&&!this.el.multiple&&this.close())},v=function(e){var t=[].slice.call(this.el.options),i=this.options[e.idx];if(this.el.multiple){if(s.includes(this.selectedIndexes,e.idx))return!1;var n=this.config.maxSelections;if(n&&this.tags.length==n)return this.setMessage("A maximum of "+n+" items can be selected.",!0),!1;this.selectedValues.push(i.value),this.selectedIndexes.push(e.idx),x.call(this,e)}else{var a=this.data?this.data[e.idx]:i;this.label.innerHTML=this.customSelected?this.config.renderSelection(a):i.textContent,this.selectedValue=i.value,this.selectedIndex=e.idx,s.each(this.options,function(t,i){var n=this.items[t];t!==e.idx&&(n&&s.removeClass(n,"selected"),i.selected=!1,i.removeAttribute("selected"))},this)}s.includes(t,i)||this.el.add(i),e.setAttribute("aria-selected",!0),s.addClass(e,"selected"),s.addClass(this.container,"has-selected"),i.selected=!0,i.setAttribute("selected",""),this.emit("selectr.select",i),this.emit("selectr.change",i)},b=function(e){var t=this.options[e.idx];if(this.el.multiple){var i=this.selectedIndexes.indexOf(e.idx);this.selectedIndexes.splice(i,1);var n=this.selectedValues.indexOf(t.value);this.selectedValues.splice(n,1),C.call(this,e),this.tags.length||s.removeClass(this.container,"has-selected")}else{if(!this.config.allowDeselect)return!1;this.label.innerHTML="",this.selectedValue=null,this.el.selectedIndex=-1,s.removeClass(this.container,"has-selected")}this.items[e.idx].setAttribute("aria-selected",!1),s.removeClass(this.items[e.idx],"selected"),t.selected=!1,t.removeAttribute("selected"),this.emit("selectr.deselect",t),this.emit("selectr.change",t)},x=function(e){var t=this,i=document.createDocumentFragment(),n=this.options[e.idx],a=this.data?this.data[e.idx]:n,l=this.customSelected?this.config.renderSelection(a):n.textContent,o=s.createElement("li",{class:"selectr-tag",html:l}),h=s.createElement("button",{class:"selectr-tag-remove",type:"button"});if(o.appendChild(h),o.idx=e.idx,o.tag=n.value,this.tags.push(o),this.config.sortSelected){var c=this.tags.slice();c.sort(function(e,i){var s,n,a=[],l=[];for(!0===t.config.sortSelected?(s=e.tag,n=i.tag):"text"===t.config.sortSelected&&(s=e.textContent,n=i.textContent),s.replace(/(\d+)|(\D+)/g,function(e,t,i){a.push([t||1/0,i||""])}),n.replace(/(\d+)|(\D+)/g,function(e,t,i){l.push([t||1/0,i||""])});a.length&&l.length;){var o=a.shift(),h=l.shift(),c=o[0]-h[0]||o[1].localeCompare(h[1]);if(c)return c}return a.length-l.length}),s.each(c,function(e,t){i.appendChild(t)}),this.label.innerHTML=""}else i.appendChild(o);this.config.taggable?this.label.insertBefore(i,this.input.parentNode):this.label.appendChild(i)},C=function(e){var t=!1;s.each(this.tags,function(i,s){s.idx===e.idx&&(t=s)},this),t&&(this.label.removeChild(t),this.tags.splice(this.tags.indexOf(t),1))},y=function(){var e=this.tree;if(e.scrollTop>=e.scrollHeight-e.offsetHeight&&this.pageIndex<this.pages.length){var t=document.createDocumentFragment();s.each(this.pages[this.pageIndex],function(e,i){i.parentNode?i.parentNode.parentNode||t.appendChild(i.parentNode):t.appendChild(i)},this),e.appendChild(t),this.pageIndex++,this.emit("selectr.paginate",{items:this.items.length,total:this.data.length,page:this.pageIndex,pages:this.pages.length})}},w=function(){(this.config.searchable||this.config.taggable)&&(this.input.value=null,this.searching=!1,this.config.searchable&&s.removeClass(this.inputContainer,"active"),s.hasClass(this.container,"notice")&&(s.removeClass(this.container,"notice"),s.addClass(this.container,"open"),this.input.focus()),s.each(this.items,function(e,t){s.removeClass(t,"excluded"),this.customOption||(t.innerHTML=t.textContent)},this))},I=function(e,t){var i=new RegExp(e,"i").exec(t.textContent);return!!i&&t.textContent.replace(i[0],"<span class='selectr-match'>"+i[0]+"</span>")},O=function(e,t){if(t=t||{},!e)throw new Error("You must supply either a HTMLSelectElement or a CSS3 selector string.");if(this.el=e,"string"==typeof e&&(this.el=n(e)),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(t)};return O.prototype.render=function(e){if(!this.rendered){this.config=s.extend(t,e),this.originalType=this.el.type,this.originalIndex=this.el.tabIndex,this.originalOptionCount=this.el.options.length,(this.config.multiple||this.config.taggable)&&(this.el.multiple=!0),this.disabled=a(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,i.mixin(this),p.call(this),this.update(),this.optsRect=s.getRect(this.tree),this.rendered=!0;var n=this;setTimeout(function(){n.emit("selectr.init")},20)}},O.prototype.destroy=function(){this.rendered&&(this.emit("selectr.destroy"),"select-one"===this.originalType&&(this.el.multiple=!1),this.config.data&&(this.el.innerHTML=""),s.removeClass(this.el,"selectr-hidden"),this.el.form&&s.off(this.el.form,"reset",this.events.reset),s.off(document,"click",this.events.dismiss),s.off(document,"keydown",this.events.navigate),s.off(window,"resize",this.update),s.off(window,"scroll",this.update),this.container.parentNode.replaceChild(this.el,this.container),this.rendered=!1)},O.prototype.setValue=function(e){var t=s.isArray(e);if(t||(e=e.toString().trim()),!this.el.multiple&&t)return!1;s.each(this.options,function(i,n){(t&&s.includes(e.toString(),n.value)||n.value===e)&&m.call(this,this.items[n.idx])},this)},O.prototype.getValue=function(e,t){var i;if(this.el.multiple)e?this.selectedIndexes.length&&((i={}).values=[],s.each(this.selectedIndexes,function(e,t){var s=this.options[t];i.values[e]={value:s.value,text:s.textContent}},this)):i=this.selectedValues.slice();else if(e){var n=this.options[this.selectedIndex];i={value:n.value,text:n.textContent}}else i=this.selectedValue;return e&&t&&(i=JSON.stringify(i)),i},O.prototype.addOption=function(e,t){if(e){if(s.isArray(e))s.each(e,function(e,t){this.addOption(t)},this);else if(s.isObject(e)){if(t){var i=!1;if(s.each(this.options,function(t,s){s.value.toLowerCase()===e.value.toLowerCase()&&(i=!0)}),i)return!1}var n=s.createElement("option",e);this.data&&this.data.push(e),this.options.push(n),n.idx=this.options.length-1;var a=f.call(this,n);return e.selected&&v.call(this,a),n}if(this.setPlaceholder(),this.requiresPagination){var l=this;this.pages=this.items.map(function(e,t){return t%l.config.pagination==0?l.items.slice(t,t+l.config.pagination):null}).filter(function(e){return e})}return!0}},O.prototype.search=function(e){e=e||this.input.value;var t=document.createDocumentFragment();this.removeMessage(),r.call(this),e.length>1?(s.each(this.options,function(i,n){var a=this.items[n.idx];s.includes(n.textContent.toLowerCase(),e.toLowerCase())&&!n.disabled?(a.parentNode?a.parentNode.parentNode||t.appendChild(a.parentNode):t.appendChild(a),s.removeClass(a,"excluded"),this.customOption||(a.innerHTML=I(e,n))):s.addClass(a,"excluded")},this),t.childElementCount||this.setMessage("no results.")):c.call(this),this.tree.appendChild(t)},O.prototype.toggle=function(){this.disabled||(this.opened?this.close():this.open())},O.prototype.open=function(){var e=this;if(this.opened||this.emit("selectr.open"),this.opened=!0,this.mobileDevice||this.config.nativeDropdown)return s.addClass(this.container,"native-open"),void(this.config.data&&s.each(this.options,function(e,t){this.el.add(t)},this));s.addClass(this.container,"open"),c.call(this),h.call(this),this.tree.scrollHeight<=this.optsRect.height&&this.requiresPagination&&y.call(this),s.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(){e.input.focus(),e.input.tabIndex=0},10)},O.prototype.close=function(){if(this.opened&&this.emit("selectr.close"),this.opened=!1,this.mobileDevice||this.config.nativeDropdown)s.removeClass(this.container,"native-open");else{var e=s.hasClass(this.container,"notice");this.config.searchable&&!e&&(this.input.blur(),this.input.tabIndex=-1,this.searching=!1),e&&(s.removeClass(this.container,"notice"),this.notice.textContent=""),s.removeClass(this.container,"open"),s.removeClass(this.container,"native-open"),this.selected.setAttribute("aria-expanded",!1),this.tree.setAttribute("aria-hidden",!0),this.tree.setAttribute("aria-expanded",!1),r.call(this),w.call(this)}},O.prototype.enable=function(){this.disabled=!1,this.el.disabled=!1,this.selected.tabIndex=this.originalIndex,s.each(this.tags,function(e,t){t.lastElementChild.tabIndex=0}),s.removeClass(this.container,"selectr-disabled")},O.prototype.disable=function(e){e||(this.el.disabled=!0),this.selected.tabIndex=-1,s.each(this.tags,function(e,t){t.lastElementChild.tabIndex=-1}),this.disabled=!0,s.addClass(this.container,"selectr-disabled")},O.prototype.reset=function(){this.disabled||(this.clear(),o.call(this,!0),s.each(this.el.options,function(e,t){t.selected&&v.call(this,this.items[t.idx])},this),this.emit("selectr.reset"))},O.prototype.clear=function(){if(this.el.multiple){var e=this.selectedIndexes.slice();s.each(e,function(e,t){b.call(this,this.items[t])},this)}else b.call(this,this.items[this.el.selectedIndex]);this.emit("selectr.clear")},O.prototype.serialise=function(e){var t=[];return s.each(this.options,function(e,i){var s={value:i.value,text:i.textContent};i.selected&&(s.selected=!0),i.disabled&&(s.disabled=!0),t[e]=s}),e?JSON.stringify(t):t},O.prototype.serialize=function(e){return this.serialise(e)},O.prototype.setPlaceholder=function(e){e=e||this.config.placeholder||this.el.getAttribute("placeholder"),this.options.length||(e="No options available"),this.placeEl.innerHTML=e},O.prototype.setMessage=function(e,t){t&&this.close(),s.addClass(this.container,"notice"),this.notice.textContent=e},O.prototype.removeMessage=function(){s.removeClass(this.container,"notice"),this.notice.innerHTML=""},O});
{
"name": "mobius1-selectr",
"version": "2.2.0",
"version": "2.2.1",
"description": "A lightweight dependency-free javascript select box replacement.",

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

@@ -90,2 +90,5 @@ # Selectr [![Build Status](https://travis-ci.org/Mobius1/Selectr.svg?branch=master)](https://travis-ci.org/Mobius1/Selectr) [![npm version](https://badge.fury.io/js/mobius1-selectr.svg)](https://badge.fury.io/js/mobius1-selectr) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/Mobius1/Selectr/blob/master/LICENSE)

### 2.2.1
* Hotfix
### 2.2.0

@@ -92,0 +95,0 @@ * Empty select elements can now be used ([#23](https://github.com/Mobius1/Selectr/issues/23))

/*!
* Selectr 2.2.0
* Selectr 2.2.1
* http://mobius.ovh/docs/selectr

@@ -298,2 +298,6 @@ *

};
var selected = function(obj) {
return obj.hasOwnProperty("selected") && obj.selected === true;
}

@@ -321,14 +325,10 @@ /**

// Check the original data for selected options on form.reset()
if ( reset ) {
if ( this.config.data ) {
util.each(this.config.data, function(idx, item) {
util.each(this.options, function(i, option) {
if ( option.value === item.value && set(item, "selected") ) {
option.selected = true;
option.setAttribute("selected", "");
}
}, this);
if ( this.config.data ) {
util.each(this.config.data, function(idx, item) {
util.each(this.options, function(i, option) {
if ( option.value === item.value && selected(item) ) {
select.call(this, this.items[option.idx]);
}
}, this);
}
}, this);
}

@@ -639,3 +639,3 @@ };

util.each(opt.children, function(x, data) {
option = new Option(data.text, data.value, false, set(data, "selected"));
option = new Option(data.text, data.value, false, selected(data));

@@ -657,3 +657,3 @@ option.disabled = set(data, "disabled");

} else {
option = new Option(opt.text, opt.value, false, set(opt, "selected"));
option = new Option(opt.text, opt.value, false, selected(opt));

@@ -780,4 +780,2 @@ option.disabled = set(opt, "disabled");

console.log(e.target, e.target.idx, this.items[e.target.idx]);
change.call(this, this.items[e.target.idx]);

@@ -981,3 +979,3 @@

if (option.selected && option.defaultSelected) {
if (option.selected) {
util.addClass(opt, "selected");

@@ -984,0 +982,0 @@ }

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