Current File : /home/pacjaorg/.trash/media.1/system/js/fields/joomla-field-fancy-select.min.js
/**
 * @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(){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.placeholder){const t=document.createElement("option");t.setAttribute("placeholder",""),t.textContent=this.placeholder,this.select.appendChild(t)}if(this.choicesInstance=new Choices(this.select,{placeholderValue:this.placeholder,searchPlaceholderValue:this.searchPlaceholder,removeItemButton:!0,searchFloor:this.minTermLength,searchResultLimit:parseInt(this.select.dataset.maxResults,10)||10,renderChoiceLimit:parseInt(this.select.dataset.maxRender,10)||-1,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 t=this.choicesInstance._highlightChoice;this.choicesInstance._highlightChoice=e=>{e&&t.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(s=>{s.classList.remove(this.choicesInstance.config.classNames.highlightedState),s.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 i=e.target.value.toLowerCase();let c=!1;if(this.choicesInstance.config.choices.some(o=>o.value.toLowerCase()===i||o.label.toLowerCase()===i?(c=o.value,!0):!1),c===!1&&Object.keys(this.choicesCache).some(o=>o.toLowerCase()===i||this.choicesCache[o].toLowerCase()===i?(c=o,!0):!1),c!==!1){this.choicesInstance.setChoiceByValue(c),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.config.choices.forEach(s=>{this.choicesCache[s.value]=s.label});const t=300;let e=null;this.select.addEventListener("search",()=>{clearTimeout(e),e=setTimeout(this.requestLookup.bind(this),t)})}}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:e=>{this.activeXHR=null;const s=e?JSON.parse(e):[];if(!s.length)return;let i;for(let c=s.length-1;c>=0;c--)i=s[c],i.value=""+i.value,this.choicesCache[i.value]?s.splice(c,1):this.choicesCache[i.value]=i.text;s.length&&this.choicesInstance.setChoices(s,"value","text",!1)},onError:()=>{this.activeXHR=null}})}disableAllOptions(){const{choices:t}=this.choicesInstance._store;t.forEach((e,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,e=this.choicesInstance.getValue(!0);t.forEach((s,i)=>{t[i].disabled=!1}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(t,"value","label",!0),this.value=e}disableByValue(t){const{choices:e}=this.choicesInstance._store,s=this.choicesInstance.getValue(!0);e.forEach((c,o)=>{c.value===t&&(e[o].disabled=!0,e[o].selected=!1)});const i=s.indexOf(t);i>-1&&s.slice(i,1),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(e,"value","label",!0),this.value=s}enableByValue(t){const{choices:e}=this.choicesInstance._store,s=this.choicesInstance.getValue(!0);e.forEach((i,c)=>{i.value===t&&(e[c].disabled=!1)}),this.choicesInstance.clearStore(),this.choicesInstance.setChoices(e,"value","label",!0),this.value=s}});
Site is undergoing maintenance

PACJA Events

Maintenance mode is on

Site will be available soon. Thank you for your patience!