Skip to content

Commit

Permalink
feat: support filtering state based on HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-ebey committed Oct 2, 2023
1 parent 04250d5 commit 4640089
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ext/loading-states.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
return pathElt.getAttribute('data-loading-path') === requestPath
}

function mayProcessLoadingStateByMethod(elt, requestMethod) {
const methodElt = htmx.closest(elt, "[data-loading-method]")
if (!methodElt) {
return true
}

return methodElt.getAttribute("data-loading-method") === requestMethod
}

function queueLoadingState(sourceElt, targetElt, doCallback, undoCallback) {
const delayElt = htmx.closest(sourceElt, '[data-loading-delay]')
if (delayElt) {
Expand All @@ -46,7 +55,7 @@

function getLoadingStateElts(loadingScope, type, path) {
return Array.from(htmx.findAll(loadingScope, "[" + type + "]")).filter(
function (elt) { return mayProcessLoadingStateByPath(elt, path) }
function (elt) { return mayProcessLoadingStateByPath(elt, path) && mayProcessLoadingStateByMethod(elt, method) }
)
}

Expand Down

0 comments on commit 4640089

Please sign in to comment.