From 494f1f35ac219ca1627321fd715ab1a8acdb2af0 Mon Sep 17 00:00:00 2001 From: Behind The Math Date: Tue, 20 Mar 2018 18:42:39 -0400 Subject: [PATCH] Bug fixes --- lib/eval-script.js | 2 +- lib/parse-options.js | 20 ++++++++++---------- lib/send-request.js | 4 ++-- lib/util/extend.js | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/eval-script.js b/lib/eval-script.js index b508006..0569e76 100644 --- a/lib/eval-script.js +++ b/lib/eval-script.js @@ -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) } diff --git a/lib/parse-options.js b/lib/parse-options.js index a3f5239..b65cd48 100644 --- a/lib/parse-options.js +++ b/lib/parse-options.js @@ -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}) + } +} diff --git a/lib/send-request.js b/lib/send-request.js index e251e61..1c4a7f8 100644 --- a/lib/send-request.js +++ b/lib/send-request.js @@ -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) diff --git a/lib/util/extend.js b/lib/util/extend.js index 07efde9..dae7e12 100644 --- a/lib/util/extend.js +++ b/lib/util/extend.js @@ -1,6 +1,6 @@ module.exports = function(target) { if (target == null) { - return target + return null } var to = Object(target)