CoreFiles by mySites.guru
joomla-field-switcher.min.js1 lines, 4,400 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
c40dffb6d417747610bf56247c5d67eb
sha1
2f96902ff55ef23eba8cc797d3abe04ee424036b
sha256
eb629918778be92ba9c541baf4f72ea94d8541f469f99b5c1684fb75433481a3
(t=>{const s={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.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&&this.inputs.length>0)this.addListeners();else{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(t){const s=new CustomEvent(t,{bubbles:!0,cancelable:!0});s.relatedTarget=this,this.dispatchEvent(s),this.removeEventListener(t,this)}createMarkup(){let t=0;this.type||this.setAttribute("type","success");const s=document.createElement("fieldset");s.classList.add("switcher"),s.classList.add(this.type),s.setAttribute("tabindex","0"),s.id=this.id;const e=document.createElement("span");e.classList.add("switch"),e.classList.add(this.type),this.inputs.forEach((e,i)=>{e.setAttribute("tabindex","-1"),e.checked&&s.setAttribute("aria-checked",!0),s.appendChild(e),1===i&&e.checked&&(t=1)}),s.appendChild(e);const i=document.createElement("span");i.classList.add("switcher-labels");const n=document.createElement("span");n.classList.add("switcher-label-0"),n.innerHTML=`${this.offText}`;const a=document.createElement("span");a.classList.add("switcher-label-1"),a.innerHTML=`${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(s),this.appendChild(i),this.initialized=!0}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.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(t){t.keyCode!==s.ENTER&&t.keyCode!==s.SPACE||(t.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(t=>{t.addEventListener("click",this.toggle)}),this.inputsContainer.addEventListener("keydown",this.keyEvents)}removeListeners(){this.inputLabel&&this.inputLabel.removeEventListener("click",this.onFocus),this.inputs.forEach(t=>{t.removeEventListener("click",this.toggle)}),this.inputsContainer.removeEventListener("keydown",this.keyEvents)}})})(customElements);

No other release has this exact content. See every version of this file.