mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-11-18 14:29:20 +00:00
restore old semantics w/ body returning its children
This commit is contained in:
parent
f685b57332
commit
d2d22c2903
11
src/htmx.js
11
src/htmx.js
@ -273,6 +273,12 @@ var htmx = (function() {
|
|||||||
return parser.parseFromString(resp, 'text/html')
|
return parser.parseFromString(resp, 'text/html')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function takeChildren(elt, fragment) {
|
||||||
|
while (elt.childNodes.length > 0) {
|
||||||
|
fragment.append(elt.childNodes[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} response HTML
|
* @param {string} response HTML
|
||||||
* @returns {DocumentFragment} a document fragment representing the response HTML, including
|
* @returns {DocumentFragment} a document fragment representing the response HTML, including
|
||||||
@ -287,14 +293,15 @@ var htmx = (function() {
|
|||||||
// if it is a full document, parse it and return the body
|
// if it is a full document, parse it and return the body
|
||||||
const fragment = new DocumentFragment();
|
const fragment = new DocumentFragment();
|
||||||
let doc = parseHTML(response);
|
let doc = parseHTML(response);
|
||||||
fragment.append(doc.body);
|
takeChildren(doc.body, fragment)
|
||||||
|
forEach(doc.body.children, (elt) => fragment.append(elt));
|
||||||
fragment.head = doc.head;
|
fragment.head = doc.head;
|
||||||
return fragment;
|
return fragment;
|
||||||
} else if (startTag === 'body') {
|
} else if (startTag === 'body') {
|
||||||
// body w/ a potential head, parse head & body w/o wrapping in template
|
// body w/ a potential head, parse head & body w/o wrapping in template
|
||||||
const fragment = new DocumentFragment();
|
const fragment = new DocumentFragment();
|
||||||
let doc = parseHTML(head + responseWithNoHead);
|
let doc = parseHTML(head + responseWithNoHead);
|
||||||
fragment.append(doc.body);
|
takeChildren(doc.body, fragment)
|
||||||
fragment.head = doc.head;
|
fragment.head = doc.head;
|
||||||
return fragment;
|
return fragment;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -10,8 +10,8 @@ describe('Core htmx internals Tests', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('makeFragment works with janky stuff', function() {
|
it('makeFragment works with janky stuff', function() {
|
||||||
htmx._('makeFragment')('<html></html>').firstElementChild.tagName.should.equal('BODY')
|
htmx._('makeFragment')('<html></html>').children.length.should.equal(0)
|
||||||
htmx._('makeFragment')('<html><body></body></html>').firstElementChild.tagName.should.equal('BODY')
|
htmx._('makeFragment')('<html><body></body></html>').children.length.should.equal(0)
|
||||||
|
|
||||||
// NB - the tag name should be the *parent* element hosting the HTML since we use the fragment children
|
// NB - the tag name should be the *parent* element hosting the HTML since we use the fragment children
|
||||||
// for the swap
|
// for the swap
|
||||||
@ -22,8 +22,8 @@ describe('Core htmx internals Tests', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('makeFragment works with template wrapping', function() {
|
it('makeFragment works with template wrapping', function() {
|
||||||
htmx._('makeFragment')('<html></html>').children.length.should.equal(1)
|
htmx._('makeFragment')('<html></html>').children.length.should.equal(0)
|
||||||
htmx._('makeFragment')('<html><body></body></html>').children.length.should.equal(1)
|
htmx._('makeFragment')('<html><body></body></html>').children.length.should.equal(0)
|
||||||
|
|
||||||
var fragment = htmx._('makeFragment')('<td></td>')
|
var fragment = htmx._('makeFragment')('<td></td>')
|
||||||
fragment.firstElementChild.tagName.should.equal('TD')
|
fragment.firstElementChild.tagName.should.equal('TD')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user