document.addEventListener('click', function(e) { alert('doc click'); }); (function() { // EVENT DELEGATION — works regardless of DOM load order document.addEventListener('click', function(e) { var btn = e.target.closest('.df26-agenda-panel-toggle'); if (!btn) return; var panel = btn.closest('.df26-agenda-panel'); if (!panel) return; var isOpen = panel.classList.contains('is-open'); if (isOpen) { panel.classList.remove('is-open'); btn.setAttribute('aria-expanded', 'false'); } else { panel.classList.add('is-open'); btn.setAttribute('aria-expanded', 'true'); } }); // REVEAL — also delegated via MutationObserver to handle late DOM function initReveal() { var els = document.querySelectorAll('.df26-reveal'); if (!els.length) return; var observer = new IntersectionObserver(function(entries) { entries.forEach(function(entry) { if (entry.isIntersecting) { entry.target.classList.add('is-visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.12 }); els.forEach(function(el) { observer.observe(el); }); } // CAROUSEL — also delegated function initCarousel() { var wrap = document.querySelector('.df25-in-action-carousel-wrap'); if (!wrap) return; var carousel = wrap.querySelector('.df25-in-action-carousel'); var prevBtn = wrap.querySelector('.df25-in-action-arrow-prev'); var nextBtn = wrap.querySelector('.df25-in-action-arrow-next'); if (!carousel || !prevBtn || !nextBtn) return; function getScrollAmount() { var firstCard = carousel.querySelector('.df25-in-action-card'); if (!firstCard) return 320; var gap = parseFloat(getComputedStyle(carousel).columnGap || getComputedStyle(carousel).gap || 24); return firstCard.getBoundingClientRect().width + gap; } function updateButtons() { var maxScrollLeft = carousel.scrollWidth - carousel.clientWidth; prevBtn.classList.toggle('is-disabled', carousel.scrollLeft <= 4); nextBtn.classList.toggle('is-disabled', carousel.scrollLeft >= maxScrollLeft - 4); } prevBtn.addEventListener('click', function() { if (window.innerWidth <= 900) return; carousel.scrollBy({ left: -getScrollAmount(), behavior: 'smooth' }); }); nextBtn.addEventListener('click', function() { if (window.innerWidth <= 900) return; carousel.scrollBy({ left: getScrollAmount(), behavior: 'smooth' }); }); carousel.addEventListener('scroll', updateButtons, { passive: true }); window.addEventListener('resize', updateButtons); updateButtons(); } // MutationObserver watches for DOM changes and inits when content lands var mutationReady = false; var domObserver = new MutationObserver(function() { if (mutationReady) return; var reveals = document.querySelectorAll('.df26-reveal'); var carousel = document.querySelector('.df25-in-action-carousel-wrap'); if (reveals.length) { mutationReady = true; initReveal(); initCarousel(); domObserver.disconnect(); } }); domObserver.observe(document.body, { childList: true, subtree: true }); // Also try immediately and on DOMContentLoaded as fallbacks initReveal(); initCarousel(); document.addEventListener('DOMContentLoaded', function() { initReveal(); initCarousel(); }); })();