CoreFiles by mySites.guru
showon.min.js1 lines, 3,287 bytes, from Joomla_4.0.5-Stable-Full_Package.zip
Raw History Compare with 4.0.4
md5
511fc187be786d66b6d59bf123622c88
sha1
faea9ca18e3e92a6243f66d83d5ff12f01b925bc
sha256
0abe95ecae75a80e5a0ac9aa413555f7e8a06d393ad3a49237ed5bb0f45a8ffe
class Showon{constructor(e){const i=this;this.container=e||document,this.fields={},this.showonFields=[].slice.call(this.container.querySelectorAll("[data-showon]")),this.showonFields.length&&(this.showonFields.forEach((e=>{if(e.hasAttribute("data-showon-initialised"))return;e.setAttribute("data-showon-initialised","");const t=e.getAttribute("data-showon")||"",s=JSON.parse(t);let o;s.length&&(o=[].slice.call(i.container.querySelectorAll(`[name="${s[0].field}"], [name="${s[0].field}[]"]`)),this.fields[s[0].field]||(this.fields[s[0].field]={origin:[],targets:[]}),o.forEach((e=>{-1===this.fields[s[0].field].origin.indexOf(e)&&this.fields[s[0].field].origin.push(e)})),this.fields[s[0].field].targets.push(e),s.length>1&&s.forEach(((t,l)=>{0!==l&&(o=[].slice.call(i.container.querySelectorAll(`[name="${t.field}"], [name="${t.field}[]"]`)),this.fields[s[0].field]||(this.fields[s[0].field]={origin:[],targets:[]}),o.forEach((e=>{-1===this.fields[s[0].field].origin.indexOf(e)&&this.fields[s[0].field].origin.push(e)})),-1===this.fields[s[0].field].targets.indexOf(e)&&this.fields[s[0].field].targets.push(e))})))})),this.linkedOptions=this.linkedOptions.bind(this),Object.keys(this.fields).forEach((e=>{this.fields[e].origin.length&&this.fields[e].origin.forEach((t=>{i.linkedOptions(e),t.addEventListener("change",(()=>{i.linkedOptions(e)})),t.addEventListener("keyup",(()=>{i.linkedOptions(e)})),t.addEventListener("click",(()=>{i.linkedOptions(e)}))}))})))}linkedOptions(e){this.fields[e].targets.forEach((i=>{const t=JSON.parse(i.getAttribute("data-showon"))||[];let s,o=!0;t.forEach(((i,l)=>{const a=i||{};a.valid=0,this.fields[e].origin.forEach((e=>{if(e.name.replace("[]","")!==i.field)return;const t=e.id;if(e.getAttribute("type")&&["checkbox","radio"].includes(e.getAttribute("type").toLowerCase())){if(!e.checked)return;s=document.getElementById(t).value}else"SELECT"===e.nodeName&&e.hasAttribute("multiple")?s=Array.from(e.querySelectorAll("option:checked")).map((e=>e.value)):(s=document.getElementById(t).value,null===s&&"select"===e.tagName.toLowerCase()&&(s=[]));"object"!=typeof s&&(s=JSON.parse(`["${s}"]`)),s.forEach((e=>{"="===a.sign&&-1!==a.values.indexOf(e)&&(a.valid=1),"!="===a.sign&&-1===a.values.indexOf(e)&&(a.valid=1)}))})),""===a.op?0===a.valid&&(o=!1):("AND"===a.op&&a.valid+t[l-1].valid<2&&(o=!1,a.valid=0),"OR"===a.op&&a.valid+t[l-1].valid>0&&(o=!0,a.valid=1))})),"option"!==i.tagName?o?i.classList.remove("hidden"):i.classList.add("hidden"):i.disabled=!o}))}}if(!window.Joomla)throw new Error("Joomla API is not properly initialized");Joomla.Showon||(Joomla.Showon={initialise:e=>new Showon(e)}),Joomla.Showon.initialise(document);const getMatchedParents=(e,i)=>{let t,s=e;const o=[];for(;s;)t=s.matches&&s.matches(i)?s:null,t&&o.unshift(t),s=s.parentNode;return o};document.addEventListener("joomla:updated",(({target:e})=>{if(e.classList.contains("subform-repeatable-group")){const i=[].slice.call(e.querySelectorAll("[data-showon]"));if(i.length){const t=[],s=[];getMatchedParents(e,".subform-repeatable-group").forEach((e=>{t.push(new RegExp(`\\[${e.dataset.baseName}X\\]`,"g")),s.push(`[${e.dataset.group}]`)})),i.forEach((e=>{let{showon:i}=e.dataset;t.forEach(((e,t)=>{i=i.replace(e,s[t])})),e.dataset.showon=i}))}}Joomla.Showon.initialise(e)}));

The same content is in 12 releases, Joomla 4.0.4-rc1 to 4.1.0-alpha2. See them all, or every version of this file.