Code cleanup #120
@@ -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,7 +15,7 @@ module.exports = function(el) {
|
|||||||
|
|
||||||
if (src !== "") {
|
if (src !== "") {
|
||||||
script.src = src
|
script.src = src
|
||||||
script.async = false // force synchronous loading of peripheral js
|
script.async = false // force synchronous loading of peripheral JS
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code !== "") {
|
if (code !== "") {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module.exports = function(els, events, opts) {
|
|||||||
events = (typeof events === "string" ? events.split(" ") : events)
|
events = (typeof events === "string" ? events.split(" ") : events)
|
||||||
|
|
||||||
events.forEach(function(e) {
|
events.forEach(function(e) {
|
||||||
var event // = new CustomEvent(e) // doesn't everywhere yet
|
var event
|
||||||
event = document.createEvent("HTMLEvents")
|
event = document.createEvent("HTMLEvents")
|
||||||
event.initEvent(e, true, true)
|
event.initEvent(e, true, true)
|
||||||
event.eventName = e
|
event.eventName = e
|
||||||
@@ -17,8 +17,8 @@ module.exports = function(els, events, opts) {
|
|||||||
forEachEls(els, function(el) {
|
forEachEls(els, function(el) {
|
||||||
var domFix = false
|
var domFix = false
|
||||||
if (!el.parentNode && el !== document && el !== window) {
|
if (!el.parentNode && el !== document && el !== window) {
|
||||||
// THANKS YOU IE (9/10//11 concerned)
|
// THANK YOU IE (9/10/11)
|
||||||
// dispatchEvent doesn't work if element is not in the dom
|
// dispatchEvent doesn't work if the element is not in the DOM
|
||||||
domFix = true
|
domFix = true
|
||||||
document.body.appendChild(el)
|
document.body.appendChild(el)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ var evalScript = require("./eval-script")
|
|||||||
// Finds and executes scripts (used for newly added elements)
|
// Finds and executes scripts (used for newly added elements)
|
||||||
// Needed since innerHTML does not run scripts
|
// Needed since innerHTML does not run scripts
|
||||||
module.exports = function(el) {
|
module.exports = function(el) {
|
||||||
// console.log("going to execute scripts for ", el)
|
|
||||||
|
|
||||||
if (el.tagName.toLowerCase() === "script") {
|
if (el.tagName.toLowerCase() === "script") {
|
||||||
evalScript(el)
|
evalScript(el)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ module.exports = function(els, fn, context) {
|
|||||||
if (els instanceof HTMLCollection || els instanceof NodeList || els instanceof Array) {
|
if (els instanceof HTMLCollection || els instanceof NodeList || els instanceof Array) {
|
||||||
return Array.prototype.forEach.call(els, fn, context)
|
return Array.prototype.forEach.call(els, fn, context)
|
||||||
}
|
}
|
||||||
// assume simple dom element
|
// assume simple DOM element
|
||||||
return fn.call(context, els)
|
return fn.call(context, els)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module.exports = function() {
|
|||||||
if (typeof console.log === "function") {
|
if (typeof console.log === "function") {
|
||||||
console.log.apply(console, arguments)
|
console.log.apply(console, arguments)
|
||||||
}
|
}
|
||||||
// ie is weird
|
// IE is weird
|
||||||
else if (console.log) {
|
else if (console.log) {
|
||||||
console.log(arguments)
|
console.log(arguments)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user