Skip to content

Commit c3a7e69

Browse files
reanimate
1 parent d9d62aa commit c3a7e69

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/oc-client.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ export function createOc(oc) {
106106
return href + (~href.indexOf("?") ? "&" : "?") + $.param(parameters);
107107
};
108108

109+
const reanimateScripts = (component) => {
110+
for (const script of Array.from(component.querySelectorAll("script"))) {
111+
const newScript = document.createElement("script");
112+
newScript.textContent = script.textContent;
113+
for (const attribute of Array.from(script.attributes)) {
114+
newScript.setAttribute(attribute.name, attribute.value);
115+
}
116+
script.parentNode?.replaceChild(newScript, script);
117+
}
118+
};
119+
109120
const getHeaders = () => {
110121
const globalHeaders = ocConf.globalHeaders;
111122
return {
@@ -198,6 +209,9 @@ export function createOc(oc) {
198209
setAttribute("data-version", dataVersion);
199210
setAttribute("data-id", data.ocId);
200211
component.innerHTML = data.html;
212+
// If the html contains <scripts> tags, innerHTML will not execute them.
213+
// So we need to do it manually.
214+
reanimateScripts(component);
201215

202216
if (data.key) {
203217
setAttribute("data-hash", data.key);

0 commit comments

Comments
 (0)