Fix bugs and add tests #145

Merged
BehindTheMath merged 11 commits from fix/bugs-and-add-tests into master 2018-04-09 22:36:33 -05:00
4 changed files with 14 additions and 14 deletions
Showing only changes of commit 494f1f35ac - Show all commits

View File

@@ -31,7 +31,7 @@ module.exports = function(el) {
// execute
parent.appendChild(script)
// avoid pollution only in head or body tags
if (["head", "body"].indexOf(parent.tagName.toLowerCase()) > 0) {
if (parent instanceof HTMLHeadElement || parent instanceof HTMLBodyElement) {
parent.removeChild(script)
}

View File

@@ -9,16 +9,7 @@ module.exports = function(options) {
options.switches = options.switches || {}
options.switchesOptions = options.switchesOptions || {}
options.history = options.history || true
options.analytics = (typeof options.analytics === "function" || options.analytics === false) ?
options.analytics :
function() {
if (window._gaq) {
_gaq.push(["_trackPageview"])
}
if (window.ga) {
ga("send", "pageview", {page: location.pathname, title: document.title})
}
}
options.analytics = (typeof options.analytics === "function" || options.analytics === false) ? options.analytics : defaultAnalytics
options.scrollTo = (typeof options.scrollTo === "undefined") ? 0 : options.scrollTo
options.scrollRestoration = (typeof options.scrollRestoration !== "undefined") ? options.scrollRestoration : true
options.cacheBust = (typeof options.cacheBust === "undefined") ? true : options.cacheBust
@@ -38,3 +29,12 @@ module.exports = function(options) {
return options
}
function defaultAnalytics() {
if (window._gaq) {
_gaq.push(["_trackPageview"])
}
if (window.ga) {
ga("send", "pageview", {page: location.pathname, title: document.title})
}
}

View File

@@ -15,7 +15,7 @@ module.exports = function(location, options, callback) {
if (request.status === 200) {
callback(request.responseText, request, location)
}
else {
else if (request.status !== 0) {
callback(null, request, location)
}
}
@@ -65,7 +65,7 @@ module.exports = function(location, options, callback) {
// Send the proper header information for POST forms
if (requestPayload && requestMethod === "POST") {
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
}
request.send(requestPayload)

View File

@@ -1,6 +1,6 @@
module.exports = function(target) {
if (target == null) {
return target
return null
}
var to = Object(target)