diff --git a/index.html b/index.html index 052f772..8f6341a 100644 --- a/index.html +++ b/index.html @@ -17,11 +17,15 @@
diff --git a/script.js b/script.js index 45df28f..e541a85 100644 --- a/script.js +++ b/script.js @@ -1,20 +1,31 @@ -// ========== Language Toggle ========== +// ========== Language Switcher (FI / SV / EN) ========== let currentLang = 'fi'; -const langToggle = document.getElementById('langToggle'); -langToggle.addEventListener('click', () => { - currentLang = currentLang === 'fi' ? 'en' : 'fi'; - langToggle.textContent = currentLang.toUpperCase(); - document.documentElement.lang = currentLang; +function switchLanguage(lang) { + currentLang = lang; + document.documentElement.lang = lang; + // Update active button + document.querySelectorAll('.lang-btn').forEach(btn => { + btn.classList.toggle('active', btn.dataset.lang === lang); + }); + + // Update all translatable elements document.querySelectorAll('[data-fi]').forEach(el => { - const text = el.getAttribute(`data-${currentLang}`); + const text = el.getAttribute(`data-${lang}`); if (text) { - if (el.tagName === 'A' || el.tagName === 'BUTTON' || el.tagName === 'P' || el.tagName === 'SPAN' || el.tagName === 'H1' || el.tagName === 'H2' || el.tagName === 'H3' || el.tagName === 'LI') { + if (['A', 'BUTTON', 'P', 'SPAN', 'H1', 'H2', 'H3', 'LI'].includes(el.tagName)) { el.innerHTML = text; } } }); +} + +// Attach click handlers to all lang buttons +document.querySelectorAll('.lang-btn').forEach(btn => { + btn.addEventListener('click', () => { + switchLanguage(btn.dataset.lang); + }); }); // ========== Mobile Navigation ========== @@ -59,7 +70,7 @@ const observer = new IntersectionObserver((entries) => { }, observerOptions); // Add fade-in class to animatable elements -document.querySelectorAll('.theme-card, .region-card, .about-facts li, .section-title, .section-intro').forEach(el => { +document.querySelectorAll('.theme-card, .about-facts li, .section-title, .section-intro').forEach(el => { el.classList.add('fade-in'); observer.observe(el); }); diff --git a/style.css b/style.css index c60440b..04afea5 100644 --- a/style.css +++ b/style.css @@ -128,22 +128,39 @@ ul { color: var(--color-accent); } -.lang-toggle { - background: var(--color-dark); - color: white; - border: none; - padding: 0.4rem 0.8rem; - font-weight: 700; - font-size: 0.75rem; - letter-spacing: 0.05em; +.lang-buttons { + display: flex; + gap: 0; border-radius: 4px; + overflow: hidden; + border: 1px solid var(--color-dark); +} + +.lang-btn { + background: transparent; + color: var(--color-dark); + border: none; + padding: 0.35rem 0.6rem; + font-weight: 700; + font-size: 0.7rem; + letter-spacing: 0.05em; cursor: pointer; - transition: background 0.2s; + transition: all 0.2s; font-family: var(--font); } -.lang-toggle:hover { +.lang-btn:not(:last-child) { + border-right: 1px solid var(--color-dark); +} + +.lang-btn.active { + background: var(--color-dark); + color: white; +} + +.lang-btn:hover:not(.active) { background: var(--color-accent); + color: white; } .hamburger {