diff --git a/content/header/index.md b/content/header/index.md index 96e9d970f..67194b90d 100644 --- a/content/header/index.md +++ b/content/header/index.md @@ -3,7 +3,8 @@ title: "Header" insert_anchor_links: "left" template: "partials/header.html" extra: - logoPath: "images/new_logo_tft_light.png" + logoPathLight: "images/new_logo_tft_light.png" + logoPathDark: "images/new_logo_tft_dark.png" --- diff --git a/static/js/custom.js b/static/js/custom.js index 481a7d2b7..adbbbfcb9 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -194,36 +194,32 @@ document.getElementById("year").innerHTML = new Date().getFullYear(); +// Get the toggle switch and the logo element +const toggleSwitch = document.getElementById('darkModeSwitch'); +const siteLogo = document.getElementById('site-logo'); + +// Apply the saved theme on load document.addEventListener('DOMContentLoaded', () => { - const toggleSwitch = document.getElementById('darkModeSwitch'); - const logo = document.getElementById('logo'); - - // Log the current state for debugging - console.log('Light logo:', logo.getAttribute('data-light-logo')); - console.log('Dark logo:', logo.getAttribute('data-dark-logo')); - const savedTheme = localStorage.getItem('theme'); if (savedTheme === 'dark') { - document.body.classList.add('dark-mode'); - toggleSwitch.checked = true; - logo.src = logo.getAttribute('data-dark-logo'); - console.log('Loaded dark mode with dark logo.'); + document.body.classList.add('dark-mode'); + toggleSwitch.checked = true; + siteLogo.src = siteLogo.getAttribute('data-dark'); } else { - logo.src = logo.getAttribute('data-light-logo'); - console.log('Loaded light mode with light logo.'); + document.body.classList.remove('dark-mode'); + siteLogo.src = siteLogo.getAttribute('data-light'); + } +}); + +// Toggle dark mode +toggleSwitch.addEventListener('change', () => { + if (toggleSwitch.checked) { + document.body.classList.add('dark-mode'); + localStorage.setItem('theme', 'dark'); + siteLogo.src = siteLogo.getAttribute('data-dark'); + } else { + document.body.classList.remove('dark-mode'); + localStorage.setItem('theme', 'light'); + siteLogo.src = siteLogo.getAttribute('data-light'); } - - toggleSwitch.addEventListener('change', () => { - if (toggleSwitch.checked) { - document.body.classList.add('dark-mode'); - localStorage.setItem('theme', 'dark'); - logo.src = logo.getAttribute('data-dark-logo'); - console.log('Switched to dark mode. Updated logo to dark.'); - } else { - document.body.classList.remove('dark-mode'); - localStorage.setItem('theme', 'light'); - logo.src = logo.getAttribute('data-light-logo'); - console.log('Switched to light mode. Updated logo to light.'); - } - }); }); diff --git a/templates/partials/header.html b/templates/partials/header.html index 2dced2bcf..78b988edd 100644 --- a/templates/partials/header.html +++ b/templates/partials/header.html @@ -6,16 +6,15 @@
- - + +