43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
// Shared header navigation for all pages
|
|
(function(){
|
|
const links = [
|
|
{ href: '/', label: 'Accueil' },
|
|
{ href: '/events', label: 'Événements' },
|
|
{ href: '/admin', label: 'Admin' },
|
|
{ href: '/scoreboard', label: 'Classement' },
|
|
];
|
|
|
|
const path = location.pathname.replace(/\/index\.html$/, '');
|
|
const isActive = (href) => {
|
|
if (href === '/') return path === '/' || path === '';
|
|
return path.startsWith(href);
|
|
};
|
|
|
|
const nav = document.createElement('nav');
|
|
nav.className = 'site-nav';
|
|
nav.innerHTML = links.map(l =>
|
|
`<a href="${l.href}" class="${isActive(l.href) ? 'active' : ''}">${l.label}</a>`
|
|
).join('');
|
|
|
|
let header = document.querySelector('header');
|
|
if (!header) {
|
|
header = document.createElement('header');
|
|
document.body.prepend(header);
|
|
}
|
|
// Basic style if not present (non-intrusive)
|
|
header.style.position = header.style.position || 'sticky';
|
|
header.style.top = header.style.top || '0';
|
|
header.style.zIndex = header.style.zIndex || '4';
|
|
|
|
// Title (keep existing title if present)
|
|
let h1 = header.querySelector('h1');
|
|
if (!h1) {
|
|
h1 = document.createElement('h1');
|
|
h1.textContent = 'Super Sunday';
|
|
header.prepend(h1);
|
|
}
|
|
// Replace or add nav
|
|
const oldNav = header.querySelector('nav');
|
|
if (oldNav) oldNav.replaceWith(nav); else header.appendChild(nav);
|
|
})();
|