(function(){"use strict";/** * @copyright (C) 2018 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt */var v=function(){function c(d){var e=this,a=this;this.container=d||document,this.fields={},this.showonFields=[].slice.call(this.container.querySelectorAll("[data-showon]")),this.showonFields.length&&(this.showonFields.forEach(function(t){if(!t.hasAttribute("data-showon-initialised")){t.setAttribute("data-showon-initialised","");var s=t.getAttribute("data-showon")||"",i=JSON.parse(s),o;i.length&&(o=[].slice.call(a.container.querySelectorAll('[name="'+i[0].field+'"], [name="'+i[0].field+'[]"]')),e.fields[i[0].field]||(e.fields[i[0].field]={origin:[],targets:[]}),o.forEach(function(f){e.fields[i[0].field].origin.indexOf(f)===-1&&e.fields[i[0].field].origin.push(f)}),e.fields[i[0].field].targets.push(t),i.length>1&&i.forEach(function(f,h){h!==0&&(o=[].slice.call(a.container.querySelectorAll('[name="'+f.field+'"], [name="'+f.field+'[]"]')),e.fields[i[0].field]||(e.fields[i[0].field]={origin:[],targets:[]}),o.forEach(function(n){e.fields[i[0].field].origin.indexOf(n)===-1&&e.fields[i[0].field].origin.push(n)}),e.fields[i[0].field].targets.indexOf(t)===-1&&e.fields[i[0].field].targets.push(t))}))}}),this.linkedOptions=this.linkedOptions.bind(this),Object.keys(this.fields).forEach(function(t){e.fields[t].origin.length&&e.fields[t].origin.forEach(function(s){a.linkedOptions(t),s.addEventListener("change",function(){a.linkedOptions(t)}),s.addEventListener("keyup",function(){a.linkedOptions(t)}),s.addEventListener("click",function(){a.linkedOptions(t)})})}))}var r=c.prototype;return r.linkedOptions=function(e){var a=this;this.fields[e].targets.forEach(function(t){var s=JSON.parse(t.getAttribute("data-showon"))||[],i=!0,o;s.forEach(function(f,h){var n=f||{};n.valid=0,a.fields[e].origin.forEach(function(l){if(l.name.replace("[]","")===f.field){var p=l.id;if(l.getAttribute("type")&&["checkbox","radio"].includes(l.getAttribute("type").toLowerCase())){if(!l.checked)return;o=document.getElementById(p).value}else l.nodeName==="SELECT"&&l.hasAttribute("multiple")?o=Array.from(l.querySelectorAll("option:checked")).map(function(u){return u.value}):(o=document.getElementById(p).value,o===null&&l.tagName.toLowerCase()==="select"&&(o=[]));typeof o!="object"&&(o=JSON.parse('["'+o+'"]')),o.forEach(function(u){n.sign==="="&&n.values.indexOf(u)!==-1&&(n.valid=1),n.sign==="!="&&n.values.indexOf(u)===-1&&(n.valid=1)})}}),n.op===""?n.valid===0&&(i=!1):(n.op==="AND"&&n.valid+s[h-1].valid<2&&(i=!1,n.valid=0),n.op==="OR"&&n.valid+s[h-1].valid>0&&(i=!0,n.valid=1))}),t.tagName!=="option"?i?(t.classList.remove("hidden"),t.dispatchEvent(new CustomEvent("joomla:showon-show",{bubbles:!0}))):(t.classList.add("hidden"),t.dispatchEvent(new CustomEvent("joomla:showon-hide",{bubbles:!0}))):t.disabled=!i})},c}();if(!window.Joomla)throw new Error("Joomla API is not properly initialized");Joomla.Showon||(Joomla.Showon={initialise:function(r){return new v(r)}}),Joomla.Showon.initialise(document);var g=function(r,d){for(var e=r,a,t=[];e;)a=e.matches&&e.matches(d)?e:null,a&&t.unshift(a),e=e.parentNode;return t};document.addEventListener("joomla:updated",function(c){var r=c.target;if(r.classList.contains("subform-repeatable-group")){var d=[].slice.call(r.querySelectorAll("[data-showon]"));if(d.length){var e=[],a=[];g(r,".subform-repeatable-group").forEach(function(t){e.push(new RegExp("\\["+t.dataset.baseName+"X\\]","g")),a.push("["+t.dataset.group+"]")}),d.forEach(function(t){var s=t.dataset.showon;e.forEach(function(i,o){s=s.replace(i,a[o])}),t.dataset.showon=s})}}Joomla.Showon.initialise(r)})})();