diff --git a/assets/js/appearance.js b/assets/js/appearance.js index 1af7f713..da3f8a9b 100644 --- a/assets/js/appearance.js +++ b/assets/js/appearance.js @@ -54,12 +54,33 @@ window.addEventListener("DOMContentLoaded", (event) => { const switcher = document.getElementById("appearance-switcher"); const switcherMobile = document.getElementById("appearance-switcher-mobile"); + // Load the i18n translations for the tooltips + const darkLabel = '{{ i18n "footer.dark_appearance" }}'; + const lightLabel = '{{ i18n "footer.light_appearance" }}'; + updateMeta(); this.updateLogo?.(getTargetAppearance()); // Initialize mermaid theme on page load updateMermaidTheme(); + // Helper to update the tooltip depending on the current mode + const updateTooltip = (targetAppearance) => { + // If target is dark, the next action will be switching to light + const label = targetAppearance === "dark" ? lightLabel : darkLabel; + if (switcher) { + switcher.setAttribute("aria-label", label); + switcher.setAttribute("title", label); + } + if (switcherMobile) { + switcherMobile.setAttribute("aria-label", label); + switcherMobile.setAttribute("title", label); + } + }; + + // Set initial tooltip on load + updateTooltip(getTargetAppearance()); + if (switcher) { switcher.addEventListener("click", () => { document.documentElement.classList.toggle("dark"); @@ -70,6 +91,7 @@ window.addEventListener("DOMContentLoaded", (event) => { ); updateMeta(); updateMermaidTheme(); + updateTooltip(targetAppearance); this.updateLogo?.(targetAppearance); }); switcher.addEventListener("contextmenu", (event) => { @@ -87,6 +109,7 @@ window.addEventListener("DOMContentLoaded", (event) => { ); updateMeta(); updateMermaidTheme(); + updateTooltip(targetAppearance); this.updateLogo?.(targetAppearance); }); switcherMobile.addEventListener("contextmenu", (event) => { diff --git a/layouts/partials/header/components/desktop-menu.html b/layouts/partials/header/components/desktop-menu.html index 2ae3c0ef..492d8d13 100644 --- a/layouts/partials/header/components/desktop-menu.html +++ b/layouts/partials/header/components/desktop-menu.html @@ -24,9 +24,10 @@