* Fix bug when checking if elements were parsed already
parse-element.js checks if the element was already parsed by
checking for the `data-pjax-click-state` attribute. However, this
attribute was not added until the link is clicked.
Originally, there was a separate attribute, `data-pjax-enabled`,
which tracked if the element was parsed already, but that was
changed in 9a86044.
This commit merges the attributes for mouse clicks and key presses
into one and adds that attribute when the element is initially
parsed.
* More bug fixes
* Fix documentation for currentUrlFullReload
* Ignore lines from coverage if they can't be tested
* Refactor attach-link and attach-form
* Fix and refactors tests
* Add tests
* Add TS definitions for options.requestOptions
* Code cleanup
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
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. Can’t be executed correctly. Code skipped ", el)
|
||
}
|
||
return false
|
||
}
|
||
|
||
script.type = "text/javascript"
|
||
|
||
/* istanbul ignore if */
|
||
if (src !== "") {
|
||
script.src = src
|
||
script.async = false // force synchronous loading of peripheral JS
|
||
}
|
||
|
||
if (code !== "") {
|
||
try {
|
||
script.appendChild(document.createTextNode(code))
|
||
}
|
||
catch (e) {
|
||
/* istanbul ignore next */
|
||
// old IEs have funky script nodes
|
||
script.text = code
|
||
}
|
||
}
|
||
|
||
// execute
|
||
parent.appendChild(script)
|
||
// avoid pollution only in head or body tags
|
||
if (parent instanceof HTMLHeadElement || parent instanceof HTMLBodyElement) {
|
||
parent.removeChild(script)
|
||
}
|
||
|
||
return true
|
||
}
|