/** * Footer Component - i18n-enabled * Shared footer for all Tractatus pages with language persistence */ (function() { 'use strict'; class TractatusFooter { constructor() { this.init(); } init() { console.log('[Footer] Initializing...'); // Listen for i18n initialization event (fired by i18n-simple.js) if (window.I18n && window.I18n.translations && window.I18n.translations.footer) { // i18n already loaded console.log('[Footer] i18n already loaded, rendering immediately'); this.render(); this.attachEventListeners(); } else { // Wait for i18nInitialized event console.log('[Footer] Waiting for i18nInitialized event...'); window.addEventListener('i18nInitialized', () => { console.log('[Footer] i18n initialized event received'); // Double-check translations loaded if (window.I18n && window.I18n.translations && window.I18n.translations.footer) { console.log('[Footer] Footer translations confirmed, rendering'); this.render(); this.attachEventListeners(); } else { console.error('[Footer] Event fired but no footer translations:', window.I18n?.translations); // Render anyway this.render(); this.attachEventListeners(); } }, { once: true }); } } 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); this.applyFooterTranslations(); }); return; // Exit early if DOM not ready } // Apply translations after DOM update this.applyFooterTranslations(); } applyFooterTranslations() { // Use double requestAnimationFrame to ensure DOM is fully painted requestAnimationFrame(() => { requestAnimationFrame(() => { if (window.I18n && window.I18n.applyTranslations) { console.log('[Footer] Applying translations...'); console.log('[Footer] Footer exists:', !!document.querySelector('footer[role="contentinfo"]')); console.log('[Footer] Elements with data-i18n:', document.querySelectorAll('footer[role="contentinfo"] [data-i18n]').length); window.I18n.applyTranslations(); console.log('[Footer] Translations applied'); // Verify a sample translation const aboutHeading = document.querySelector('footer [data-i18n="footer.about_heading"]'); if (aboutHeading) { console.log('[Footer] about_heading element text:', aboutHeading.innerHTML); } } else { console.warn('[Footer] I18n not available for translation'); } }); }); } 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(); } })();