UNPKG

532 BJavaScriptView Raw
1htmx.defineExtension('alpine-morph', {
2 isInlineSwap: function (swapStyle) {
3 return swapStyle === 'morph';
4 },
5 handleSwap: function (swapStyle, target, fragment) {
6 if (swapStyle === 'morph') {
7 if (fragment.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
8 Alpine.morph(target, fragment.firstElementChild);
9 return [target];
10 } else {
11 Alpine.morph(target, fragment.outerHTML);
12 return [target];
13 }
14 }
15 }
16});
\No newline at end of file