- md5
- 783bac560aca65bd9eed17ae6bff02a4
- sha1
- 781433f1f38a0610f835cbc227d04b9fb9daa501
- sha256
- 0f58c18a33f91cb63b6a258629e9ea0f567931d62b92ec630641c2f6ddbfadd3
"use strict";(function(a){"use strict";class b extends HTMLElement{get allowCustom(){return this.hasAttribute("allow-custom")}get remoteSearch(){return this.hasAttribute("remote-search")}get url(){return this.getAttribute("url")}get termKey(){return this.getAttribute("term-key")||"term"}get minTermLength(){return parseInt(this.getAttribute("min-term-length"))||1}get newItemPrefix(){return this.getAttribute("new-item-prefix")||""}get placeholder(){return this.getAttribute("placeholder")}get searchPlaceholder(){return this.getAttribute("search-placeholder")}get value(){return this.choicesInstance.getValue(!0)}set value(a){this.choicesInstance.setValueByChoice(""+a)}connectedCallback(){if(!window.Choices)throw new Error("JoomlaFieldFancySelect require Choices.js to work");if(this.select=this.querySelector("select"),!this.select)throw new Error("JoomlaFieldFancySelect require <select> element to work");if(this.choicesInstance=new Choices(this.select,{placeholderValue:this.placeholder,searchPlaceholderValue:this.searchPlaceholder,removeItemButton:!0,searchFloor:this.minTermLength,searchResultLimit:10,shouldSort:!1,fuseOptions:{threshold:.3},noResultsText:Joomla.Text._("JGLOBAL_SELECT_NO_RESULTS_MATCH","No results found"),noChoicesText:Joomla.Text._("JGLOBAL_SELECT_NO_RESULTS_MATCH","No results found"),itemSelectText:Joomla.Text._("JGLOBAL_SELECT_PRESS_TO_SELECT","Press to select"),classNames:{button:"choices__button_joomla"}}),this.choicesCache={},this.allowCustom&&this.addEventListener("keydown",a=>{if(13===a.keyCode&&a.target===this.choicesInstance.input&&(a.preventDefault(),!(this.choicesInstance.highlightPosition||!a.target.value||this.choicesCache[a.target.value]))){const b=this.choicesInstance.dropdown.querySelector("."+this.choicesInstance.config.classNames.highlightedState);if(!b)return this.choicesInstance.setChoices([{value:this.newItemPrefix+a.target.value,label:a.target.value,selected:!0,customProperties:{value:a.target.value}}],"value","label",!1),this.choicesCache[a.target.value]=a.target.value,a.target.value=null,this.choicesInstance.hideDropdown(),!1}}),this.remoteSearch&&this.url){this.choicesInstance.presetChoices.forEach(a=>{this.choicesCache[a.value]=a.label});let a=null;this.activeXHR=null,this.select.addEventListener("search",()=>{clearTimeout(a),a=setTimeout(this.requestLookup.bind(this),300)})}}disconnectedCallback(){this.choicesInstance&&(this.choicesInstance.destroy(),this.choicesInstance=null),this.activeXHR&&(this.activeXHR.abort(),this.activeXHR=null)}requestLookup(){let a=this.url;a+=-1===a.indexOf("?")?"?":"&",a+=encodeURIComponent(this.termKey)+"="+encodeURIComponent(this.choicesInstance.input.value),this.activeXHR&&this.activeXHR.abort(),this.activeXHR=Joomla.request({url:a,onSuccess:a=>{this.activeXHR=null;const b=a?JSON.parse(a):[];if(!b.length)return;let c;for(let d=b.length-1;0<=d;d--)c=b[d],this.choicesCache[c.value]&&b.splice(d,1);b.length&&this.choicesInstance.setChoices(b,"value","text",!1)},onError:()=>{this.activeXHR=null}})}}a.define("joomla-field-fancy-select",b)})(customElements);
No other release has this exact content. See every version of this file.