diff options
Diffstat (limited to 'static/js/ext/remove-me.js')
-rw-r--r-- | static/js/ext/remove-me.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/static/js/ext/remove-me.js b/static/js/ext/remove-me.js new file mode 100644 index 0000000..21cd788 --- /dev/null +++ b/static/js/ext/remove-me.js @@ -0,0 +1,31 @@ +(function(){ + if (htmx.version && !htmx.version.startsWith("1.")) { + console.warn("WARNING: You are using an htmx 1 extension with htmx " + htmx.version + + ". It is recommended that you move to the version of this extension found on https://htmx.org/extensions") + } + function maybeRemoveMe(elt) { + var timing = elt.getAttribute("remove-me") || elt.getAttribute("data-remove-me"); + if (timing) { + setTimeout(function () { + elt.parentElement.removeChild(elt); + }, htmx.parseInterval(timing)); + } + } + + htmx.defineExtension('remove-me', { + onEvent: function (name, evt) { + if (name === "htmx:afterProcessNode") { + var elt = evt.detail.elt; + if (elt.getAttribute) { + maybeRemoveMe(elt); + if (elt.querySelectorAll) { + var children = elt.querySelectorAll("[remove-me], [data-remove-me]"); + for (var i = 0; i < children.length; i++) { + maybeRemoveMe(children[i]); + } + } + } + } + } + }); +})(); |