diff --git a/src/pat/inject/inject.js b/src/pat/inject/inject.js index 4d3ebcb6c..e396c4c12 100644 --- a/src/pat/inject/inject.js +++ b/src/pat/inject/inject.js @@ -459,7 +459,7 @@ const inject = { /* Called after the XHR has succeeded and we have a new $sources * element to inject. */ - const wrapper = document.createElement("div"); + const wrapper = document.createElement("template"); if ($sources.length > 0) { const method = cfg.sourceMod === "content" ? "innerHTML" : "outerHTML"; // There might be multiple sources, so we need to loop over them. @@ -467,7 +467,7 @@ const inject = { const sources_string = [...$sources].map(source => source[method]).join("\n"); wrapper.innerHTML = sources_string; - for (const img of wrapper.querySelectorAll("img")) { + for (const img of wrapper.content.querySelectorAll("img")) { events.add_event_listener( img, "load", @@ -481,7 +481,7 @@ const inject = { } // Copy, because after insertion wrapper.children is empty. - const source_nodes = [...wrapper.childNodes]; + const source_nodes = [...wrapper.content.childNodes]; // Now the injection actually happens. if (this._inject(trigger, source_nodes, target, cfg)) { diff --git a/src/pat/inject/inject.test.js b/src/pat/inject/inject.test.js index 028085599..2a8d332ac 100644 --- a/src/pat/inject/inject.test.js +++ b/src/pat/inject/inject.test.js @@ -1868,6 +1868,61 @@ describe("pat-inject", function () { }); }); + describe("9.6 - injecting tables.", function () { + let spy_ajax; + + beforeEach(function () { + spy_ajax = jest.spyOn($, "ajax").mockImplementation(() => deferred); + }); + + afterEach(function () { + spy_ajax.mockRestore(); + }); + + it("9.6.1 - Correctly injects table rows", async function () { + // Table rows
wohoo |