{"version":3,"file":"overflowExpandableController-24a0dd4a.js","sources":["../../../../app/frontend/components/shared/overflowExpandableController.js"],"sourcesContent":["/*\n This is a controller used to expand and collapse content. It is re-run on window-resize (debounced).\n It expects the following markup:\n [data-expandable]\n - Container element to run the functionality on. Every other element is a child of this element.\n - This element can have the --expandable-height css variable set on it to set the height of the content element.\n - Without proper css classes (setting the max-height of the content element to --expandable-height) this code will not function correctly.\n [data-expandable-activator]\n - Button to to expand/collapse the content.\n - This element has another property of data-toggle-content which has the value to change its content when expanded/closed.\n - Traditionally it is a More/Less text button.\n [data-expandable-content]\n - Element to expand/collapse.\n - This element can have a [data-expandable-height] which contains a pixel value to decide when it should be expanded.\n [data-expandable-match-height]\n - This must be a child element of the content element.\n - If it is present, the content element will be set to the same height as this element.\n - It can also have an optional [data-offset] value to add an additional amount of padding\n */\n(function () {\n const updateHeight = (contentEl, activatorEl, wrapperEl) => {\n let maxHeight = 40; // default\n const childToMatch = contentEl.querySelector('[data-expandable-match-height]');\n if (contentEl.dataset.expandableHeight) {\n maxHeight = parseInt(contentEl.dataset.expandableHeight);\n } else if (childToMatch) {\n const offset = childToMatch.dataset.offset ? parseInt(childToMatch.dataset.offset) : 0;\n maxHeight = childToMatch.getBoundingClientRect().height + offset;\n wrapperEl.style = `--expandable-height: ${maxHeight}px`;\n }\n if (contentEl.scrollHeight > maxHeight) {\n activatorEl.classList.remove('hide');\n } else {\n activatorEl.classList.add('hide');\n }\n }\n ;\n\n const calculateHeights = () => {\n document.querySelectorAll('[data-expandable]').forEach(el => {\n const wrapperEl = el;\n const contentEl = el.querySelector('[data-expandable-content]');\n const activatorEl = el.querySelector('[data-expandable-activator]');\n updateHeight(contentEl, activatorEl, wrapperEl);\n });\n }\n\n calculateHeights();\n\n document.querySelectorAll('[data-expandable]').forEach(el => {\n const contentEl = el.querySelector('[data-expandable-content]');\n const activatorEl = el.querySelector('[data-expandable-activator]');\n activatorEl.addEventListener('click', (e) => {\n e.stopPropagation();\n el.classList.toggle('container-expanded');\n contentEl.classList.toggle('expanded');\n const newContent = activatorEl.dataset.toggleContent;\n activatorEl.dataset.toggleContent = activatorEl.innerText;\n activatorEl.innerText = newContent;\n })\n });\n\n let timeout;\n window.addEventListener('resize', () => {\n // clear the timeout\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(calculateHeights, 250);\n });\n window.addEventListener('custom_event_1', () => {\n // clear the timeout\n if (timeout) {\n clearTimeout(timeout);\n }\n timeout = setTimeout(calculateHeights, 250);\n });\n})()"],"names":["updateHeight","contentEl","activatorEl","wrapperEl","maxHeight","childToMatch","offset","calculateHeights","el","e","newContent","timeout"],"mappings":"CAmBC,UAAY,CACX,MAAMA,EAAe,CAACC,EAAWC,EAAaC,IAAc,CAC1D,IAAIC,EAAY,GAChB,MAAMC,EAAeJ,EAAU,cAAc,gCAAgC,EAC7E,GAAIA,EAAU,QAAQ,iBACpBG,EAAY,SAASH,EAAU,QAAQ,gBAAgB,UAC9CI,EAAc,CACvB,MAAMC,EAASD,EAAa,QAAQ,OAAS,SAASA,EAAa,QAAQ,MAAM,EAAI,EACrFD,EAAYC,EAAa,wBAAwB,OAASC,EAC1DH,EAAU,MAAQ,wBAAwBC,CAAS,IACpD,CACGH,EAAU,aAAeG,EAC3BF,EAAY,UAAU,OAAO,MAAM,EAEnCA,EAAY,UAAU,IAAI,MAAM,CAEnC,EAGKK,EAAmB,IAAM,CAC7B,SAAS,iBAAiB,mBAAmB,EAAE,QAAQC,GAAM,CAC3D,MAAML,EAAYK,EACZP,EAAYO,EAAG,cAAc,2BAA2B,EACxDN,EAAcM,EAAG,cAAc,6BAA6B,EAClER,EAAaC,EAAWC,EAAaC,CAAS,CACpD,CAAK,CACF,EAEDI,IAEA,SAAS,iBAAiB,mBAAmB,EAAE,QAAQC,GAAM,CAC3D,MAAMP,EAAYO,EAAG,cAAc,2BAA2B,EACxDN,EAAcM,EAAG,cAAc,6BAA6B,EAClEN,EAAY,iBAAiB,QAAUO,GAAM,CAC3CA,E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