UNPKG

933 BJavaScriptView Raw
1(function(){
2 function maybeRemoveMe(elt) {
3 var timing = elt.getAttribute("remove-me") || elt.getAttribute("data-remove-me");
4 if (timing) {
5 setTimeout(function () {
6 elt.parentElement.removeChild(elt);
7 }, htmx.parseInterval(timing));
8 }
9 }
10
11 htmx.defineExtension('remove-me', {
12 onEvent: function (name, evt) {
13 if (name === "htmx:afterProcessNode") {
14 var elt = evt.detail.elt;
15 if (elt.getAttribute) {
16 maybeRemoveMe(elt);
17 if (elt.querySelectorAll) {
18 var children = elt.querySelectorAll("[remove-me], [data-remove-me]");
19 for (var i = 0; i < children.length; i++) {
20 maybeRemoveMe(children[i]);
21 }
22 }
23 }
24 }
25 }
26 });
27})();