on-page-load.js 865 B

1234567891011121314151617181920212223242526
  1. // on network error when clicking on a link, navigate to the page anyway
  2. addEventListener('htmx:sendError', function (event) {
  3. if (event.target.tagName == "A") {
  4. // if the server is down, this will show the browser's default "Unable to connect" page, which is familiar to the user
  5. document.location = event.detail.pathInfo.requestPath
  6. }
  7. });
  8. // make 4xx 5xx responses swap in as well
  9. addEventListener('htmx:beforeOnLoad', function (event) {
  10. // console.log("%o", event)
  11. event.detail.shouldSwap = true;
  12. event.detail.isError = false;
  13. });
  14. function closeNavigationMenu() {
  15. document.getElementById("sidebar-toggler").checked = false
  16. }
  17. // browser built-in navigation
  18. addEventListener("popstate", (event) => {
  19. closeNavigationMenu()
  20. });
  21. // htmx triggered navigation
  22. addEventListener("htmx:pushedIntoHistory", (event) => {
  23. closeNavigationMenu()
  24. });