CoreFiles by mySites.guru
joomla-field-switcher.min.js1 lines, 4,426 bytes, from Joomla_4.0.0-alpha7-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha6
md5
79a9264177e039743db99ca57c156d61
sha1
23c3a7b1399b9b5103c246143250ed02a5c185eb
sha256
e7d61a57a3e5da0534b9f34f22648a7ed4f6c6137c730b482cbefe07595b7543
"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-labelledby",`${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);

The same content is in 2 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha8. See them all, or every version of this file.