- md5
- 810bfc43b07e0b1b3c5014be1328eafb
- sha1
- 4f96dcd8e96b8e2b974206c618453ab0bae71971
- sha256
- ab91294c5f7c3b8f9fcf063acbda866177f2f0278d9c2269c8907449edfbad17
(t=>{const e={ENTER:13,SPACE:32};t.define("joomla-field-switcher",class extends HTMLElement{static get observedAttributes(){return["type","off-text","on-text"]}get type(){return this.getAttribute("type")}set type(t){return this.setAttribute("type",t)}get offText(){return this.getAttribute("off-text")||"Off"}get onText(){return this.getAttribute("on-text")||"On"}constructor(){super(),this.inputs=[],this.spans=[],this.inputsContainer="",this.newActive=""}connectedCallback(){if(this.inputs=[].slice.call(this.querySelectorAll("input")),2!==this.inputs.length||"radio"!==this.inputs[0].type)throw new Error('`Joomla-switcher` requires two inputs type="checkbox"');this.createMarkup.bind(this)(),this.inputsContainer=this.firstElementChild,this.inputsContainer.setAttribute("role","switch"),this.inputs[1].checked?(this.inputs[1].parentNode.classList.add("active"),this.spans[1].classList.add("active"),this.inputsContainer.setAttribute("aria-label",this.spans[1].innerHTML)):(this.spans[0].classList.add("active"),this.inputsContainer.setAttribute("aria-label",this.spans[0].innerHTML)),this.inputs.forEach(t=>{t.addEventListener("click",this.toggle.bind(this))}),this.inputsContainer.addEventListener("keydown",this.keyEvents.bind(this))}disconnectedCallback(){this.removeEventListener("joomla.switcher.toggle",this.toggle,!0),this.removeEventListener("click",this.switch,!0),this.removeEventListener("keydown",this.keydown,!0)}dispatchCustomEvent(t){const e=new CustomEvent(t,{bubbles:!0,cancelable:!0});e.relatedTarget=this,this.dispatchEvent(e),this.removeEventListener(t,this)}createMarkup(){let t=0;const e=document.createElement("span");e.classList.add("switcher"),e.setAttribute("tabindex",0),this.type||this.setAttribute("type","success");const s=document.createElement("span");s.classList.add("switch"),this.inputs.forEach((s,i)=>{s.setAttribute("tabindex","-1"),s.checked&&e.setAttribute("aria-checked",!0),e.appendChild(s),1===i&&s.checked&&(t=1)}),e.appendChild(s);const i=document.createElement("span");i.classList.add("switcher-labels");const n=document.createElement("span");n.classList.add("switcher-label-0"),n.innerText=this.offText;const a=document.createElement("span");a.classList.add("switcher-label-1"),a.innerText=this.onText,0===t?n.classList.add("active"):a.classList.add("active"),this.spans.push(n),this.spans.push(a),i.appendChild(n),i.appendChild(a),this.appendChild(e),this.appendChild(i)}switch(){this.spans.forEach(t=>{t.classList.remove("active")}),this.inputsContainer.classList.contains("active")?this.inputsContainer.classList.remove("active"):this.inputsContainer.classList.add("active"),this.inputs.forEach(t=>{t.classList.remove("active")}),1===this.newActive?(this.inputs[this.newActive].classList.add("active"),this.inputs[1].setAttribute("checked",""),this.inputs[0].removeAttribute("checked"),this.inputsContainer.setAttribute("aria-checked",!0),this.inputsContainer.setAttribute("aria-label",this.spans[1].innerHTML),this.dispatchCustomEvent("joomla.switcher.on")):(this.inputs[1].removeAttribute("checked"),this.inputs[0].setAttribute("checked",""),this.inputs[0].classList.add("active"),this.inputsContainer.setAttribute("aria-checked",!1),this.inputsContainer.setAttribute("aria-label",this.spans[0].innerHTML),this.dispatchCustomEvent("joomla.switcher.off")),this.spans[this.newActive].classList.add("active")}toggle(){this.newActive=this.inputs[1].classList.contains("active")?0:1,this.switch.bind(this)()}keyEvents(t){t.keyCode!==e.ENTER&&t.keyCode!==e.SPACE||(t.preventDefault(),this.newActive=this.inputs[1].classList.contains("active")?0:1,this.switch.bind(this)())}})})(customElements);
No other release has this exact content. See every version of this file.