Merge pull request #118 from MoOx/fix/external-scripts-events
Fix external scripts events
This commit was merged in pull request #118.
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
module.exports = function(el) {
|
module.exports = function(el) {
|
||||||
// console.log("going to execute script", el)
|
|
||||||
|
|
||||||
var code = (el.text || el.textContent || el.innerHTML || "")
|
var code = (el.text || el.textContent || el.innerHTML || "")
|
||||||
var src = (el.src || "");
|
var src = (el.src || "");
|
||||||
var parent = el.parentNode || document.querySelector("head") || document.documentElement
|
var parent = el.parentNode || document.querySelector("head") || document.documentElement
|
||||||
@@ -17,8 +15,7 @@ module.exports = function(el) {
|
|||||||
|
|
||||||
if (src != "") {
|
if (src != "") {
|
||||||
script.src = src;
|
script.src = src;
|
||||||
script.onload = function() { document.dispatchEvent((new Event("pjax:complete"))); }
|
script.async = false; // force synchronous loading of peripheral js
|
||||||
script.async = false; // force asynchronous loading of peripheral js
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != "") {
|
if (code != "") {
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ tape("test evalScript method", function(t) {
|
|||||||
evalScript(script)
|
evalScript(script)
|
||||||
t.equal(document.body.className, "executed", "script has been properly executed")
|
t.equal(document.body.className, "executed", "script has been properly executed")
|
||||||
|
|
||||||
// script.innerHTML = "document.write('failure')"
|
script.innerHTML = "document.write('failure')"
|
||||||
// var bodyText = document.body.text
|
document.body.text = "document.write hasn't been executed"
|
||||||
// evalScript(script)
|
var bodyText = document.body.text
|
||||||
// t.equal(document.body.text, bodyText, "document.write hasn't been executed")
|
evalScript(script)
|
||||||
|
t.equal(document.body.text, bodyText, "document.write hasn't been executed")
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user