36 lines
955 B
HTML
36 lines
955 B
HTML
{{ block "script" .}}
|
|
<script>
|
|
function updateActiveNav() {
|
|
const url = window.location.pathname;
|
|
document.querySelectorAll('.nav-link').forEach((link) => {
|
|
link.classList.remove('active');
|
|
if (link.getAttribute('hx-get') === url) {
|
|
link.classList.add('active');
|
|
}
|
|
});
|
|
}
|
|
document.addEventListener('DOMContentLoaded', (event) => {
|
|
updateActiveNav();
|
|
document.body.addEventListener('htmx:pushedIntoHistory', function (evt) {
|
|
updateActiveNav();
|
|
});
|
|
|
|
document.body.addEventListener('htmx:historyRestore', function () {
|
|
updateActiveNav();
|
|
});
|
|
|
|
document.body.addEventListener('htmx:beforeRequest', function (evt) {
|
|
const elt = evt.target;
|
|
if (
|
|
elt.classList &&
|
|
elt.classList.contains('nav-link') &&
|
|
elt.classList.contains('active')
|
|
) {
|
|
evt.preventDefault();
|
|
evt.stopPropagation();
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
{{ end }}
|