Activate regular script tags after sx swap operations
Scripts inserted via innerHTML/insertAdjacentHTML don't execute. Add _activateScripts() to _swapContent that recreates script tags (without type or type=text/javascript) as live elements. This fixes editor.js not loading when navigating to edit pages via sx-get. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1719,6 +1719,20 @@
|
|||||||
|
|
||||||
// ---- Swap engine ------------------------------------------------------
|
// ---- 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) {
|
function _swapContent(target, html, strategy) {
|
||||||
switch (strategy) {
|
switch (strategy) {
|
||||||
case "innerHTML":
|
case "innerHTML":
|
||||||
@@ -1730,6 +1744,7 @@
|
|||||||
tgt.insertAdjacentHTML("afterend", html);
|
tgt.insertAdjacentHTML("afterend", html);
|
||||||
parent.removeChild(tgt);
|
parent.removeChild(tgt);
|
||||||
// Process parent to catch all newly inserted siblings
|
// Process parent to catch all newly inserted siblings
|
||||||
|
_activateScripts(parent);
|
||||||
Sx.processScripts(parent);
|
Sx.processScripts(parent);
|
||||||
Sx.hydrate(parent);
|
Sx.hydrate(parent);
|
||||||
SxEngine.process(parent);
|
SxEngine.process(parent);
|
||||||
@@ -1752,6 +1767,7 @@
|
|||||||
default:
|
default:
|
||||||
target.innerHTML = html;
|
target.innerHTML = html;
|
||||||
}
|
}
|
||||||
|
_activateScripts(target);
|
||||||
Sx.processScripts(target);
|
Sx.processScripts(target);
|
||||||
Sx.hydrate(target);
|
Sx.hydrate(target);
|
||||||
SxEngine.process(target);
|
SxEngine.process(target);
|
||||||
|
|||||||
Reference in New Issue
Block a user