// Site-wide htmx policy. Loaded right after htmx itself. (function () { // htmx wires up swapped-in content (e.g. a dialog's hx-post form) in its // settle step, by default 20ms after the swap: a click or Enter in that // window would submit the form natively. No settle transitions are used, // so settle in the same tick. htmx.config.defaultSettleDelay = 0; // A server-sent HX-Redirect follows a mutation (move, delete, …): load the // target into the current history entry rather than pushing a new one, so // Back skips the stale pre-mutation page. replaceState + reload rather than // location.replace: a target differing only by #fragment would otherwise // not re-fetch. htmx.location = { set href(target) { window.history.replaceState(null, '', target); window.location.reload(); }, reload: function () { window.location.reload(); } }; // Failed requests answer with a plain-text reason; show it. document.addEventListener('htmx:responseError', function (e) { var xhr = e.detail.xhr; alert(xhr.responseText || ('Request failed (' + xhr.status + ')')); }); document.addEventListener('htmx:sendError', function () { alert('Network error'); }); })();