From 09f14fc86cd161f3a27e988b56212322b08e2a16 Mon Sep 17 00:00:00 2001 From: markusfluer Date: Thu, 2 Nov 2017 12:40:30 +0100 Subject: [PATCH] Added evaluation of remote script tags --- lib/eval-script.js | 22 ++++++++++++++++------ lib/execute-scripts.js | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/eval-script.js b/lib/eval-script.js index 9591fd3..232090d 100644 --- a/lib/eval-script.js +++ b/lib/eval-script.js @@ -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; } diff --git a/lib/execute-scripts.js b/lib/execute-scripts.js index 04ece08..d5fab5a 100644 --- a/lib/execute-scripts.js +++ b/lib/execute-scripts.js @@ -14,7 +14,7 @@ module.exports = function(el) { if (script.parentNode) { script.parentNode.removeChild(script) } - evalScript(script) + evalScript(script); } - }) + }); }