/** * Configuration Object */ const ACCORDION_CONFIG = { selectors: { column: "[new_footer_column]", trigger: "[new_footer_bar]", text: "[new_footer_text]", iconOpen: "[new_footer_icon_open]", iconClose: "[new_footer_icon_close]", list: "[new_footer_list]", firstItem: "[footer_item_first] a", lastItem: "[footer_item_last] a", }, // Mobile Breakpoint (px) - Adjust if needed mobileBreakpoint: 991, // Helper to handle transitions animateIcon: (element, stateClass, isAdding) => { if (!element) return; element.classList.add("footer-is-animating"); void element.offsetWidth; // Force Reflow if (isAdding) { element.classList.add(stateClass); } else { element.classList.remove(stateClass); } setTimeout(() => { element.classList.remove("footer-is-animating"); }, 250); }, onOpen: (elements) => { if (elements.text) elements.text.style.color = "#70FFCB"; ACCORDION_CONFIG.animateIcon(elements.iconOpen, "footer-teal-visible", true); ACCORDION_CONFIG.animateIcon(elements.iconClose, "footer-gray-hidden", true); if (elements.list) { elements.list.classList.remove("hidden"); elements.list.classList.add("footer-list-visible"); elements.list.setAttribute("aria-hidden", "false"); elements.list.removeAttribute("inert"); } if (elements.trigger) elements.trigger.setAttribute("aria-expanded", "true"); }, onClose: (elements) => { if (elements.text) elements.text.style.color = "#fdfcfa"; ACCORDION_CONFIG.animateIcon(elements.iconOpen, "footer-teal-visible", false); ACCORDION_CONFIG.animateIcon(elements.iconClose, "footer-gray-hidden", false); if (elements.list) { elements.list.classList.remove("footer-list-visible"); elements.list.classList.add("hidden"); elements.list.setAttribute("aria-hidden", "true"); elements.list.setAttribute("inert", ""); } if (elements.trigger) elements.trigger.setAttribute("aria-expanded", "false"); }, resetOnResize: true, }; /** * Main Controller Class */ class FooterAccordionController { constructor(config) { this.config = config; this.activeColumn = null; this.columns = document.querySelectorAll(this.config.selectors.column); if (this.columns.length > 0) { this.init(); // Run once on load to set correct initial state this.handleResize(); } } init() { this.columns.forEach((column) => { const trigger = column.querySelector(this.config.selectors.trigger); if (!trigger) return; trigger.addEventListener("click", (e) => this.handleTrigger(e, column)); trigger.addEventListener("keydown", (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); this.handleTrigger(e, column); } }); this.setupAccessibility(column); }); window.addEventListener("resize", this.handleResize.bind(this)); } getElements(column) { return { column: column, trigger: column.querySelector(this.config.selectors.trigger), text: column.querySelector(this.config.selectors.text), iconOpen: column.querySelector(this.config.selectors.iconOpen), iconClose: column.querySelector(this.config.selectors.iconClose), list: column.querySelector(this.config.selectors.list), }; } handleTrigger(e, clickedColumn) { // Prevent interaction on Desktop (optional, usually footer links are just links on desktop) if (window.innerWidth > this.config.mobileBreakpoint) return; const isClickedAlreadyOpen = this.activeColumn === clickedColumn; if (this.activeColumn && !isClickedAlreadyOpen) { this.close(this.activeColumn); } if (isClickedAlreadyOpen) { this.close(clickedColumn); this.activeColumn = null; } else { this.open(clickedColumn); this.activeColumn = clickedColumn; } } open(column) { const els = this.getElements(column); if (els.trigger) this.config.onOpen(els); } close(column) { const els = this.getElements(column); if (els.trigger) this.config.onClose(els); } setupAccessibility(column) { const firstItem = column.querySelector(this.config.selectors.firstItem); const lastItem = column.querySelector(this.config.selectors.lastItem); if (firstItem) { firstItem.addEventListener("keydown", (e) => { if (e.shiftKey && e.key === "Tab") { if (this.activeColumn === column) { this.close(column); this.activeColumn = null; } } }); } if (lastItem) { lastItem.addEventListener("keydown", (e) => { if (!e.shiftKey && e.key === "Tab") { if (this.activeColumn === column) { this.close(column); this.activeColumn = null; } } }); } } /** * UPDATED: Handles Desktop/Mobile Switch */ handleResize() { const isDesktop = window.innerWidth > this.config.mobileBreakpoint; // 1. Reset Active State (Close open accordions if going to desktop) if (this.config.resetOnResize && isDesktop && this.activeColumn) { this.close(this.activeColumn); this.activeColumn = null; } // 2. Global Attribute Management this.columns.forEach(column => { const list = column.querySelector(this.config.selectors.list); if(!list) return; if (isDesktop) { // DESKTOP: Always accessible list.removeAttribute("inert"); // Optional: Ensure it's visible if CSS hides it // list.style.display = 'block'; } else { // MOBILE: Only accessible if it is the currently OPEN column if (this.activeColumn === column) { list.removeAttribute("inert"); } else { list.setAttribute("inert", ""); } } }); } } // --- Initialize --- if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", () => { new FooterAccordionController(ACCORDION_CONFIG); }); } else { new FooterAccordionController(ACCORDION_CONFIG); }