mobius1-selectr
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "mobius1-selectr", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A lightweight dependency-free javascript select box replacement.", | ||
@@ -5,0 +5,0 @@ "main": "selectr.min.js", |
# Selectr | ||
A lightweight dependency-free select box replacement. 2.8kb minified and gzipped. | ||
A lightweight dependency-free select box replacement written in vanilla javascript. 2.8kb minified and gzipped. | ||
@@ -4,0 +4,0 @@ Features: |
199
selectr.js
/*! | ||
* Selectr 1.0.2 | ||
* Selectr 1.0.3 | ||
* http://mobiuswebdesign.co.uk/plugins/selectr | ||
@@ -33,12 +33,13 @@ * | ||
var _newElement = function(a, b) { | ||
var c, d = document.createElement(a); | ||
if (b && "object" == typeof b) | ||
for (c in b) | ||
if (c in d) "innerHTML" === c ? d.innerHTML = b[c] : d[c] = b[c]; | ||
else if ("class" === c) | ||
for (var e = b[c].split(" "), f = e.length - 1; f >= 0; f--) { | ||
if ( e[f].length ) | ||
d.classList.add(e[f]); | ||
} | ||
else d.setAttribute(c, b[c]); | ||
var c = document, | ||
d = c.createElement(a); | ||
if (b && "object" == typeof b) { | ||
var e; | ||
for (e in b) | ||
if ("html" === e) d.innerHTML = b[e]; | ||
else if ("text" === e) { | ||
var f = c.createTextNode(b[e]); | ||
d.appendChild(f) | ||
} else d.setAttribute(e, b[e]) | ||
} | ||
return d | ||
@@ -118,5 +119,2 @@ }; | ||
this.scrollX = window.scrollX || window.pageXOffset; | ||
this.scrollY = window.scrollY || window.pageYOffset; | ||
this.options = extend(defaults, opts); | ||
@@ -281,3 +279,3 @@ | ||
if ( opt.nodeName === 'OPTGROUP' ) { | ||
let group = _newElement('li', { class: 'selectr-optgroup', innerHTML: opt.label }); | ||
let group = _newElement('li', { class: 'selectr-optgroup', html: opt.label }); | ||
_append(_this.optsFrag, group); | ||
@@ -318,3 +316,4 @@ | ||
var placeholder = this.options.placeholder || this.elem.getAttribute('placeholder') || 'Choose...'; | ||
_append(this.selected, _newElement('div', { class: 'selectr-placeholder', innerHTML: placeholder})); | ||
this.placeElem = _newElement('div', { class: 'selectr-placeholder', html: placeholder}); | ||
_append(this.selected, this.placeElem); | ||
@@ -344,3 +343,3 @@ if ( (!this.elem.multiple && !!this.elem.value.length) || (this.elem.multiple && !!this.txt.children.length) ) { | ||
var content = this.hasTemplate ? this.options.render(option) : option.textContent.trim(); | ||
var opt = _newElement('li', { class: 'selectr-option', innerHTML: content }); | ||
var opt = _newElement('li', { class: 'selectr-option', html: content }); | ||
@@ -381,41 +380,65 @@ if ( option.hasAttribute('selected') ) { | ||
// Prevent text selection | ||
_addListener(_this.selected, 'mousedown', function(e){ e.preventDefault(); }); | ||
_addListener(_this.optsOptions, 'mousedown', function(e){ e.preventDefault(); }); | ||
this.handleClickEvents = this.handleEvents.bind(this); | ||
this.handleDismiss = this.dismiss.bind(this); | ||
this.handleNavigate = this.navigate.bind(this); | ||
_addListener(_this.selected, 'click', _this.toggleOptions.bind(_this)); | ||
_addListener(_this.optsOptions, 'click', function(event) { | ||
_this.selectOption(event); | ||
}); | ||
// Global listener | ||
_addListener(this.container, 'click', this.handleClickEvents); | ||
if ( _this.elem.multiple ) { | ||
_addListener(_this.txt, 'click', _this.removeTags.bind(_this)); | ||
} | ||
// Prevent text selection | ||
_addListener(this.selected, 'mousedown', function(e){ e.preventDefault(); }); | ||
_addListener(this.optsOptions, 'mousedown', function(e){ e.preventDefault(); }); | ||
if ( _this.options.searchable ) { | ||
_addListener(_this.input, 'keyup', _this.search.bind(_this)); | ||
_addListener(_this.clear, 'click', _this.clearOptions.bind(_this)); | ||
if ( this.options.searchable ) { | ||
_addListener(this.input, 'keyup', this.search.bind(this)); | ||
_addListener(this.clear, 'click', this.clearOptions.bind(this)); | ||
} | ||
_addListener(document, 'click', this.handleDismiss); | ||
_addListener(document, 'keydown', this.handleNavigate); | ||
_this.handleDismiss = _this.dismiss.bind(_this); | ||
_this.handleNavigate = _this.navigate.bind(_this); | ||
this.update = _debounce(function() { | ||
_this.setDimensions(); | ||
}, 50); | ||
_addListener(document, 'click', _this.handleDismiss); | ||
_addListener(document, 'keydown', _this.handleNavigate); | ||
_addListener(window, 'resize', this.update); | ||
_addListener(window, 'scroll', this.update); | ||
}, | ||
_this.resize = _debounce(function() { | ||
_this.setDimensions(); | ||
}, 100); | ||
handleEvents: function(e) | ||
{ | ||
e = e || window.event; | ||
_addListener(window, 'resize', _this.resize); | ||
var target = e.target; | ||
_addListener(window, 'scroll', _this.resize); | ||
// Click on placeholder or selected text | ||
if ( target === this.txt || target === this.placeElem ) { | ||
target = this.placeElem.parentNode; | ||
} | ||
// Open / close dropdown | ||
if ( target === this.selected ) { | ||
if ( !this.disabled ) { | ||
this.toggleOptions(); | ||
} | ||
} | ||
// Select option | ||
if ( _hasClass(target, 'selectr-option') ) { | ||
this.selectOption(e); | ||
} | ||
// Remove tag button | ||
if ( _hasClass(target, 'selectr-tag-remove') ) { | ||
this.removeTags(e); | ||
} | ||
e.preventDefault(); | ||
}, | ||
navigate: function(event) | ||
navigate: function(e) | ||
{ | ||
event = event || window.event; | ||
e = e || window.e; | ||
var _this = this, keyCode = event.keyCode; | ||
var _this = this, keyCode = e.keyCode; | ||
@@ -425,3 +448,3 @@ // Filter out the keys we don't want | ||
event.preventDefault(); | ||
e.preventDefault(); | ||
@@ -431,18 +454,9 @@ var list = this.searching ? this.searchList : this.list, dir; | ||
switch (keyCode) { | ||
case 13: // select option | ||
_this.selectOption(event); | ||
return; | ||
case 13: | ||
return void _this.selectOption(e); | ||
case 38: | ||
dir = "up", _this.activeIdx > 0 && _this.activeIdx--; | ||
break; | ||
case 38: // Scroll up options | ||
dir = 'up'; | ||
if ( _this.activeIdx > 0 ) { | ||
_this.activeIdx--; | ||
} | ||
break; | ||
case 40: // scroll down options | ||
dir = 'down'; | ||
if ( _this.activeIdx < list.length - 1 ) { | ||
_this.activeIdx++; | ||
}; | ||
break; | ||
case 40: | ||
dir = "down", _this.activeIdx < list.length - 1 && _this.activeIdx++ | ||
} | ||
@@ -452,7 +466,10 @@ | ||
var nextRect = nextElem.getBoundingClientRect(); | ||
var optsTop = _this.optsOptions.scrollTop; | ||
var scrollY = window.scrollY || window.pageYOffset; | ||
var offset = _this.optsRect.top + scrollY; | ||
if ( dir === 'up' ) { | ||
var currentOffset = _this.optsRect.top; | ||
var nextTop = nextRect.top + _this.scrollY; | ||
var nextOffset = _this.optsOptions.scrollTop + (nextTop - currentOffset); | ||
var currentOffset = offset; | ||
var nextTop = nextRect.top + scrollY; | ||
var nextOffset = optsTop + (nextTop - currentOffset); | ||
@@ -465,6 +482,5 @@ if (_this.activeIdx === 0) { | ||
} else { | ||
var currentOffset = _this.optsRect.top + | ||
_this.optsOptions.offsetHeight; | ||
var nextBottom = nextRect.top + _this.scrollY + nextElem.offsetHeight; | ||
var nextOffset = _this.optsOptions.scrollTop + nextBottom - currentOffset; | ||
var currentOffset = offset + _this.optsRect.height; | ||
var nextBottom = nextRect.top + scrollY + nextRect.height; | ||
var nextOffset = optsTop + nextBottom - currentOffset; | ||
@@ -478,14 +494,7 @@ if (_this.activeIdx === 0) { | ||
// Set the class for highlighting | ||
forEach(list, function(i, opt) { | ||
if ( i === _this.activeIdx ) { | ||
_addClass(opt, 'active'); | ||
} else { | ||
_removeClass(opt, 'active'); | ||
} | ||
}); | ||
_removeClass(_this.optsOptions.getElementsByClassName('active')[0], 'active'); | ||
_addClass(list[_this.activeIdx], 'active'); | ||
}, | ||
search: function(event) | ||
search: function(e) | ||
{ | ||
@@ -495,3 +504,3 @@ var _this = this; | ||
var len = value.length; | ||
var navigating = event.keyCode === 38 || event.keyCode === 40; | ||
var navigating = e.keyCode === 38 || e.keyCode === 40; | ||
@@ -547,11 +556,9 @@ if ( ( len < this.options.minChars && len >= this.lastLen ) || navigating ) return; | ||
selectOption: function(event) | ||
selectOption: function(e) | ||
{ | ||
event = event || window.event; | ||
var _this = this; | ||
var selected = event.target; | ||
var selected = e.target; | ||
var list = this.searching ? this.searchList : this.list; | ||
if ( event.type === 'keydown' ) { | ||
if ( e.type === 'keydown' ) { | ||
selected = list[_this.activeIdx]; | ||
@@ -696,3 +703,3 @@ } | ||
'data-text': item.text || '', | ||
innerHTML: result | ||
html: result | ||
}); | ||
@@ -805,3 +812,3 @@ | ||
let tag = _newElement('li', { class: 'selectr-tag', innerHTML: content }); | ||
let tag = _newElement('li', { class: 'selectr-tag', html: content }); | ||
let btn = _newElement('button', { class: 'selectr-tag-remove', type: 'button' }); | ||
@@ -828,17 +835,10 @@ | ||
removeTags: function(event) | ||
removeTags: function(e) | ||
{ | ||
if ( this.disabled ) return; | ||
event = event || window.event; | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
var target = event.target; | ||
var nodeName = target.nodeName; | ||
if ( nodeName !== 'BUTTON' ) return; | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
this.removeTag(target.parentNode); | ||
this.removeTag(e.target.parentNode); | ||
}, | ||
@@ -877,4 +877,2 @@ | ||
if ( this.disabled ) return; | ||
if ( open ) { | ||
@@ -1061,7 +1059,2 @@ this.close() | ||
this.container.style.cssText += 'width: '+w+'; '; | ||
this.scrollX = window.scrollX || window.pageXOffset; | ||
this.scrollY = window.scrollY || window.pageYOffset; | ||
if ( this.opened ) { | ||
@@ -1072,2 +1065,4 @@ this.elemRect = this.elem.getBoundingClientRect(); | ||
this.close(); | ||
if ( bottom > wh ) { | ||
@@ -1079,2 +1074,4 @@ _addClass(this.container, 'inverted'); | ||
} | ||
this.container.style.cssText += 'width: '+w+'; '; | ||
}, | ||
@@ -1081,0 +1078,0 @@ |
/*! | ||
* Selectr 1.0.2 | ||
* Selectr 1.0.3 | ||
* http://mobiuswebdesign.co.uk/plugins/selectr | ||
@@ -7,2 +7,2 @@ * | ||
*/ | ||
String.prototype.includes||(String.prototype.includes=function(a,b){"use strict";return"number"!=typeof b&&(b=0),!(b+a.length>this.length)&&this.indexOf(a,b)!==-1}),function(a,b){var c="Selectr";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function k(a,c){if(null===a)throw new Error("Selectr requires an element to work.");var d={minChars:1,width:"auto",emptyOption:!0,searchable:!0,selectedIndex:null,selectedValue:null,selectedIndexes:[],selectedValues:[],containerClass:"",maxSelections:null};this.elem=a,this.elemRect=this.elem.getBoundingClientRect(),this.selectedVal=null,this.selectedVals=[],this.ajaxOpts=!1,this.tags=[],this.opts=[],this.values=[],this.list=[],this.lastLen=0,this.disabled=!1,this.opened=!1,this.searching=!1,this.searchList=[],this.activeIdx=0,this.remote=!1,this.scrollX=window.scrollX||window.pageXOffset,this.scrollY=window.scrollY||window.pageYOffset,this.options=b(d,c),this.hasTemplate=this.options.hasOwnProperty("render")&&"function"==typeof this.options.render,this.initialise()}var b=function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a},c=function(a,b){var c,d=document.createElement(a);if(b&&"object"==typeof b)for(c in b)if(c in d)"innerHTML"===c?d.innerHTML=b[c]:d[c]=b[c];else if("class"===c)for(var e=b[c].split(" "),f=e.length-1;f>=0;f--)e[f].length&&d.classList.add(e[f]);else d.setAttribute(c,b[c]);return d},d=function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a)){var d;for(d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a)}else for(var e=0,f=a.length;e<f;e++)b.call(c,e,a[e],a)},e=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}},f=function(a,b){return a.classList?a.classList.contains(b):!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))},g=function(a,b){a.classList?a.classList.add(b):f(b)||(a.className=a.className.trim()+" "+b)},h=function(a,b){a.classList?a.classList.remove(b):f(b)&&(a.className=a.className.replace(new RegExp("(^|\\b)"+b.split(" ").join("|")+"(\\b|$)","gi")," "))},i=function(a,b){a.appendChild(b)},j=function(a,b,c,d){a.addEventListener(b,c,d||!1)};return k.prototype={initialise:function(){if(!this.initialised){var a=this;if(this.on=function(b,c){this.elem.addEventListener(b,function(b){c.call(this,b,a)})},a.options.multiple&&(a.elem.setAttribute("multiple",!0),a.elem.multiple=!0),this.options.data){var b=document.createDocumentFragment();_forEach(this.options.data,function(a,d){let e=c("option",{value:d.value});e.textContent=d.text,b.appendChild(e)}),this.elem.appendChild(b)}a.options.ajax&&"object"==typeof a.options.ajax?a.setAjaxUrl():this.setSelections(),this.build(),this.initialised=!0,setTimeout(function(){a.emit("selectr.init")},100)}},setSelections:function(){var a=this;"OPTGROUP"===this.elem.options[0].parentNode.nodeName&&(this.hasOptGroups=!0),this.elem.multiple?(this.options.emptyOption=!1,(this.options.selectedIndexes.length||this.options.selectedValues.length)&&d(this.elem.options,function(b,c){c.selected=!1,(a.options.selectedIndexes.indexOf(b)>-1||a.options.selectedValues.indexOf(c.value)>-1)&&(c.selected=!0)})):(this.options.emptyOption&&(this.emptyOpt=c("option",{value:"",selected:!0}),this.hasOptGroups?this.elem.insertBefore(this.emptyOpt,this.elem.options[0].parentNode):this.elem.insertBefore(this.emptyOpt,this.elem.options[0])),null!==this.options.selectedIndex?(this.options.emptyOption&&this.options.selectedIndex++,this.elem.value=this.elem.options[this.options.selectedIndex].value):null!==this.options.selectedValue&&(this.elem.value=this.options.selectedValue,this.selectedVal=this.options.selectedValue))},setAjaxUrl:function(){this.ajaxOpts=!0;var a=this,b=a.options.ajax;a.ajax_url=b.url,b.queryParam&&(a.ajax_url+="?",b.params&&d(b.params,function(b,c){a.ajax_url+=b+"="+c+"&"}),a.ajax_url+=b.queryParam+"="),"function"!=typeof a.options.ajax.formatSelected&&(a.options.ajax.formatSelected=function(a){return a.text})},build:function(){var a=this;this.optsFrag=document.createDocumentFragment(),g(this.elem,"hidden-input"),this.container=c("div",{id:"selectr-"+a.elem.id,class:"selectr-container "+this.options.containerClass}),this.selected=c("div",{class:"selectr-selected"}),this.txt=c(this.elem.multiple?"ul":"span",{class:"selectr-text"}),this.optsContainer=c("div",{class:"selectr-options-container"}),this.optsOptions=c("ul",{class:"selectr-options"}),this.notice=c("div",{class:"selectr-notice"}),this.elem.multiple&&(g(this.txt,"selectr-tags"),g(this.container,"multiple")),this.options.searchable&&(this.input=c("input",{class:"selectr-input"}),this.clear=c("button",{class:"selectr-clear",type:"button"}),this.inputContainer=c("div",{class:"selectr-input-container"})),a.options.ajax||(this.hasOptGroups?(g(this.optsOptions,"optgroups"),d(this.elem.children,function(b,e){if("OPTGROUP"===e.nodeName){let b=c("li",{class:"selectr-optgroup",innerHTML:e.label});i(a.optsFrag,b),e.children&&d(e.children,function(b,c){a.buildOption(b,c)})}})):d(this.elem.options,function(b,c){a.buildOption(b,c)}),g(this.list[this.activeIdx],"active")),i(this.optsOptions,this.optsFrag),i(this.selected,this.txt),i(this.container,this.selected),this.options.searchable&&(i(this.inputContainer,this.input),i(this.inputContainer,this.clear),i(this.optsContainer,this.inputContainer)),i(this.optsContainer,this.optsOptions),i(this.optsContainer,this.notice),i(this.container,this.optsContainer);var b=this.options.placeholder||this.elem.getAttribute("placeholder")||"Choose...";i(this.selected,c("div",{class:"selectr-placeholder",innerHTML:b})),(!this.elem.multiple&&this.elem.value.length||this.elem.multiple&&this.txt.children.length)&&(g(this.container,"has-selected"),!this.elem.multiple&&this.emptyOpt&&(this.emptyOpt.selected=!1)),this.elem.parentNode.insertBefore(this.container,this.elem),i(this.container,this.elem),this.setDimensions(),this.attachEventListeners()},buildOption:function(a,b){if(b!==this.emptyOpt&&"OPTION"===b.nodeName&&b.value){var d=this.hasTemplate?this.options.render(b):b.textContent.trim(),e=c("li",{class:"selectr-option",innerHTML:d});if(b.hasAttribute("selected")&&(b.selected=!0),i(this.optsFrag,e),b.selected&&(g(e,"selected"),this.elem.multiple?this.createTag(b):(this.txt.innerHTML=d,this.selectedIndex=a),this.selectedVals.push(b.value)),b.disabled)return void g(e,"disabled");this.opts.push(b),this.values.push(b.value),this.list.push(e)}},attachEventListeners:function(){var a=this;j(a.selected,"mousedown",function(a){a.preventDefault()}),j(a.optsOptions,"mousedown",function(a){a.preventDefault()}),j(a.selected,"click",a.toggleOptions.bind(a)),j(a.optsOptions,"click",function(b){a.selectOption(b)}),a.elem.multiple&&j(a.txt,"click",a.removeTags.bind(a)),a.options.searchable&&(j(a.input,"keyup",a.search.bind(a)),j(a.clear,"click",a.clearOptions.bind(a))),a.handleDismiss=a.dismiss.bind(a),a.handleNavigate=a.navigate.bind(a),j(document,"click",a.handleDismiss),j(document,"keydown",a.handleNavigate),a.resize=e(function(){a.setDimensions()},100),j(window,"resize",a.resize),j(window,"scroll",a.resize)},navigate:function(a){a=a||window.event;var b=this,c=a.keyCode;if(b.opened&&(13===c||38===c||40===c)){a.preventDefault();var f,e=this.searching?this.searchList:this.list;switch(c){case 13:return void b.selectOption(a);case 38:f="up",b.activeIdx>0&&b.activeIdx--;break;case 40:f="down",b.activeIdx<e.length-1&&b.activeIdx++}var i=e[b.activeIdx],j=i.getBoundingClientRect();if("up"===f){var k=b.optsRect.top,l=j.top+b.scrollY,m=b.optsOptions.scrollTop+(l-k);0===b.activeIdx?b.optsOptions.scrollTop=0:l-k<0&&(b.optsOptions.scrollTop=m)}else{var k=b.optsRect.top+b.optsOptions.offsetHeight,n=j.top+b.scrollY+i.offsetHeight,m=b.optsOptions.scrollTop+n-k;0===b.activeIdx?b.optsOptions.scrollTop=0:n>k&&(b.optsOptions.scrollTop=m)}d(e,function(a,c){a===b.activeIdx?g(c,"active"):h(c,"active")})}},search:function(a){var b=this,c=b.input.value,e=c.length,f=38===a.keyCode||40===a.keyCode;if(!(e<this.options.minChars&&e>=this.lastLen||f)){if(this.ajaxOpts)return void this.ajaxSearch();this.container.classList.contains("notice")||(c.length>0?g(this.inputContainer,"active"):h(this.inputContainer,"active")),b.searching=!0,b.searchList=[],d(b.opts,function(a,d){let e=b.list[a],f=d.textContent.trim(),i=c.trim();if(f.toLowerCase().includes(i.toLowerCase())){if(b.searchList.push(e),b.hasTemplate)g(e,"match");else{let a=new RegExp(i,"i").exec(f);e.innerHTML=d.textContent.replace(a[0],"<span>"+a[0]+"</span>")}h(e,"excluded")}else g(e,"excluded"),h(e,"match")}),b.searchList.length?this.open():(b.notify("No results."),this.input.focus()),this.lastLen=this.input.value.length}},selectOption:function(a){a=a||window.event;var b=this,c=a.target,e=this.searching?this.searchList:this.list;if("keydown"===a.type&&(c=e[b.activeIdx]),"LI"===c.nodeName&&!c.classList.contains("disabled")){if(b.ajaxOpts)return void b.selectRemoteOption(c);var f=b.list.indexOf(c),i=b.opts[f],j=!1;if(b.elem.multiple){if(c.classList.contains("selected")){var k;d(b.tags,function(a,b){b.getAttribute("data-value")===i.value&&(k=b)}),k&&b.removeTag(k)}else{if(null!==b.options.maxSelections&&b.selectedVals.length>=b.options.maxSelections)return void b.notify("A maximum of "+b.options.maxSelections+" items can be selected.");b.selectedVals.push(i.value),b.createTag(i),i.selected=!0,g(c,"selected"),b.emit("selectr.select"),b.input.value=""}b.txt.children.length&&(j=!0)}else if(b.selectedIndex===f)b.txt.innerHTML="",i.selected=!1,h(c,"selected"),b.selectedVal=null,b.selectedIndex=null,b.elem.value=null,b.emit("selectr.deselect");else{let a=b.optsOptions.getElementsByClassName("selected")[0];a&&h(a,"selected"),b.txt.innerHTML=b.hasTemplate?b.options.render(i):i.textContent,i.selected=!0,g(c,"selected"),b.selectedVal=i.value,b.selectedIndex=f,b.emit("selectr.select"),j=!0}j?g(b.container,"has-selected"):h(b.container,"has-selected"),b.reset(),b.elem.multiple||b.close(),b.emit("selectr.change")}},ajaxSearch:function(){function f(e){var f=document.createDocumentFragment(),g=document.createDocumentFragment();b.searchList=[],b.opts=[],d(e,function(d,e){let h=a.formatResults(e)||e.text,j=c("li",{class:"selectr-option","data-value":e.value,"data-text":e.text||"",innerHTML:h}),k=c("option",{value:e.value});k.textContent=e.text,b.searchList.push(j),b.opts.push(k),i(f,j),i(g,k)}),b.optsOptions.innerHTML="",i(b.optsOptions,f),b.elem.innerHTML="",i(b.elem,g)}this.searching=!0,g(this.inputContainer,"loading");var a=this.options.ajax,b=this,e=new XMLHttpRequest;e.onload=function(){if(4===e.readyState&&200===e.status){var c=JSON.parse(e.responseText);if("function"!=typeof a.parseResults)return;var d=a.parseResults(c);f(d),h(b.inputContainer,"loading"),b.remoteItems=d}},e.open("GET",b.ajax_url+b.input.value,!0),e.send()},selectRemoteOption:function(a){var c,e,f,b=this,i=a.getAttribute("data-value");if(d(b.remoteItems,function(a,d){d.value==i&&(e=d,f=a,c=b.opts[a])}),this.elem.multiple)if(a.classList.contains("selected")&&b.selectedVals.indexOf(i)>-1){var j;d(b.tags,function(a,b){b.getAttribute("data-value")===i&&(j=b)}),j&&b.removeTag(j)}else b.createTag(a,e),b.selectedVals.push(i),b.opts[f].selected=!0,b.emit("selectr.select"),g(a,"selected");else if(b.selectedIndex===f)b.txt.innerHTML="",c.selected=!1,h(a,"selected"),b.selectedVal=null,b.selectedIndex=null,b.elem.value=null,b.emit("selectr.deselect");else{let d=b.optsOptions.getElementsByClassName("selected")[0];d&&h(d,"selected"),b.txt.innerHTML=this.options.ajax.formatSelected(e)||c.getAttribute("data-text")||c.textContent,c.selected=!0,g(a,"selected"),b.selectedVal=c.value,b.selectedIndex=f,b.emit("selectr.select")}this.elem.value?g(this.container,"has-selected"):h(this.container,"has-selected"),this.emit("selectr.select"),this.emit("selectr.change"),this.close()},createTag:function(a,b){var f,e=document.createDocumentFragment();f=b?this.options.ajax.formatSelected(b)||a.getAttribute("data-text")||a.textContent:this.hasTemplate?this.options.render(a):a.textContent;let j=c("li",{class:"selectr-tag",innerHTML:f}),k=c("button",{class:"selectr-tag-remove",type:"button"});i(j,k),i(e,j),i(this.txt,e),this.tags.push(j),this.txt.children.length?g(this.container,"has-selected"):h(this.container,"has-selected"),b?j.setAttribute("data-value",a.getAttribute("data-value")):j.setAttribute("data-value",a.value)},removeTags:function(a){if(!this.disabled){a=a||window.event;var b=a.target,c=b.nodeName;"BUTTON"===c&&(a.preventDefault(),a.stopPropagation(),this.removeTag(b.parentNode))}},removeTag:function(a){var e,f,b=this,c=a.getAttribute("data-value");d(this.opts,function(a,d){d.value==c&&(f=a,e=b.opts[f])}),e.selected=!1,h(this.list[f],"selected"),this.selectedVals.splice(this.selectedVals.indexOf(e.value),1),this.tags.splice(this.tags.indexOf(a),1),this.txt.removeChild(a),this.tags.length||h(this.container,"has-selected"),this.emit("selectr.deselect")},toggleOptions:function(){var b=this.container.classList.contains("open");this.disabled||(b?this.close():this.open())},clearOptions:function(){this.options.searchable&&(this.input.value=null,this.searching=!1,h(this.inputContainer,"active"),h(this.container,"notice"),g(this.container,"open"),this.input.focus()),this.reset()},reset:function(){var a=this;d(this.list,function(b,c){let d=a.opts[b];c.innerHTML=a.hasTemplate?a.options.render(d):d.textContent,h(c,"match"),h(c,"excluded")})},open:function(){var a=this,b=this.elemRect.top+this.elemRect.height+230,c=window.innerHeight;b>c?g(this.container,"inverted"):h(this.container,"inverted"),g(this.container,"open"),h(this.container,"notice"),this.options.searchable&&setTimeout(function(){a.input.focus()},10),this.optsRect=this.optsOptions.getBoundingClientRect(),this.opened=!0,this.ajaxOpts&&(this.searching=!0),this.emit("selectr.open")},close:function(){var a=this.container.classList.contains("notice");this.options.searchable&&!a&&(this.input.blur(),this.searching=!1),a&&(this.container.classList.remove("notice"),this.notice.textContent=""),h(this.container,"open"),this.opened=!1,this.emit("selectr.close")},dismiss:function(a){var b=a.target;this.container.contains(b)||!this.opened&&!this.container.classList.contains("notice")||this.close()},notify:function(a){this.close(),this.container.classList.add("notice"),this.notice.textContent=a},setValue:function(a){var b=this,c=[].slice.call(b.values).indexOf(a);if(!(c<0)){if(b.elem.multiple)b.selectedVals.indexOf(a)<0&&b.createTag(b.opts[c]);else{b.txt.innerHTML=b.hasTemplate?b.options.render(b.opts[c]):b.opts[c].textContent;let a=b.optsOptions.getElementsByClassName("selected")[0];a&&h(a,"selected")}b.selectedVals.push(a),g(b.list[c],"selected"),g(b.container,"has-selected"),b.opts[c].selected=!0,b.emit("selectr.select")}},getValue:function(){return this.elem.multiple?this.selectedVals:this.selectedVal},removeValue:function(a){if(this.tags.length){var b=this,c=[].slice.call(this.values).indexOf(a);if(!(c<0)){var e=this.list[c],f=this.opts[c];if(this.elem.multiple){var g;d(this.tags,function(b,c){c.getAttribute("data-value")===a&&(g=c)}),g&&b.removeTag(g)}else this.txt.innerHTML=this.hasTemplate?this.options.render(f):f.textContent,null!==this.elem.selectedIndex&&h(this.list[this.elem.selectedIndex],"selected");f.selected=!1,h(e,"selected"),this.emit("selectr.select")}}},setDimensions:function(){var a=this.options.width||this.elemRect.width;if("auto"===this.options.width?a="100%":a+="px",this.container.style.cssText+="width: "+a+"; ",this.scrollX=window.scrollX||window.pageXOffset,this.scrollY=window.scrollY||window.pageYOffset,this.opened){this.elemRect=this.elem.getBoundingClientRect();var b=this.elemRect.top+this.elemRect.height+230,c=window.innerHeight;b>c?g(this.container,"inverted"):h(this.container,"inverted")}},emit:function(a){this.elem.dispatchEvent(new Event(a))},enable:function(){this.disabled=!1,h(this.container,"disabled")},disable:function(){this.disabled=!0,g(this.container,"disabled")},destroy:function(){if(this.initialised){var a=this,b=a.container.parentNode;b.insertBefore(a.elem,a.container),b.removeChild(a.container),h(a.elem,"hidden-input"),!a.elem.multiple&&a.options.emptyOption&&a.elem.removeChild(a.elem.options[0]),a.container=null,a.selected=null,a.txt=null,a.optsContainer=null,a.optsOptions=null,a.input=null,a.clear=null,a.inputContainer=null,window.removeEventListener("resize",a.resize),document.removeEventListener("click",a.handleDismiss),document.removeEventListener("keydown",a.handleNavigate),a.initialised=!1}}},k}); | ||
String.prototype.includes||(String.prototype.includes=function(a,b){"use strict";return"number"!=typeof b&&(b=0),!(b+a.length>this.length)&&this.indexOf(a,b)!==-1}),function(a,b){var c="Selectr";"function"==typeof define&&define.amd?define([],b(c)):"object"==typeof exports?module.exports=b(c):a[c]=b(c)}(this,function(a){"use strict";function k(a,c){if(null===a)throw new Error("Selectr requires an element to work.");var d={minChars:1,width:"auto",emptyOption:!0,searchable:!0,selectedIndex:null,selectedValue:null,selectedIndexes:[],selectedValues:[],containerClass:"",maxSelections:null};this.elem=a,this.elemRect=this.elem.getBoundingClientRect(),this.selectedVal=null,this.selectedVals=[],this.ajaxOpts=!1,this.tags=[],this.opts=[],this.values=[],this.list=[],this.lastLen=0,this.disabled=!1,this.opened=!1,this.searching=!1,this.searchList=[],this.activeIdx=0,this.remote=!1,this.options=b(d,c),this.hasTemplate=this.options.hasOwnProperty("render")&&"function"==typeof this.options.render,this.initialise()}var b=function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a},c=function(a,b){var c=document,d=c.createElement(a);if(b&&"object"==typeof b){var e;for(e in b)if("html"===e)d.innerHTML=b[e];else if("text"===e){var f=c.createTextNode(b[e]);d.appendChild(f)}else d.setAttribute(e,b[e])}return d},d=function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a)){var d;for(d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,d,a[d],a)}else for(var e=0,f=a.length;e<f;e++)b.call(c,e,a[e],a)},e=function(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}},f=function(a,b){return a.classList?a.classList.contains(b):!!a.className.match(new RegExp("(\\s|^)"+b+"(\\s|$)"))},g=function(a,b){a.classList?a.classList.add(b):f(b)||(a.className=a.className.trim()+" "+b)},h=function(a,b){a.classList?a.classList.remove(b):f(b)&&(a.className=a.className.replace(new RegExp("(^|\\b)"+b.split(" ").join("|")+"(\\b|$)","gi")," "))},i=function(a,b){a.appendChild(b)},j=function(a,b,c,d){a.addEventListener(b,c,d||!1)};return k.prototype={initialise:function(){if(!this.initialised){var a=this;if(this.on=function(b,c){this.elem.addEventListener(b,function(b){c.call(this,b,a)})},a.options.multiple&&(a.elem.setAttribute("multiple",!0),a.elem.multiple=!0),this.options.data){var b=document.createDocumentFragment();_forEach(this.options.data,function(a,d){let e=c("option",{value:d.value});e.textContent=d.text,b.appendChild(e)}),this.elem.appendChild(b)}a.options.ajax&&"object"==typeof a.options.ajax?a.setAjaxUrl():this.setSelections(),this.build(),this.initialised=!0,setTimeout(function(){a.emit("selectr.init")},100)}},setSelections:function(){var a=this;"OPTGROUP"===this.elem.options[0].parentNode.nodeName&&(this.hasOptGroups=!0),this.elem.multiple?(this.options.emptyOption=!1,(this.options.selectedIndexes.length||this.options.selectedValues.length)&&d(this.elem.options,function(b,c){c.selected=!1,(a.options.selectedIndexes.indexOf(b)>-1||a.options.selectedValues.indexOf(c.value)>-1)&&(c.selected=!0)})):(this.options.emptyOption&&(this.emptyOpt=c("option",{value:"",selected:!0}),this.hasOptGroups?this.elem.insertBefore(this.emptyOpt,this.elem.options[0].parentNode):this.elem.insertBefore(this.emptyOpt,this.elem.options[0])),null!==this.options.selectedIndex?(this.options.emptyOption&&this.options.selectedIndex++,this.elem.value=this.elem.options[this.options.selectedIndex].value):null!==this.options.selectedValue&&(this.elem.value=this.options.selectedValue,this.selectedVal=this.options.selectedValue))},setAjaxUrl:function(){this.ajaxOpts=!0;var a=this,b=a.options.ajax;a.ajax_url=b.url,b.queryParam&&(a.ajax_url+="?",b.params&&d(b.params,function(b,c){a.ajax_url+=b+"="+c+"&"}),a.ajax_url+=b.queryParam+"="),"function"!=typeof a.options.ajax.formatSelected&&(a.options.ajax.formatSelected=function(a){return a.text})},build:function(){var a=this;this.optsFrag=document.createDocumentFragment(),g(this.elem,"hidden-input"),this.container=c("div",{id:"selectr-"+a.elem.id,class:"selectr-container "+this.options.containerClass}),this.selected=c("div",{class:"selectr-selected"}),this.txt=c(this.elem.multiple?"ul":"span",{class:"selectr-text"}),this.optsContainer=c("div",{class:"selectr-options-container"}),this.optsOptions=c("ul",{class:"selectr-options"}),this.notice=c("div",{class:"selectr-notice"}),this.elem.multiple&&(g(this.txt,"selectr-tags"),g(this.container,"multiple")),this.options.searchable&&(this.input=c("input",{class:"selectr-input"}),this.clear=c("button",{class:"selectr-clear",type:"button"}),this.inputContainer=c("div",{class:"selectr-input-container"})),a.options.ajax||(this.hasOptGroups?(g(this.optsOptions,"optgroups"),d(this.elem.children,function(b,e){if("OPTGROUP"===e.nodeName){let b=c("li",{class:"selectr-optgroup",html:e.label});i(a.optsFrag,b),e.children&&d(e.children,function(b,c){a.buildOption(b,c)})}})):d(this.elem.options,function(b,c){a.buildOption(b,c)}),g(this.list[this.activeIdx],"active")),i(this.optsOptions,this.optsFrag),i(this.selected,this.txt),i(this.container,this.selected),this.options.searchable&&(i(this.inputContainer,this.input),i(this.inputContainer,this.clear),i(this.optsContainer,this.inputContainer)),i(this.optsContainer,this.optsOptions),i(this.optsContainer,this.notice),i(this.container,this.optsContainer);var b=this.options.placeholder||this.elem.getAttribute("placeholder")||"Choose...";this.placeElem=c("div",{class:"selectr-placeholder",html:b}),i(this.selected,this.placeElem),(!this.elem.multiple&&this.elem.value.length||this.elem.multiple&&this.txt.children.length)&&(g(this.container,"has-selected"),!this.elem.multiple&&this.emptyOpt&&(this.emptyOpt.selected=!1)),this.elem.parentNode.insertBefore(this.container,this.elem),i(this.container,this.elem),this.setDimensions(),this.attachEventListeners()},buildOption:function(a,b){if(b!==this.emptyOpt&&"OPTION"===b.nodeName&&b.value){var d=this.hasTemplate?this.options.render(b):b.textContent.trim(),e=c("li",{class:"selectr-option",html:d});if(b.hasAttribute("selected")&&(b.selected=!0),i(this.optsFrag,e),b.selected&&(g(e,"selected"),this.elem.multiple?this.createTag(b):(this.txt.innerHTML=d,this.selectedIndex=a),this.selectedVals.push(b.value)),b.disabled)return void g(e,"disabled");this.opts.push(b),this.values.push(b.value),this.list.push(e)}},attachEventListeners:function(){var a=this;this.handleClickEvents=this.handleEvents.bind(this),this.handleDismiss=this.dismiss.bind(this),this.handleNavigate=this.navigate.bind(this),j(this.container,"click",this.handleClickEvents),j(this.selected,"mousedown",function(a){a.preventDefault()}),j(this.optsOptions,"mousedown",function(a){a.preventDefault()}),this.options.searchable&&(j(this.input,"keyup",this.search.bind(this)),j(this.clear,"click",this.clearOptions.bind(this))),j(document,"click",this.handleDismiss),j(document,"keydown",this.handleNavigate),this.update=e(function(){a.setDimensions()},50),j(window,"resize",this.update),j(window,"scroll",this.update)},handleEvents:function(a){a=a||window.event;var b=a.target;b!==this.txt&&b!==this.placeElem||(b=this.placeElem.parentNode),b===this.selected&&(this.disabled||this.toggleOptions()),f(b,"selectr-option")&&this.selectOption(a),f(b,"selectr-tag-remove")&&this.removeTags(a),a.preventDefault()},navigate:function(a){a=a||window.e;var b=this,c=a.keyCode;if(b.opened&&(13===c||38===c||40===c)){a.preventDefault();var e,d=this.searching?this.searchList:this.list;switch(c){case 13:return void b.selectOption(a);case 38:e="up",b.activeIdx>0&&b.activeIdx--;break;case 40:e="down",b.activeIdx<d.length-1&&b.activeIdx++}var f=d[b.activeIdx],i=f.getBoundingClientRect(),j=b.optsOptions.scrollTop,k=window.scrollY||window.pageYOffset,l=b.optsRect.top+k;if("up"===e){var m=l,n=i.top+k,o=j+(n-m);0===b.activeIdx?b.optsOptions.scrollTop=0:n-m<0&&(b.optsOptions.scrollTop=o)}else{var m=l+b.optsRect.height,p=i.top+k+i.height,o=j+p-m;0===b.activeIdx?b.optsOptions.scrollTop=0:p>m&&(b.optsOptions.scrollTop=o)}h(b.optsOptions.getElementsByClassName("active")[0],"active"),g(d[b.activeIdx],"active")}},search:function(a){var b=this,c=b.input.value,e=c.length,f=38===a.keyCode||40===a.keyCode;if(!(e<this.options.minChars&&e>=this.lastLen||f)){if(this.ajaxOpts)return void this.ajaxSearch();this.container.classList.contains("notice")||(c.length>0?g(this.inputContainer,"active"):h(this.inputContainer,"active")),b.searching=!0,b.searchList=[],d(b.opts,function(a,d){let e=b.list[a],f=d.textContent.trim(),i=c.trim();if(f.toLowerCase().includes(i.toLowerCase())){if(b.searchList.push(e),b.hasTemplate)g(e,"match");else{let a=new RegExp(i,"i").exec(f);e.innerHTML=d.textContent.replace(a[0],"<span>"+a[0]+"</span>")}h(e,"excluded")}else g(e,"excluded"),h(e,"match")}),b.searchList.length?this.open():(b.notify("No results."),this.input.focus()),this.lastLen=this.input.value.length}},selectOption:function(a){var b=this,c=a.target,e=this.searching?this.searchList:this.list;if("keydown"===a.type&&(c=e[b.activeIdx]),"LI"===c.nodeName&&!c.classList.contains("disabled")){if(b.ajaxOpts)return void b.selectRemoteOption(c);var f=b.list.indexOf(c),i=b.opts[f],j=!1;if(b.elem.multiple){if(c.classList.contains("selected")){var k;d(b.tags,function(a,b){b.getAttribute("data-value")===i.value&&(k=b)}),k&&b.removeTag(k)}else{if(null!==b.options.maxSelections&&b.selectedVals.length>=b.options.maxSelections)return void b.notify("A maximum of "+b.options.maxSelections+" items can be selected.");b.selectedVals.push(i.value),b.createTag(i),i.selected=!0,g(c,"selected"),b.emit("selectr.select"),b.input.value=""}b.txt.children.length&&(j=!0)}else if(b.selectedIndex===f)b.txt.innerHTML="",i.selected=!1,h(c,"selected"),b.selectedVal=null,b.selectedIndex=null,b.elem.value=null,b.emit("selectr.deselect");else{let a=b.optsOptions.getElementsByClassName("selected")[0];a&&h(a,"selected"),b.txt.innerHTML=b.hasTemplate?b.options.render(i):i.textContent,i.selected=!0,g(c,"selected"),b.selectedVal=i.value,b.selectedIndex=f,b.emit("selectr.select"),j=!0}j?g(b.container,"has-selected"):h(b.container,"has-selected"),b.reset(),b.elem.multiple||b.close(),b.emit("selectr.change")}},ajaxSearch:function(){function f(e){var f=document.createDocumentFragment(),g=document.createDocumentFragment();b.searchList=[],b.opts=[],d(e,function(d,e){let h=a.formatResults(e)||e.text,j=c("li",{class:"selectr-option","data-value":e.value,"data-text":e.text||"",html:h}),k=c("option",{value:e.value});k.textContent=e.text,b.searchList.push(j),b.opts.push(k),i(f,j),i(g,k)}),b.optsOptions.innerHTML="",i(b.optsOptions,f),b.elem.innerHTML="",i(b.elem,g)}this.searching=!0,g(this.inputContainer,"loading");var a=this.options.ajax,b=this,e=new XMLHttpRequest;e.onload=function(){if(4===e.readyState&&200===e.status){var c=JSON.parse(e.responseText);if("function"!=typeof a.parseResults)return;var d=a.parseResults(c);f(d),h(b.inputContainer,"loading"),b.remoteItems=d}},e.open("GET",b.ajax_url+b.input.value,!0),e.send()},selectRemoteOption:function(a){var c,e,f,b=this,i=a.getAttribute("data-value");if(d(b.remoteItems,function(a,d){d.value==i&&(e=d,f=a,c=b.opts[a])}),this.elem.multiple)if(a.classList.contains("selected")&&b.selectedVals.indexOf(i)>-1){var j;d(b.tags,function(a,b){b.getAttribute("data-value")===i&&(j=b)}),j&&b.removeTag(j)}else b.createTag(a,e),b.selectedVals.push(i),b.opts[f].selected=!0,b.emit("selectr.select"),g(a,"selected");else if(b.selectedIndex===f)b.txt.innerHTML="",c.selected=!1,h(a,"selected"),b.selectedVal=null,b.selectedIndex=null,b.elem.value=null,b.emit("selectr.deselect");else{let d=b.optsOptions.getElementsByClassName("selected")[0];d&&h(d,"selected"),b.txt.innerHTML=this.options.ajax.formatSelected(e)||c.getAttribute("data-text")||c.textContent,c.selected=!0,g(a,"selected"),b.selectedVal=c.value,b.selectedIndex=f,b.emit("selectr.select")}this.elem.value?g(this.container,"has-selected"):h(this.container,"has-selected"),this.emit("selectr.select"),this.emit("selectr.change"),this.close()},createTag:function(a,b){var f,e=document.createDocumentFragment();f=b?this.options.ajax.formatSelected(b)||a.getAttribute("data-text")||a.textContent:this.hasTemplate?this.options.render(a):a.textContent;let j=c("li",{class:"selectr-tag",html:f}),k=c("button",{class:"selectr-tag-remove",type:"button"});i(j,k),i(e,j),i(this.txt,e),this.tags.push(j),this.txt.children.length?g(this.container,"has-selected"):h(this.container,"has-selected"),b?j.setAttribute("data-value",a.getAttribute("data-value")):j.setAttribute("data-value",a.value)},removeTags:function(a){this.disabled||(a.preventDefault(),a.stopPropagation(),this.removeTag(a.target.parentNode))},removeTag:function(a){var e,f,b=this,c=a.getAttribute("data-value");d(this.opts,function(a,d){d.value==c&&(f=a,e=b.opts[f])}),e.selected=!1,h(this.list[f],"selected"),this.selectedVals.splice(this.selectedVals.indexOf(e.value),1),this.tags.splice(this.tags.indexOf(a),1),this.txt.removeChild(a),this.tags.length||h(this.container,"has-selected"),this.emit("selectr.deselect")},toggleOptions:function(){var b=this.container.classList.contains("open");b?this.close():this.open()},clearOptions:function(){this.options.searchable&&(this.input.value=null,this.searching=!1,h(this.inputContainer,"active"),h(this.container,"notice"),g(this.container,"open"),this.input.focus()),this.reset()},reset:function(){var a=this;d(this.list,function(b,c){let d=a.opts[b];c.innerHTML=a.hasTemplate?a.options.render(d):d.textContent,h(c,"match"),h(c,"excluded")})},open:function(){var a=this,b=this.elemRect.top+this.elemRect.height+230,c=window.innerHeight;b>c?g(this.container,"inverted"):h(this.container,"inverted"),g(this.container,"open"),h(this.container,"notice"),this.options.searchable&&setTimeout(function(){a.input.focus()},10),this.optsRect=this.optsOptions.getBoundingClientRect(),this.opened=!0,this.ajaxOpts&&(this.searching=!0),this.emit("selectr.open")},close:function(){var a=this.container.classList.contains("notice");this.options.searchable&&!a&&(this.input.blur(),this.searching=!1),a&&(this.container.classList.remove("notice"),this.notice.textContent=""),h(this.container,"open"),this.opened=!1,this.emit("selectr.close")},dismiss:function(a){var b=a.target;this.container.contains(b)||!this.opened&&!this.container.classList.contains("notice")||this.close()},notify:function(a){this.close(),this.container.classList.add("notice"),this.notice.textContent=a},setValue:function(a){var b=this,c=[].slice.call(b.values).indexOf(a);if(!(c<0)){if(b.elem.multiple)b.selectedVals.indexOf(a)<0&&b.createTag(b.opts[c]);else{b.txt.innerHTML=b.hasTemplate?b.options.render(b.opts[c]):b.opts[c].textContent;let a=b.optsOptions.getElementsByClassName("selected")[0];a&&h(a,"selected")}b.selectedVals.push(a),g(b.list[c],"selected"),g(b.container,"has-selected"),b.opts[c].selected=!0,b.emit("selectr.select")}},getValue:function(){return this.elem.multiple?this.selectedVals:this.selectedVal},removeValue:function(a){if(this.tags.length){var b=this,c=[].slice.call(this.values).indexOf(a);if(!(c<0)){var e=this.list[c],f=this.opts[c];if(this.elem.multiple){var g;d(this.tags,function(b,c){c.getAttribute("data-value")===a&&(g=c)}),g&&b.removeTag(g)}else this.txt.innerHTML=this.hasTemplate?this.options.render(f):f.textContent,null!==this.elem.selectedIndex&&h(this.list[this.elem.selectedIndex],"selected");f.selected=!1,h(e,"selected"),this.emit("selectr.select")}}},setDimensions:function(){var a=this.options.width||this.elemRect.width;if("auto"===this.options.width?a="100%":a+="px",this.opened){this.elemRect=this.elem.getBoundingClientRect();var b=this.elemRect.top+this.elemRect.height+230,c=window.innerHeight;this.close(),b>c?g(this.container,"inverted"):h(this.container,"inverted")}this.container.style.cssText+="width: "+a+"; "},emit:function(a){this.elem.dispatchEvent(new Event(a))},enable:function(){this.disabled=!1,h(this.container,"disabled")},disable:function(){this.disabled=!0,g(this.container,"disabled")},destroy:function(){if(this.initialised){var a=this,b=a.container.parentNode;b.insertBefore(a.elem,a.container),b.removeChild(a.container),h(a.elem,"hidden-input"),!a.elem.multiple&&a.options.emptyOption&&a.elem.removeChild(a.elem.options[0]),a.container=null,a.selected=null,a.txt=null,a.optsContainer=null,a.optsOptions=null,a.input=null,a.clear=null,a.inputContainer=null,window.removeEventListener("resize",a.resize),document.removeEventListener("click",a.handleDismiss),document.removeEventListener("keydown",a.handleNavigate),a.initialised=!1}}},k}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
1191
57998