CoreFiles by mySites.guru
joomla-field-fancy-select.min.js1 lines, 5,702 bytes, from Joomla_4.0.0-beta3-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta2
md5
a5970fd522dacfa8293296dde2d2360a
sha1
30ee8d108526ca4241a52878e07c13877c185c1d
sha256
8c3aeda4e6e5c75ef5bef7db8a543f1b037608b5d7e34a85f62eb26951e54e0c
"use strict";window.customElements.define("joomla-field-fancy-select",class 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.setChoiceByValue(a)}constructor(){if(super(),this.keyCode={ENTER:13},!Joomla)throw new Error("Joomla API is not properly initiated");if(!window.Choices)throw new Error("JoomlaFieldFancySelect requires Choices.js to work");this.choicesCache={},this.activeXHR=null,this.choicesInstance=null,this.isDisconnected=!1}connectedCallback(){if(window.Choices||"complete"===document.readyState)this.doConnect();else{const a=()=>{this.doConnect(),window.removeEventListener("load",a)};window.addEventListener("load",a)}}doConnect(){if(this.select=this.querySelector("select"),!this.select)throw new Error("JoomlaFieldFancySelect requires <select> element to work");if(this.choicesInstance)return void(this.isDisconnected&&(this.choicesInstance.init(),this.isDisconnected=!1));if(this.isDisconnected=!1,this.select.multiple&&this.placeholder){const a=document.createElement("option");a.setAttribute("placeholder",""),a.textContent=this.placeholder,this.select.appendChild(a)}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.allowCustom){const a=this.choicesInstance._highlightChoice;this.choicesInstance._highlightChoice=b=>{b&&a.call(this.choicesInstance,b)},this.addEventListener("mouseleave",()=>{if(this.choicesInstance.dropdown.isActive){const a=Array.from(this.choicesInstance.dropdown.element.querySelectorAll(`.${this.choicesInstance.config.classNames.highlightedState}`));a.forEach(a=>{a.classList.remove(this.choicesInstance.config.classNames.highlightedState),a.setAttribute("aria-selected","false")}),this.choicesInstance._highlightPosition=0}}),this.addEventListener("keydown",a=>{if(a.keyCode!==this.keyCode.ENTER||a.target!==this.choicesInstance.input.element)return;if(a.preventDefault(),this.choicesInstance._highlightPosition||!a.target.value)return;const b=this.choicesInstance.dropdown.element.querySelector(`.${this.choicesInstance.config.classNames.highlightedState}`);if(b)return;const c=a.target.value.toLowerCase();let d=!1;return(this.choicesInstance.config.choices.some(a=>(a.value.toLowerCase()===c||a.label.toLowerCase()===c)&&(d=a.value,!0)),!1===d&&Object.keys(this.choicesCache).some(a=>(a.toLowerCase()===c||this.choicesCache[a].toLowerCase()===c)&&(d=a,!0)),!1!==d)?(this.choicesInstance.setChoiceByValue(d),a.target.value=null,void this.choicesInstance.hideDropdown()):(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)})}if(this.remoteSearch&&this.url){this.choicesInstance.config.choices.forEach(a=>{this.choicesCache[a.value]=a.label});let a=null;this.select.addEventListener("search",()=>{clearTimeout(a),a=setTimeout(this.requestLookup.bind(this),300)})}}disconnectedCallback(){this.choicesInstance&&(this.choicesInstance.destroy(),this.isDisconnected=!0),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],c.value=""+c.value,this.choicesCache[c.value]?b.splice(d,1):this.choicesCache[c.value]=c.text;b.length&&this.choicesInstance.setChoices(b,"value","text",!1)},onError:()=>{this.activeXHR=null}})}disableAllOptions(){const{choices:a}=this.choicesInstance._store;a.forEach((b,c)=>{a[c].disabled=!0,a[c].selected=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(a,"value","label",!0)}enableAllOptions(){const{choices:a}=this.choicesInstance._store,b=this.choicesInstance.getValue(!0);a.forEach((b,c)=>{a[c].disabled=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(a,"value","label",!0),this.value=b}disableByValue(a){const{choices:b}=this.choicesInstance._store,c=this.choicesInstance.getValue(!0);b.forEach((c,d)=>{c.value===a&&(b[d].disabled=!0,b[d].selected=!1)});const d=c.indexOf(a);-1<d&&c.slice(d,1),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(b,"value","label",!0),this.value=c}enableByValue(a){const{choices:b}=this.choicesInstance._store,c=this.choicesInstance.getValue(!0);b.forEach((c,d)=>{c.value===a&&(b[d].disabled=!1)}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(b,"value","label",!0),this.value=c}});

The same content is in 3 releases, Joomla 4.0.0-beta2 to 4.0.0-beta4. See them all, or every version of this file.