-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththeme.js
More file actions
58 lines (50 loc) · 1.83 KB
/
theme.js
File metadata and controls
58 lines (50 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Theme management
class ThemeManager {
constructor() {
this.THEME_KEY = 'note_app_theme';
this.currentTheme = localStorage.getItem(this.THEME_KEY) || 'light';
this.init();
}
init() {
// Apply saved theme on load
this.applyTheme(this.currentTheme);
// Set up theme toggle button
const themeToggleBtn = document.getElementById('themeToggleBtn');
if (themeToggleBtn) {
themeToggleBtn.addEventListener('click', () => this.toggleTheme());
this.updateThemeButton(themeToggleBtn, this.currentTheme);
}
}
toggleTheme() {
const newTheme = this.currentTheme === 'light' ? 'dark' : 'light';
this.applyTheme(newTheme);
this.currentTheme = newTheme;
localStorage.setItem(this.THEME_KEY, newTheme);
}
applyTheme(theme) {
document.body.classList.remove('theme-light', 'theme-dark');
document.body.classList.add(`theme-${theme}`);
// Update theme toggle button
const themeToggleBtn = document.getElementById('themeToggleBtn');
if (themeToggleBtn) {
this.updateThemeButton(themeToggleBtn, theme);
}
}
updateThemeButton(button, theme) {
const icon = button.querySelector('i');
const text = button.querySelector('span');
if (theme === 'light') {
icon.className = 'fas fa-moon';
text.textContent = 'Dark Mode';
button.title = 'Switch to dark mode';
} else {
icon.className = 'fas fa-sun';
text.textContent = 'Light Mode';
button.title = 'Switch to light mode';
}
}
}
// Initialize theme manager when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.themeManager = new ThemeManager();
});