Skip to content

Commit

Permalink
Added evaluation of remote script tags
Browse files Browse the repository at this point in the history
  • Loading branch information
lacrioque committed Nov 2, 2017
1 parent b17457f commit 09f14fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions lib/eval-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = function(el) {
// console.log("going to execute script", el)

var code = (el.text || el.textContent || el.innerHTML || "")
var src = (el.src || "");
var parent = el.parentNode || document.querySelector("head") || document.documentElement
var script = document.createElement("script")

Expand All @@ -13,12 +14,21 @@ module.exports = function(el) {
}

script.type = "text/javascript"
try {
script.appendChild(document.createTextNode(code))

if (src != "") {
script.src = src;
script.onload = function() { document.dispatchEvent((new Event("pjax:complete"))); }
script.async = false; // force asynchronous loading of peripheral js
}
catch (e) {
// old IEs have funky script nodes
script.text = code

if (code != "") {
try {
script.appendChild(document.createTextNode(code))
}
catch (e) {
// old IEs have funky script nodes
script.text = code
}
}

// execute
Expand All @@ -28,5 +38,5 @@ module.exports = function(el) {
parent.removeChild(script)
}

return true
return true;
}
4 changes: 2 additions & 2 deletions lib/execute-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(el) {
if (script.parentNode) {
script.parentNode.removeChild(script)
}
evalScript(script)
evalScript(script);
}
})
});
}

0 comments on commit 09f14fc

Please sign in to comment.