(function () { 'use strict'; const FAQ = { CLS: { wrap: '.ei-faq', item: '.ei-item', title: '.ei-title', description: '.ei-description', active: 'ei-active' }, DATA: { bound: 'eiFaqBound' }, init(root) { const scope = root && root.jquery ? root[0] : root || document; const faqWraps = scope.querySelectorAll(this.CLS.wrap); if (!faqWraps.length) return; faqWraps.forEach(faqWrap => { const faqItems = faqWrap.querySelectorAll(this.CLS.item); faqItems.forEach(item => { const title = item.querySelector(this.CLS.title); const desc = item.querySelector(this.CLS.description); if (!title || !desc) return; if (item.classList.contains(this.CLS.active)) { desc.style.height = desc.scrollHeight + 'px'; } if (title.dataset[this.DATA.bound]) return; title.dataset[this.DATA.bound] = '1'; title.addEventListener('click', () => { this.closeOthers(faqWrap, item); this.toggle(item, desc); }); }); }); }, toggle(item, desc) { const isActive = item.classList.contains(this.CLS.active); desc.style.height = isActive ? '0px' : desc.scrollHeight + 'px'; item.classList.toggle(this.CLS.active, !isActive); }, closeOthers(faqWrap, currentItem) { const items = faqWrap.querySelectorAll(this.CLS.item); items.forEach(item => { if (item !== currentItem && item.classList.contains(this.CLS.active)) { const desc = item.querySelector(this.CLS.description); desc.style.height = '0px'; item.classList.remove(this.CLS.active); } }); } }; // Frontend if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => FAQ.init(document)); } else { FAQ.init(document); } // Elementor Live Editor window.addEventListener('elementor/frontend/init', () => { if (window.elementorFrontend && elementorFrontend.hooks) { elementorFrontend.hooks.addAction('frontend/element_ready/global', scope => FAQ.init(scope)); } }); // Re-calc on resize (debounced) let faqResizeTimer; window.addEventListener('resize', () => { clearTimeout(faqResizeTimer); faqResizeTimer = setTimeout(() => FAQ.init(document), 150); }); })();