/** * Legal Pages Helper * * Dynamically injects a common header (topbar) and language-aware footer * into all 6 legal pages to eliminate HTML duplication. * * Reuses language detection and switching utilities from shared modules. * Uses event delegation for language links so they work on injected elements. */ (function(){ "use strict"; // Local constant for storing page language preference in localStorage var LANG_KEY = "legalLang"; /** * Build URL to alternate language page. * Supports both -en.html and -ro.html naming patterns. */ function targetPage(current, lang){ if(current.indexOf('-ro.html') !== -1) return current.replace('-ro.html', '-' + lang + '.html'); if(current.indexOf('-en.html') !== -1) return current.replace('-en.html', '-' + lang + '.html'); return current; } /** * Get current page base name (terms, privacy, cookies). */ function basePage(){ var path = window.location.pathname; if(path.indexOf('terms') !== -1) return 'terms'; if(path.indexOf('privacy') !== -1) return 'privacy'; if(path.indexOf('cookies') !== -1) return 'cookies'; return ''; } /** * Detect page language (EN or RO). */ function pageLang(){ return window.location.pathname.indexOf('-ro.html') !== -1 ? 'ro' : 'en'; } /** * Inject topbar with logo and language switcher. * Uses pageLang() to determine current page language and set active state. */ function injectTopbar(){ var base = basePage(); var lang = pageLang(); var html = '
' + '' + 'MyAi.ro' + '' + (lang === 'ro' ? 'Înapoi' : 'Back') + '' + '' + '
' + '' + 'Română' + '' + '' + 'English' + '' + '
' + '
'; $('.wrap').prepend(html); } /** * Inject language-aware footer with copyright and legal links. * Footer text and links vary by current page language (EN vs RO). */ function injectFooter(){ var lang = pageLang(); var copyrightText = lang === 'ro' ? '©2026 myAi. Toate drepturile sunt rezervate.' : '©2026 myAi. All rights reserved.'; var linksHtml = ''; if(lang === 'ro'){ linksHtml = 'Termeni și condiții' + 'Politica de confidențialitate' + 'Politica de COOKIES'; } else { linksHtml = 'Terms and Conditions' + 'Privacy Policy' + 'Cookies Policy'; } var html = ''; $('.wrap').append(html); } /** * Initialize language persistence and inject topbar/footer. */ function init(){ localStorage.setItem(LANG_KEY, pageLang()); injectTopbar(); injectFooter(); } /** * Handle language link clicks with event delegation. * Works on both static and dynamically injected language links. * Updates localStorage and navigates to the target language page. */ document.addEventListener('click', function(e){ var link = e.target.closest('.lang-link'); if(!link) return; e.preventDefault(); localStorage.setItem(LANG_KEY, link.getAttribute('data-lang')); window.location.href = targetPage(window.location.pathname, link.getAttribute('data-lang')); }); /* ============================================================ PAGE INITIALIZATION ============================================================ */ // Initialize topbar and footer injection on DOM ready if(document.readyState === 'loading'){ document.addEventListener('DOMContentLoaded', init); } else { init(); } })();