css: navbar link improvements

This commit is contained in:
AdrienLSH 2024-03-31 23:24:06 +02:00
parent 927748a13d
commit 55eb47a4e5

View File

@ -134,16 +134,23 @@ const router = async(uri) => {
return 0; return 0;
}; };
window.addEventListener("popstate", function() {router(location.pathname);}); window.addEventListener("popstate", async function() {
if (await router(location.pathname))
return;
console.log(window.location.pathname)
document.querySelector('.nav-link.active')?.classList.remove('active');
document.querySelector(`.nav-link[href='${window.location.pathname}']`)
?.classList.add('active');
});
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
document.body.addEventListener("click", e => { document.body.addEventListener("click", e => {
if (e.target.matches("[data-link]")) { if (e.target.matches("[data-link]")) {
e.preventDefault(); e.preventDefault();
if (e.target.classList.contains('nav-link')) { document.querySelector('[data-link].nav-link.active')?.classList.remove('active');
document.querySelector('[data-link].active')?.classList.remove('active'); if (e.target.classList.contains('nav-link'))
e.target.classList.add('active'); e.target.classList.add('active');
}
navigateTo(e.target.href.slice(location.origin.length)); navigateTo(e.target.href.slice(location.origin.length));
} }
}); });