{"version":3,"file":"showon.min.js","names":["akeeba","Showon","a","cont","c","_classCallCheck","self","container","document","fields","showonFields","slice","call","querySelectorAll","length","forEach","field","hasAttribute","setAttribute","localFields","jsondata","getAttribute","showonData","JSON","parse","concat","origin","targets","cField","indexOf","push","value","index","linkedOptions","bind","Object","keys","key","elem","addEventListener","console","log","_createClass","b","itemval","elementShowonDatas","showfield","elementShowonData","condition","valid","originField","name","replace","originId","id","includes","toLowerCase","checked","getElementById","nodeName","Array","from","map","el","tagName","_typeof","val","sign","values","op","disabled","classList","remove","dispatchEvent","CustomEvent","bubbles","add","initialise"],"sources":["showon.js"],"sourcesContent":["/**\n * @package solo\n * @copyright Copyright (c)2014-2024 Nicholas K. Dionysopoulos / Akeeba Ltd\n * @license GNU General Public License version 3, or later\n */\n\nif (typeof akeeba === 'undefined')\n{\n\tvar akeeba = {};\n}\n\n/**\n * Uses Joomla's ShowOn field behaviour with the following copyright notice:\n *\n * @copyright (C) 2018 Open Source Matters, Inc. \n * @license GNU General Public License version 2 or later; see LICENSE.txt\n */\nclass Showon {\n\t/**\n\t * Constructor\n\t *\n\t * @param {HTMLElement} cont Container element\n\t */\n\tconstructor(cont) {\n\t\tconst self = this;\n\t\tthis.container = cont || document;\n\t\tthis.fields = {\n\t\t\t// origin-field-name: {\n\t\t\t// origin: ['collection of all the trigger nodes'],\n\t\t\t// targets: ['collection of nodes to be controlled control']\n\t\t\t// }\n\t\t};\n\n\t\tthis.showonFields = [].slice.call(this.container.querySelectorAll('[data-showon]'));\n\t\t// Populate the fields data\n\t\tif (this.showonFields.length) {\n\t\t\t// @todo refactor this, dry\n\t\t\tthis.showonFields.forEach((field) => {\n\t\t\t\t// Set up only once\n\t\t\t\tif (field.hasAttribute('data-showon-initialised')) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfield.setAttribute('data-showon-initialised', '');\n\n\t\t\t\tconst jsondata = field.getAttribute('data-showon') || '';\n\t\t\t\tconst showonData = JSON.parse(jsondata);\n\t\t\t\tlet localFields;\n\n\t\t\t\tif (showonData.length) {\n\t\t\t\t\tlocalFields = [].slice.call(self.container.querySelectorAll(`[name=\"${showonData[0].field}\"], [name=\"${showonData[0].field}[]\"]`));\n\n\t\t\t\t\tif (!this.fields[showonData[0].field]) {\n\t\t\t\t\t\tthis.fields[showonData[0].field] = {\n\t\t\t\t\t\t\torigin: [],\n\t\t\t\t\t\t\ttargets: [],\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\t// Add trigger elements\n\t\t\t\t\tlocalFields.forEach((cField) => {\n\t\t\t\t\t\tif (this.fields[showonData[0].field].origin.indexOf(cField) === -1) {\n\t\t\t\t\t\t\tthis.fields[showonData[0].field].origin.push(cField);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\t// Add target elements\n\t\t\t\t\tthis.fields[showonData[0].field].targets.push(field);\n\n\t\t\t\t\t// Data showon can have multiple values\n\t\t\t\t\tif (showonData.length > 1) {\n\t\t\t\t\t\tshowonData.forEach((value, index) => {\n\t\t\t\t\t\t\tif (index === 0) {\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlocalFields = [].slice.call(self.container.querySelectorAll(`[name=\"${value.field}\"], [name=\"${value.field}[]\"]`));\n\n\t\t\t\t\t\t\tif (!this.fields[showonData[0].field]) {\n\t\t\t\t\t\t\t\tthis.fields[showonData[0].field] = {\n\t\t\t\t\t\t\t\t\torigin: [],\n\t\t\t\t\t\t\t\t\ttargets: [],\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// Add trigger elements\n\t\t\t\t\t\t\tlocalFields.forEach((cField) => {\n\t\t\t\t\t\t\t\tif (this.fields[showonData[0].field].origin.indexOf(cField) === -1) {\n\t\t\t\t\t\t\t\t\tthis.fields[showonData[0].field].origin.push(cField);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t// Add target elements\n\t\t\t\t\t\t\tif (this.fields[showonData[0].field].targets.indexOf(field) === -1) {\n\t\t\t\t\t\t\t\tthis.fields[showonData[0].field].targets.push(field);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// Do some binding\n\t\t\tthis.linkedOptions = this.linkedOptions.bind(this);\n\n\t\t\t// Attach events to referenced element, to check condition on change and keyup\n\t\t\tObject.keys(this.fields).forEach((key) => {\n\t\t\t\tif (this.fields[key].origin.length) {\n\t\t\t\t\tthis.fields[key].origin.forEach((elem) => {\n\t\t\t\t\t\t// Initialize the showon behaviour for the given HTMLElement\n\t\t\t\t\t\tself.linkedOptions(key);\n\n\t\t\t\t\t\t// Setup listeners\n\t\t\t\t\t\telem.addEventListener('change', () => { self.linkedOptions(key); });\n\t\t\t\t\t\telem.addEventListener('keyup', () => { self.linkedOptions(key); });\n\t\t\t\t\t\telem.addEventListener('click', () => { self.linkedOptions(key); });\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tconsole.log(this.fields);\n\t}\n\n\t/**\n\t *\n\t * @param key\n\t */\n\tlinkedOptions(key) {\n\t\t// Loop through the elements that need to be either shown or hidden\n\t\tthis.fields[key].targets.forEach((field) => {\n\t\t\tconst elementShowonDatas = JSON.parse(field.getAttribute('data-showon')) || [];\n\t\t\tlet showfield = true;\n\t\t\tlet itemval;\n\n\t\t\t// Check if target conditions are satisfied\n\t\t\telementShowonDatas.forEach((elementShowonData, index) => {\n\t\t\t\tconst condition = elementShowonData || {};\n\t\t\t\tcondition.valid = 0;\n\n\t\t\t\t// Test in each of the elements in the field array if condition is valid\n\t\t\t\tthis.fields[key].origin.forEach((originField) => {\n\t\t\t\t\tif (originField.name.replace('[]', '') !== elementShowonData.field) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst originId = originField.id;\n\n\t\t\t\t\t// If checkbox or radio box the value is read from properties\n\t\t\t\t\tif (originField.getAttribute('type') && ['checkbox', 'radio'].includes(originField.getAttribute('type').toLowerCase())) {\n\t\t\t\t\t\tif (!originField.checked) {\n\t\t\t\t\t\t\t// Unchecked fields will return a blank and so always match\n\t\t\t\t\t\t\t// a != condition so we skip them\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\titemval = document.getElementById(originId).value;\n\t\t\t\t\t} else if (originField.nodeName === 'SELECT' && originField.hasAttribute('multiple')) {\n\t\t\t\t\t\titemval = Array.from(originField.querySelectorAll('option:checked')).map((el) => el.value);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Select lists, text-area etc. Note that multiple-select list returns\n\t\t\t\t\t\t// an Array here s0 we can always treat 'itemval' as an array\n\t\t\t\t\t\titemval = document.getElementById(originId).value;\n\t\t\t\t\t\t// A multi-select