mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: change theme
This commit is contained in:
parent
aca521b54f
commit
9426b73940
17 changed files with 326 additions and 21 deletions
|
|
@ -1,3 +1,21 @@
|
|||
function currentTheme() {
|
||||
const attr = document.documentElement.getAttribute('data-theme');
|
||||
if (attr === 'light' || attr === 'dark') return attr;
|
||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
localStorage.setItem('octane-theme', theme);
|
||||
updateThemeToggleIcon();
|
||||
}
|
||||
|
||||
function updateThemeToggleIcon() {
|
||||
const btn = document.getElementById('theme-toggle');
|
||||
if (!btn) return;
|
||||
btn.textContent = currentTheme() === 'dark' ? '☀️' : '🌙';
|
||||
}
|
||||
|
||||
async function initNav(activePage) {
|
||||
const me = await api.get('/api/users/me');
|
||||
const nav = document.getElementById('main-nav');
|
||||
|
|
@ -11,7 +29,11 @@ async function initNav(activePage) {
|
|||
<a href="/history.html" class="${activePage === 'history' ? 'active' : ''}">Historique</a>
|
||||
</div>
|
||||
<div class="nav-user">
|
||||
<span>${escapeHtml(me.name)}${me.isAdmin ? ' <span class="badge">admin</span>' : ''}</span>
|
||||
<button type="button" class="icon-btn secondary" id="theme-toggle" title="Changer de thème" aria-label="Changer de thème"></button>
|
||||
<a class="nav-profile-link" href="/profile.html">
|
||||
${avatarHtml(me, 'avatar-sm')}
|
||||
<span>${escapeHtml(me.name)}${me.isAdmin ? ' <span class="badge">admin</span>' : ''}</span>
|
||||
</a>
|
||||
<a href="/auth/logout">Se déconnecter</a>
|
||||
</div>
|
||||
`;
|
||||
|
|
@ -21,5 +43,10 @@ async function initNav(activePage) {
|
|||
toggle.addEventListener('click', () => links.classList.toggle('open'));
|
||||
links.querySelectorAll('a').forEach((a) => a.addEventListener('click', () => links.classList.remove('open')));
|
||||
|
||||
updateThemeToggleIcon();
|
||||
document.getElementById('theme-toggle').addEventListener('click', () => {
|
||||
applyTheme(currentTheme() === 'dark' ? 'light' : 'dark');
|
||||
});
|
||||
|
||||
return me;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue