From 4ef719e63a98ee53c7f6490ab3289fb1d0dd596c Mon Sep 17 00:00:00 2001 From: carson Date: Thu, 11 Jun 2020 06:02:23 -0700 Subject: [PATCH] support hx-swap="none" fixes https://github.com/bigskysoftware/htmx/issues/89 --- src/htmx.js | 2 ++ test/attributes/hx-swap.js | 10 +++++++++- www/docs.md | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/htmx.js b/src/htmx.js index 4eca8668..3a9309a0 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -483,6 +483,8 @@ return (function () { function swap(swapStyle, elt, target, fragment, settleInfo) { switch (swapStyle) { + case "none": + return; case "outerHTML": swapOuterHTML(target, fragment, settleInfo); return; diff --git a/test/attributes/hx-swap.js b/test/attributes/hx-swap.js index 2e484b45..e8a4ae74 100644 --- a/test/attributes/hx-swap.js +++ b/test/attributes/hx-swap.js @@ -246,7 +246,6 @@ describe("hx-swap attribute", function(){ }, 30); }); - it('swap outerHTML properly w/ data-* prefix', function() { this.server.respondWith("GET", "/test", 'Click Me'); @@ -262,5 +261,14 @@ describe("hx-swap attribute", function(){ byId("a1").innerHTML.should.equal('Clicked!'); }); + it('swap none works properly', function() + { + this.server.respondWith("GET", "/test", 'Ooops, swapped'); + + var div = make('
Foo
') + div.click(); + this.server.respond(); + div.innerHTML.should.equal('Foo'); + }); }) diff --git a/www/docs.md b/www/docs.md index 4faba340..0e13289c 100644 --- a/www/docs.md +++ b/www/docs.md @@ -302,6 +302,7 @@ with any of the following values: | `beforebegin` | prepends the content before the target in the targets parent element | `beforeend` | appends the content after the last child inside the target | `afterend` | appends the content after the target in the targets parent element +| `none` | does not append content from respons (out of band items will still be processed) #### [Out of Band Swaps](#oob_swaps)