create new html views
This commit is contained in:
35
views/script.html
Normal file
35
views/script.html
Normal file
@@ -0,0 +1,35 @@
|
||||
{{ 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 }}
|
||||
Reference in New Issue
Block a user