envelope/core/static/django-htmx.js

23 lines
839 B
JavaScript
Raw Normal View History

2022-10-12 06:22:22 +00:00
{
2022-10-12 06:22:22 +00:00
const data = document.currentScript.dataset;
const isDebug = data.debug === "True";
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
if (isDebug) {
document.addEventListener("htmx:beforeOnLoad", function (event) {
const xhr = event.detail.xhr;
if (xhr.status == 500 || xhr.status == 404) {
// Tell htmx to stop processing this response
event.stopPropagation();
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
document.children[0].innerHTML = xhr.response;
2022-10-12 06:22:22 +00:00
2022-10-12 06:22:22 +00:00
// Run Djangos inline script
// (1, eval) wtf - see https://stackoverflow.com/questions/9107240/1-evalthis-vs-evalthis-in-javascript
(1, eval)(document.scripts[0].innerText);
// Need to directly call Djangos onload function since browser wont
window.onload();
}
});
}
2022-10-12 06:22:22 +00:00
}