mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-09-28 21:41:40 +00:00
Merge pull request #354 from andyhorng/fix-morphdom-swap
Handle DocumentFragement in morphdom-swap properly
This commit is contained in:
commit
d71a4b086f
@ -4,8 +4,13 @@ htmx.defineExtension('morphdom-swap', {
|
||||
},
|
||||
handleSwap: function (swapStyle, target, fragment) {
|
||||
if (swapStyle === 'morphdom') {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return [target]; // let htmx handle the new content
|
||||
if (fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
|
||||
morphdom(target, fragment.firstElementChild);
|
||||
return [target];
|
||||
} else {
|
||||
morphdom(target, fragment.outerHTML);
|
||||
return [target];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -28,4 +28,13 @@ describe("morphdom-swap extension", function() {
|
||||
btn.innerHTML.should.equal("Clicked!Loaded!");
|
||||
});
|
||||
|
||||
it('works with hx-select', function () {
|
||||
this.server.respondWith("GET", "/test", "<button>Clicked!</button>!");
|
||||
var btn = make('<button hx-get="/test" hx-ext="morphdom-swap" hx-swap="morphdom" hx-select="button" >Click Me!</button>')
|
||||
btn.click();
|
||||
should.equal(btn.getAttribute("hx-get"), "/test");
|
||||
this.server.respond();
|
||||
should.equal(btn.getAttribute("hx-get"), null);
|
||||
btn.innerHTML.should.equal("Clicked!");
|
||||
});
|
||||
});
|
||||
|
@ -8,6 +8,8 @@ title: </> htmx - high power tools for html
|
||||
This extension allows you to use the [morphdom](https://github.com/patrick-steele-idem/morphdom) library as the
|
||||
swapping mechanism in htmx.
|
||||
|
||||
The `morphdom` library does not support morph element to multiple elements. If the result of `hx-select` is more than one element, it will pick the first one.
|
||||
|
||||
#### Usage
|
||||
|
||||
```html
|
||||
|
Loading…
x
Reference in New Issue
Block a user