Serve delete, move and merge dialogs as htmx fragments
The server renders the dialogs (?dialog=delete|move) and answers a move that needs confirmation with the merge dialog itself, so the client no longer builds action URLs or interprets X-Merge-Available. Successful mutations send HX-Redirect, which hx.js turns into a history replace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// 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');
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user