From 4f63581c55828a807aee3a9a2e501d482aa8f351 Mon Sep 17 00:00:00 2001 From: Sascha Woo Date: Sat, 7 Oct 2023 06:22:44 +0200 Subject: [PATCH] Add new event htmx:beforeHistoryUpdate (#1573) * Add missing documentation for htmx:replacedInHistory * Add new event htmx:beforeHistoryUpdate --- src/htmx.js | 1 + www/content/events.md | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/htmx.js b/src/htmx.js index aff42649..1e544690 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -3535,6 +3535,7 @@ return (function () { // if we need to save history, do so if (historyUpdate.type) { + triggerEvent(getDocument().body, 'htmx:beforeHistoryUpdate', mergeObjects({ history: historyUpdate }, responseInfo)); if (historyUpdate.type === "push") { pushUrlIntoHistory(historyUpdate.path); triggerEvent(getDocument().body, 'htmx:pushedIntoHistory', {path: historyUpdate.path}); diff --git a/www/content/events.md b/www/content/events.md index 73a92a49..3fd5ab8d 100644 --- a/www/content/events.md +++ b/www/content/events.md @@ -344,6 +344,19 @@ attribute. If this event is cancelled, the AJAX request will not occur. * `detail.target` - the target of the request * `detail.prompt` - the user response to the prompt +### Event - `htmx:beforeHistoryUpdate` {#htmx:beforeHistoryUpdate} + +This event is triggered before a history update is performed. It can be +used to modify the `path` or `type` used to update the history. + +##### Details + +* `detail.history` - the `path` and `type` (push, replace) for the history update +* `detail.elt` - the element that dispatched the request +* `detail.xhr` - the `XMLHttpRequest` +* `detail.target` - the target of the request +* `detail.requestConfig` - the configuration of the AJAX request + ### Event - `htmx:pushedIntoHistory` {#htmx:pushedIntoHistory} This event is triggered after a URL has been pushed into history. @@ -352,6 +365,14 @@ This event is triggered after a URL has been pushed into history. * `detail.path` - the path and query of the URL that has been pushed into history +### Event - `htmx:replacedInHistory` {#htmx:replacedInHistory} + +This event is triggered after a URL has been replaced in history. + +##### Details + +* `detail.path` - the path and query of the URL that has been replaced in history + ### Event - `htmx:responseError` {#htmx:responseError} This event is triggered when an HTTP error response occurs