diff --git a/shared/static/scripts/sx.js b/shared/static/scripts/sx.js index b139d1d..669f773 100644 --- a/shared/static/scripts/sx.js +++ b/shared/static/scripts/sx.js @@ -1719,6 +1719,20 @@ // ---- Swap engine ------------------------------------------------------ + /** Scripts inserted via innerHTML/insertAdjacentHTML don't execute. + * Recreate them as live elements so the browser fetches & runs them. */ + function _activateScripts(root) { + var dead = root.querySelectorAll("script:not([type]), script[type='text/javascript']"); + for (var i = 0; i < dead.length; i++) { + var d = dead[i]; + var live = document.createElement("script"); + for (var a = 0; a < d.attributes.length; a++) + live.setAttribute(d.attributes[a].name, d.attributes[a].value); + live.textContent = d.textContent; + d.parentNode.replaceChild(live, d); + } + } + function _swapContent(target, html, strategy) { switch (strategy) { case "innerHTML": @@ -1730,6 +1744,7 @@ tgt.insertAdjacentHTML("afterend", html); parent.removeChild(tgt); // Process parent to catch all newly inserted siblings + _activateScripts(parent); Sx.processScripts(parent); Sx.hydrate(parent); SxEngine.process(parent); @@ -1752,6 +1767,7 @@ default: target.innerHTML = html; } + _activateScripts(target); Sx.processScripts(target); Sx.hydrate(target); SxEngine.process(target);