CoreFiles by mySites.guru
joomla-field-fancy-select.min.js4 lines, 6,407 bytes, from Joomla_6.2.1-Stable-Full_Package.zip
Raw History Compare with 6.2.0
md5
73a3a3a67c92d8e9385a30b1b98f3194
sha1
5d4229ac65e2b3509a0fdf02d183004ffb8812b3
sha256
485dce8580e49c597217052a1f3771a3eb9ca574f028b2bbbb2d604b0198be72
/**
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */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"),10)||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(t){this.choicesInstance.setChoiceByValue(t)}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||document.readyState==="complete")this.doConnect();else{const t=()=>{this.doConnect(),window.removeEventListener("load",t)};window.addEventListener("load",t)}}doConnect(){var t,i;if(this.select=this.querySelector("select"),!this.select)throw new Error("JoomlaFieldFancySelect requires <select> element to work");if(this.choicesInstance){this.isDisconnected&&(this.choicesInstance.init(),this.choicesInstance.setChoiceByValue(this.disconnectValues),this.isDisconnected=!1);return}if(this.isDisconnected=!1,!this.select.multiple&&this.select.options.length&&this.select.selectedIndex===0&&!this.select.querySelector("option[selected]")&&(this.select.options[0].selected=!0,this.select.options[0].setAttribute("selected","")),this.choicesInstance=new Choices(this.select,{placeholderValue:this.placeholder,searchPlaceholderValue:this.searchPlaceholder,appendGroupInSearch:!0,removeItemButton:!0,searchFloor:this.minTermLength,searchResultLimit:parseInt(this.select.dataset.maxResults,10)||10,renderChoiceLimit:parseInt(this.select.dataset.maxRender,10)||-1,renderSelectedChoices:"always",shouldSort:!1,fuseOptions:{threshold:.3,distance:850},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"},labelId:(t=(i=this.select.labels)==null||(i=i[0])==null?void 0:i.id)!=null?t:""}),this.allowCustom){const s=this.choicesInstance._highlightChoice;this.choicesInstance._highlightChoice=e=>{e&&s.call(this.choicesInstance,e)},this.addEventListener("mouseleave",()=>{if(!this.choicesInstance.dropdown.isActive)return;Array.from(this.choicesInstance.dropdown.element.querySelectorAll(`.${this.choicesInstance.config.classNames.highlightedState}`)).forEach(c=>{c.classList.remove(this.choicesInstance.config.classNames.highlightedState),c.setAttribute("aria-selected","false")}),this.choicesInstance._highlightPosition=0}),this.addEventListener("keydown",e=>{if(e.keyCode!==this.keyCode.ENTER||e.target!==this.choicesInstance.input.element||(e.preventDefault(),this.choicesInstance._highlightPosition||!e.target.value)||this.choicesInstance.dropdown.element.querySelector(`.${this.choicesInstance.config.classNames.highlightedState}`))return;const o=e.target.value.toLowerCase();let h=!1;if(this.choicesInstance.config.choices.some(l=>l.value.toLowerCase()===o||l.label.toLowerCase()===o?(h=l.value,!0):!1),h===!1&&Object.keys(this.choicesCache).some(l=>l.toLowerCase()===o||this.choicesCache[l].toLowerCase()===o?(h=l,!0):!1),h!==!1){this.choicesInstance.setChoiceByValue(h),e.target.value=null,this.choicesInstance.hideDropdown();return}this.choicesInstance.setChoices([{value:new DOMParser().parseFromString(this.newItemPrefix+e.target.value,"text/html").body.textContent,label:new DOMParser().parseFromString(e.target.value,"text/html").body.textContent,selected:!0,customProperties:{value:e.target.value}}],"value","label",!1),this.choicesCache[e.target.value]=e.target.value,e.target.value=null,this.choicesInstance.hideDropdown()})}if(this.remoteSearch&&this.url){this.choicesInstance.passedElement.optionsAsChoices().forEach(c=>{c.value!==void 0&&(this.choicesCache[c.value]=c.label)});const s=300;let e=null;this.select.addEventListener("search",()=>{clearTimeout(e),e=setTimeout(this.requestLookup.bind(this),s)})}}disconnectedCallback(){this.choicesInstance&&(this.disconnectValues=this.choicesInstance.getValue(!0),this.choicesInstance.destroy(),this.isDisconnected=!0),this.activeXHR&&(this.activeXHR.abort(),this.activeXHR=null)}requestLookup(){let{url:t}=this;t+=t.indexOf("?")===-1?"?":"&",t+=`${encodeURIComponent(this.termKey)}=${encodeURIComponent(this.choicesInstance.input.value)}`,this.activeXHR&&this.activeXHR.abort(),this.activeXHR=Joomla.request({url:t,onSuccess:i=>{this.activeXHR=null;const s=i?JSON.parse(i):[];if(!s.length)return;let e;for(let c=s.length-1;c>=0;c--)e=s[c],e.value=""+e.value,this.choicesCache[e.value]?s.splice(c,1):this.choicesCache[e.value]=e.text;s.length&&this.choicesInstance.setChoices(s,"value","text",!1)},onError:()=>{this.activeXHR=null}})}disableAllOptions(){const{choices:t}=this.choicesInstance._store;t.forEach((i,s)=>{t[s].disabled=!0,t[s].selected=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(t,"value","label",!0)}enableAllOptions(){const{choices:t}=this.choicesInstance._store,i=this.choicesInstance.getValue(!0);t.forEach((s,e)=>{t[e].disabled=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(t,"value","label",!0),this.value=i}disableByValue(t){const{choices:i}=this.choicesInstance._store,s=this.choicesInstance.getValue(!0);i.forEach((c,o)=>{c.value===t&&(i[o].disabled=!0,i[o].selected=!1)});const e=s.indexOf(t);e>-1&&s.slice(e,1),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(i,"value","label",!0),this.value=s}enableByValue(t){const{choices:i}=this.choicesInstance._store,s=this.choicesInstance.getValue(!0);i.forEach((e,c)=>{e.value===t&&(i[c].disabled=!1)}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(i,"value","label",!0),this.value=s}});

The same content is in 3 releases, Joomla 6.2.1-rc1 to 6.3.0-alpha1. See them all, or every version of this file.