optimized js
This commit is contained in:
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user