/** * Footer Component - i18n-enabled * Shared footer for all Tractatus pages with language persistence */ (function() { 'use strict'; class TractatusFooter { constructor() { this.init(); } init() { // Wait for I18n to be ready before rendering if (window.I18n && window.I18n.translations && Object.keys(window.I18n.translations).length > 0) { this.render(); this.attachEventListeners(); } else { // If I18n not ready, wait for it const checkI18n = setInterval(() => { if (window.I18n && window.I18n.translations && Object.keys(window.I18n.translations).length > 0) { clearInterval(checkI18n); this.render(); this.attachEventListeners(); } }, 100); // Fallback timeout - render without i18n after 2 seconds setTimeout(() => { clearInterval(checkI18n); if (!document.querySelector('footer[role="contentinfo"]')) { this.render(); this.attachEventListeners(); } }, 2000); } } render() { const currentYear = new Date().getFullYear(); // Create footer HTML with data-i18n attributes const footerHTML = ` `; // Insert footer at end of body const existingFooter = document.querySelector('footer[role="contentinfo"]'); if (existingFooter) { existingFooter.outerHTML = footerHTML; } else if (document.body) { document.body.insertAdjacentHTML('beforeend', footerHTML); } else { // If body not ready, wait for DOM document.addEventListener('DOMContentLoaded', () => { document.body.insertAdjacentHTML('beforeend', footerHTML); }); } // Apply translations if I18n is available if (window.I18n && window.I18n.applyTranslations) { window.I18n.applyTranslations(); } } attachEventListeners() { // Listen for language changes and re-render footer window.addEventListener('languageChanged', (event) => { console.log('[Footer] Language changed to:', event.detail.language); this.render(); }); } } // Auto-initialize when DOM is ready if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => new TractatusFooter()); } else { new TractatusFooter(); } })();