diff options
Diffstat (limited to 'themes/danix-xyz-hacker/assets/js/theme-toggle.js')
| -rw-r--r-- | themes/danix-xyz-hacker/assets/js/theme-toggle.js | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/theme-toggle.js b/themes/danix-xyz-hacker/assets/js/theme-toggle.js index 3a4fda2..bb95b2a 100644 --- a/themes/danix-xyz-hacker/assets/js/theme-toggle.js +++ b/themes/danix-xyz-hacker/assets/js/theme-toggle.js @@ -1,5 +1,25 @@ document.addEventListener('DOMContentLoaded', function() { const themeToggle = document.getElementById('theme-toggle'); + const sunIcon = document.getElementById('theme-icon-sun'); + const moonIcon = document.getElementById('theme-icon-moon'); + + function updateThemeIcon() { + const isDark = document.documentElement.classList.contains('theme-dark'); + if (sunIcon && moonIcon) { + if (isDark) { + sunIcon.style.display = 'block'; + moonIcon.style.display = 'none'; + } else { + sunIcon.style.display = 'none'; + moonIcon.style.display = 'block'; + } + } + } + + // Update icon on initial load + if (sunIcon && moonIcon) { + updateThemeIcon(); + } if (!themeToggle) { return; @@ -19,23 +39,12 @@ document.addEventListener('DOMContentLoaded', function() { // Add the new theme class htmlElement.classList.add(`theme-${newTheme}`); - // Update article type badge colors - const badges = document.querySelectorAll('[data-theme-dark-color]'); - badges.forEach(badge => { - if (newTheme === 'dark') { - const darkColor = badge.getAttribute('data-theme-dark-color'); - badge.style.color = darkColor; - badge.style.backgroundColor = darkColor + '20'; - } else { - const lightColor = badge.style.color; // Already set to light in HTML - badge.style.color = lightColor; - // backgroundColor stays as is (light color with opacity) - } - }); - // Persist to localStorage localStorage.setItem('theme', newTheme); + // Update icon display + updateThemeIcon(); + // Update Feather Icons if available if (window.feather) { window.feather.replace(); |
