Files
pjax/lib/execute-scripts.js

19 lines
564 B
JavaScript
Raw Normal View History

2019-02-11 23:17:28 -05:00
var forEachEls = require("./foreach-els");
var evalScript = require("./eval-script");
2014-05-04 08:44:52 +02:00
// Finds and executes scripts (used for newly added elements)
// Needed since innerHTML does not run scripts
module.exports = function(el) {
if (el.tagName.toLowerCase() === "script") {
2019-02-11 23:17:28 -05:00
evalScript(el);
}
2014-05-04 08:44:52 +02:00
forEachEls(el.querySelectorAll("script"), function(script) {
if (!script.type || script.type.toLowerCase() === "text/javascript") {
if (script.parentNode) {
2019-02-11 23:17:28 -05:00
script.parentNode.removeChild(script);
2014-05-04 08:44:52 +02:00
}
2019-02-11 23:17:28 -05:00
evalScript(script);
2014-05-04 08:44:52 +02:00
}
2019-02-11 23:17:28 -05:00
});
};