mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 06:26:57 +00:00
fix(ui): ensure theme-toggle button is visible on first visit
Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
This commit is contained in:
parent
2b6e81c074
commit
a5b25ab56b
2 changed files with 13 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Function to toggle theme
|
||||
function toggleTheme() {
|
||||
const currentTheme = document.documentElement.getAttribute('data-theme');
|
||||
const newTheme = (currentTheme === 'dark') ? 'light' : 'dark';
|
||||
const newTheme = (currentTheme === 'dark') ? '' : 'dark'; // Toggle between no theme and dark theme
|
||||
document.documentElement.setAttribute('data-theme', newTheme);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
|
||||
|
|
@ -13,14 +13,14 @@ function toggleTheme() {
|
|||
// Function to apply saved theme from localStorage
|
||||
function applySavedTheme() {
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme) {
|
||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||
|
||||
// Ensure the icon is set correctly based on the saved theme
|
||||
const themeIcon = document.getElementById('theme-icon');
|
||||
themeIcon.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
|
||||
if (savedTheme === 'dark') {
|
||||
document.documentElement.setAttribute('data-theme', 'dark');
|
||||
document.getElementById('theme-icon').textContent = '☀️'; // Sun icon for dark mode
|
||||
} else {
|
||||
document.documentElement.removeAttribute('data-theme'); // Default to light theme (no data-theme)
|
||||
document.getElementById('theme-icon').textContent = '🌙'; // Moon icon for light mode
|
||||
}
|
||||
}
|
||||
|
||||
// Apply theme when the page loads
|
||||
document.addEventListener('DOMContentLoaded', applySavedTheme);
|
||||
// Immediately apply the saved theme
|
||||
applySavedTheme();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue