function t_faq_init(recId) { var rec = document.getElementById('rec' + recId); if (!rec) return; var togglers = rec.querySelectorAll('.t_faq__header'); var isLazy = document.getElementById('allrecords').getAttribute('data-tilda-lazy'); var accordion = rec.querySelector('.t_faq__accordion'); var cachedHeight = 0; var cachedTop = 0; if (accordion) { accordion = accordion.getAttribute('data-accordion'); } else { accordion = 'false'; } Array.prototype.forEach.call(togglers, function (toggler) { toggler.addEventListener('click', function () { var target = toggler; var content = target.nextElementSibling; var triggerButton = target.querySelector('.t_faq__trigger-button'); if (accordion === 'true') { Array.prototype.forEach.call(togglers, function (header) { if (target !== header) { header.classList.remove('t_faq__header_opened'); t_faq_slideUp(header.nextElementSibling, target); } }); } if (triggerButton) { var isExpanded = triggerButton.getAttribute('aria-expanded') === 'true'; triggerButton.setAttribute('aria-expanded', !isExpanded); content.hidden = isExpanded; } target.classList.toggle('t_faq__header_opened'); target.style.pointerEvents = 'none'; t_faq_slideToggle(target.nextElementSibling, target); if (window.lazy === 'y' || isLazy === 'yes') { t_onFuncLoad('t_lazyload_update', function () { t_lazyload_update(); }); } }); }); function t_faq_slideToggle(target, triggerElement, duration) { if (!target) return; if (!duration && duration !== 0) duration = 300; if (window.getComputedStyle(target).display === 'none') { t_faq_slideDown(target, triggerElement, duration); } else { cachedHeight = 0; t_faq_slideUp(target, triggerElement, duration); } } function t_faq_slideUp(target, triggerElement, duration) { if (!target) return; if (!duration && duration !== 0) duration = 300; target.style.transitionProperty = 'height, margin, padding'; target.style.transitionDuration = duration + 'ms'; target.style.boxSizing = 'border-box'; target.style.height = target.offsetHeight + 'px'; target.offsetHeight; target.style.overflow = 'hidden'; target.style.height = '0'; target.style.paddingTop = '0'; target.style.paddingBottom = '0'; target.style.marginTop = '0'; target.style.marginBottom = '0'; setTimeout(function () { triggerElement.style.pointerEvents = 'auto'; target.style.display = 'none'; target.style.height = ''; target.style.paddingTop = ''; target.style.paddingBottom = ''; target.style.marginTop = ''; target.style.marginBottom = ''; target.style.overflow = ''; target.style.transitionDuration = ''; target.style.transitionProperty = ''; }, duration); } function t_faq_slideDown(target, triggerElement, duration) { if (!target) return; if (!duration && duration !== 0) duration = 300; target.style.display = ''; var cashedDisplay = window.getComputedStyle(target).display; if (cashedDisplay === 'none') cashedDisplay = 'block'; target.style.display = cashedDisplay; var targetHeight = target.offsetHeight; var targetTop = target.offsetTop; if (window.visualViewport){ var visibleTop = targetTop - window.visualViewport.pageTop; if (cachedTop && accordion === 'true' && targetTop > cachedTop && window.scrollY > cachedTop) { window.scrollTo(window.scrollX, targetTop - cachedHeight - visibleTop); } } target.style.overflow = 'hidden'; target.style.height = '0'; target.style.paddingTop = '0'; target.style.paddingBottom = '0'; target.style.marginTop = '0'; target.style.marginBottom = '0'; target.offsetHeight; target.style.boxSizing = 'border-box'; target.style.transitionProperty = 'height, margin, padding'; target.style.transitionDuration = duration + 'ms'; target.style.height = targetHeight + 'px'; target.style.paddingTop = ''; target.style.paddingBottom = ''; target.style.marginTop = ''; target.style.marginBottom = ''; setTimeout(function () { triggerElement.style.pointerEvents = 'auto'; target.style.height = ''; target.style.overflow = ''; target.style.transitionDuration = ''; target.style.transitionProperty = ''; cachedHeight = targetHeight; cachedTop = targetTop; }, duration); } }