Malý repozitář do hodin WTL pro 3.J skupinu WEB
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

33 lines
1.2 KiB

// Funkce pro přepnutí tématu
document.addEventListener('DOMContentLoaded', function () {
const themeToggle = document.getElementById('bd-theme');
const themeButtons = document.querySelectorAll('[data-bs-theme-value]');
const root = document.documentElement;
// Nastavení aktuálního tématu
function setTheme(theme) {
root.setAttribute('data-bs-theme', theme);
localStorage.setItem('theme', theme); // Uloží výběr do localStorage
updateActiveButton(theme);
}
// Aktualizace aktivního tlačítka
function updateActiveButton(theme) {
themeButtons.forEach(button => {
const isActive = button.getAttribute('data-bs-theme-value') === theme;
button.setAttribute('aria-pressed', isActive);
});
}
// Načtení uloženého tématu (pokud existuje)
const storedTheme = localStorage.getItem('theme') || 'auto';
setTheme(storedTheme);
// Přidání události pro kliknutí na tlačítka
themeButtons.forEach(button => {
button.addEventListener('click', function () {
const theme = this.getAttribute('data-bs-theme-value');
setTheme(theme);
});
});
});