Added evaluation of remote script tags

This commit is contained in:
markusfluer
2017-11-02 12:40:30 +01:00
parent b17457f5a2
commit 09f14fc86c
2 changed files with 18 additions and 8 deletions

View File

@@ -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")
@@ -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
@@ -28,5 +38,5 @@ module.exports = function(el) {
parent.removeChild(script)
}
return true
return true;
}