- md5
- 2322549bdc97c3311d0a65df7786fb15
- sha1
- 9dda70fbece0e315e2de4cf8a78917aff052d9e1
- sha256
- 02430e40f6fe85e5b8f9a32aadac7d18b84240ab67acaa00ac5a7cf1d898cdbe
"use strict";(a=>{const b={ENTER:13,SPACE:32};class c extends HTMLElement{static get observedAttributes(){return["type","off-text","on-text"]}get type(){return this.getAttribute("type")}set type(a){return this.setAttribute("type",a)}get offText(){return this.getAttribute("off-text")||"Off"}get onText(){return this.getAttribute("on-text")||"On"}constructor(){super(),this.inputs=[],this.spans=[],this.initialized=!1,this.inputsContainer="",this.newActive="",this.inputLabel="",this.inputLabelText="",this.createMarkup=this.createMarkup.bind(this),this.addListeners=this.addListeners.bind(this),this.removeListeners=this.removeListeners.bind(this),this.switch=this.switch.bind(this),this.toggle=this.toggle.bind(this),this.keyEvents=this.keyEvents.bind(this),this.onFocus=this.onFocus.bind(this)}connectedCallback(){if(this.initialized&&0<this.inputs.length)return void this.addListeners();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=\"radio\"");this.createMarkup(),this.inputsContainer=this.inputs[0].parentNode,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-labeledby",`${this.id}-lbl`)):(this.spans[0].classList.add("active"),this.inputsContainer.setAttribute("aria-label",this.spans[0].innerHTML)),this.addListeners()}disconnectedCallback(){this.removeListeners()}dispatchCustomEvent(a){const b=new CustomEvent(a,{bubbles:!0,cancelable:!0});b.relatedTarget=this,this.dispatchEvent(b),this.removeEventListener(a,this)}createMarkup(){let a=0;this.type||this.setAttribute("type","success");const b=document.createElement("fieldset");b.classList.add("switcher"),b.classList.add(this.type),b.setAttribute("tabindex","0"),b.id=this.id;const c=document.createElement("span");c.classList.add("switch"),c.classList.add(this.type),this.inputs.forEach((c,d)=>{c.setAttribute("tabindex","-1"),c.checked&&b.setAttribute("aria-checked",!0),b.appendChild(c),1===d&&c.checked&&(a=1)}),b.appendChild(c);const d=document.createElement("span");d.classList.add("switcher-labels");const e=document.createElement("span");e.classList.add("switcher-label-0"),e.innerHTML=`${this.offText}`;const f=document.createElement("span");f.classList.add("switcher-label-1"),f.innerHTML=`${this.onText}`,0==a?e.classList.add("active"):f.classList.add("active"),this.spans.push(e),this.spans.push(f),d.appendChild(e),d.appendChild(f),this.appendChild(b),this.appendChild(d),this.initialized=!0}switch(){this.spans.forEach(a=>{a.classList.remove("active")}),this.inputsContainer.classList.contains("active")?this.inputsContainer.classList.remove("active"):this.inputsContainer.classList.add("active"),this.inputs.forEach(a=>{a.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.inputLabelText} ${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.inputLabelText} ${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()}keyEvents(a){(a.keyCode===b.ENTER||a.keyCode===b.SPACE)&&(a.preventDefault(),this.newActive=this.inputs[1].classList.contains("active")?0:1,this.switch())}onFocus(){this.inputsContainer.focus()}addListeners(){this.inputLabel&&this.inputLabel.addEventListener("click",this.onFocus),this.inputs.forEach(a=>{a.addEventListener("click",this.toggle)}),this.inputsContainer.addEventListener("keydown",this.keyEvents)}removeListeners(){this.inputLabel&&this.inputLabel.removeEventListener("click",this.onFocus),this.inputs.forEach(a=>{a.removeEventListener("click",this.toggle)}),this.inputsContainer.removeEventListener("keydown",this.keyEvents)}}a.define("joomla-field-switcher",c)})(customElements);
No other release has this exact content. See every version of this file.