optimized js

This commit is contained in:
speyll
2025-04-25 01:55:36 +01:00
parent d66ba827e1
commit 25837942fc
6 changed files with 224 additions and 4 deletions

View File

@@ -2,17 +2,17 @@ class ThemeManager {
constructor() {
this.toggle = document.getElementById('theme-toggle');
if (!this.toggle) return;
this.icon = document.getElementById('theme-icon');
const { iconBase, iconDark, iconLight, soundSrc } = this.toggle.dataset;
this.iconBase = iconBase;
this.iconDark = iconDark;
this.iconLight = iconLight;
// Create audio element lazily only when needed
this.sound = null;
this.soundSrc = soundSrc;
this.init();
}
@@ -31,6 +31,7 @@ class ThemeManager {
}
toggleTheme() {
document.body.classList.add('theme-transition');
const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
const newTheme = isDark ? 'light' : 'dark';
@@ -57,7 +58,7 @@ class ThemeManager {
updateIcon(isDark) {
if (this.icon) {
this.icon.setAttribute('href',
this.icon.setAttribute('href',
`${this.iconBase}${isDark ? this.iconDark : this.iconLight}`);
}
}