mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-10-06 13:36:10 +08:00
fix(ui): split theme & icon load to prevent flicker, errors
Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
This commit is contained in:
parent
a0ce2c1bec
commit
3f3ae167e9
2 changed files with 16 additions and 5 deletions
|
@ -10,17 +10,28 @@ function toggleTheme() {
|
||||||
themeIcon.textContent = newTheme === 'dark' ? '☀️' : '🌙'; // Switch between moon and sun icons
|
themeIcon.textContent = newTheme === 'dark' ? '☀️' : '🌙'; // Switch between moon and sun icons
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to apply saved theme from localStorage
|
// Function to immediately apply saved theme without icon update
|
||||||
function applySavedTheme() {
|
function applySavedThemeImmediately() {
|
||||||
const savedTheme = localStorage.getItem('theme');
|
const savedTheme = localStorage.getItem('theme');
|
||||||
if (savedTheme === 'dark') {
|
if (savedTheme === 'dark') {
|
||||||
document.documentElement.setAttribute('data-theme', 'dark');
|
document.documentElement.setAttribute('data-theme', 'dark');
|
||||||
|
} else {
|
||||||
|
document.documentElement.removeAttribute('data-theme'); // Default to light theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to apply theme-icon update
|
||||||
|
function setThemeIcon() {
|
||||||
|
const savedTheme = localStorage.getItem('theme');
|
||||||
|
if (savedTheme === 'dark') {
|
||||||
document.getElementById('theme-icon').textContent = '☀️'; // Sun icon for dark mode
|
document.getElementById('theme-icon').textContent = '☀️'; // Sun icon for dark mode
|
||||||
} else {
|
} else {
|
||||||
document.documentElement.removeAttribute('data-theme'); // Default to light theme (no data-theme)
|
|
||||||
document.getElementById('theme-icon').textContent = '🌙'; // Moon icon for light mode
|
document.getElementById('theme-icon').textContent = '🌙'; // Moon icon for light mode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Immediately apply the saved theme to avoid flickering
|
||||||
|
applySavedThemeImmediately();
|
||||||
|
|
||||||
// Apply theme when the page loads
|
// Apply theme when the page loads
|
||||||
document.addEventListener('DOMContentLoaded', applySavedTheme);
|
document.addEventListener('DOMContentLoaded', setThemeIcon);
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="loader"></div>
|
<div class="loader"></div>
|
||||||
</div>
|
</div>
|
||||||
<button id="theme-toggle" onclick="toggleTheme()">
|
<button id="theme-toggle" onclick="toggleTheme()">
|
||||||
<span id="theme-icon">🌙</span>
|
<span id="theme-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Reference in a new issue