Adds color mode toggle and CSS theming.
This commit is contained in:
26
static/color_mode.js
Normal file
26
static/color_mode.js
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const themeToggle = document.getElementById('bd-theme');
|
||||
|
||||
// Check if a theme preference is saved in localStorage
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
|
||||
if (savedTheme === 'dark') {
|
||||
themeToggle.checked = true;
|
||||
document.documentElement.setAttribute('data-bs-theme', 'dark');
|
||||
} else {
|
||||
themeToggle.checked = false;
|
||||
document.documentElement.setAttribute('data-bs-theme', 'light');
|
||||
}
|
||||
|
||||
// Add event listener to toggle theme on checkbox change
|
||||
themeToggle.addEventListener('change', () => {
|
||||
if (themeToggle.checked) {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'dark');
|
||||
localStorage.setItem('theme', 'dark');
|
||||
} else {
|
||||
document.documentElement.setAttribute('data-bs-theme', 'light');
|
||||
localStorage.setItem('theme', 'light');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user