Files
pjax/lib/execute-scripts.js
Behind The Math 2e459fb7bc Prettier fixes
2019-02-11 23:17:28 -05:00

19 lines
564 B
JavaScript

var forEachEls = require("./foreach-els");
var evalScript = require("./eval-script");
// 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") {
evalScript(el);
}
forEachEls(el.querySelectorAll("script"), function(script) {
if (!script.type || script.type.toLowerCase() === "text/javascript") {
if (script.parentNode) {
script.parentNode.removeChild(script);
}
evalScript(script);
}
});
};