css: navbar link improvements
This commit is contained in:
parent
927748a13d
commit
55eb47a4e5
@ -134,16 +134,23 @@ const router = async(uri) => {
|
||||
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.body.addEventListener("click", e => {
|
||||
if (e.target.matches("[data-link]")) {
|
||||
e.preventDefault();
|
||||
if (e.target.classList.contains('nav-link')) {
|
||||
document.querySelector('[data-link].active')?.classList.remove('active');
|
||||
document.querySelector('[data-link].nav-link.active')?.classList.remove('active');
|
||||
if (e.target.classList.contains('nav-link'))
|
||||
e.target.classList.add('active');
|
||||
}
|
||||
navigateTo(e.target.href.slice(location.origin.length));
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user