Skip to content

Commit

Permalink
Fix issue with dynamically adding script tags
Browse files Browse the repository at this point in the history
  • Loading branch information
CMEONE committed Mar 6, 2021
1 parent 518750d commit e0cdb5a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class tApp {
static database;
static currentHash = "/";
static get version() {
return "v0.6.0";
return "v0.6.1";
}
static configure(params) {
if(params == null) {
Expand Down Expand Up @@ -303,6 +303,32 @@ class tApp {
throw "tAppError: No target DOM specified, use tApp.config.target to set the target."
}
tApp.config.target.innerHTML = html;
function nodeScriptReplace(node) {
if (nodeScriptIs(node) === true) {
node.parentNode.replaceChild(nodeScriptClone(node), node);
} else {
var i = -1, children = node.childNodes;
while (++i < children.length) {
nodeScriptReplace(children[i]);
}
}
return node;
}
function nodeScriptClone(node){
var script = document.createElement("script");
script.text = node.innerHTML;

var i = -1, attrs = node.attributes, attr;
while (++i < attrs.length) {
script.setAttribute((attr = attrs[i]).name, attr.value);
}
return script;
}

function nodeScriptIs(node) {
return node.tagName === 'SCRIPT';
}
nodeScriptReplace(tApp.config.target);
}
static renderFile(path) {
tApp.get(path).then((res) => {
Expand Down

0 comments on commit e0cdb5a

Please sign in to comment.