Files
pjax/lib/eval-script.js
BehindTheMath a72880d205 Code cleanup (#120)
* Lots of code cleanup

* Cleanup parse-options tests
  - Rename objects for clarity and inline unneeded objects
  - Remove unneeded tests
  - Use Object.keys().length instead of a custom function
  - Use typeof === "object" instead of a custom function that checks the prototype tree as well, since we don't expect anything but an object literal.

* Remove old switchFallback code

* Remove polyfill for Function.prototype.bind

* Inline small functions

* Add more documentation and tests for options.currentUrlFullReload
  Closes #17

* Update package.json
2018-02-02 09:52:44 -05:00

40 lines
1011 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module.exports = function(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")
if (code.match("document.write")) {
if (console && console.log) {
console.log("Script contains document.write. Cant be executed correctly. Code skipped ", el)
}
return false
}
script.type = "text/javascript"
if (src !== "") {
script.src = src
script.async = false // force synchronous loading of peripheral JS
}
if (code !== "") {
try {
script.appendChild(document.createTextNode(code))
}
catch (e) {
// old IEs have funky script nodes
script.text = code
}
}
// execute
parent.appendChild(script)
// avoid pollution only in head or body tags
if (["head", "body"].indexOf(parent.tagName.toLowerCase()) > 0) {
parent.removeChild(script)
}
return true
}