Code cleanup

This commit is contained in:
Behind The Math
2018-01-29 23:20:00 -05:00
committed by Robin North
parent 57aed828ac
commit 6fb509a021
12 changed files with 25 additions and 27 deletions

View File

@@ -23,7 +23,7 @@ var Pjax = function(options) {
}
var parseOptions = require("./lib/proto/parse-options.js");
parseOptions.apply(this,[options])
parseOptions.call(this,options)
this.log("Pjax options", this.options)
if (this.options.scrollRestoration && "scrollRestoration" in history) {
@@ -168,7 +168,7 @@ Pjax.prototype = {
this.request = this.doRequest(href, options.requestOptions, function(html, request) {
// Fail if unable to load HTML via AJAX
if (html === false) {
trigger(document,"pjax:complete pjax:error", options)
trigger(document, "pjax:complete pjax:error", options)
return
}
@@ -218,8 +218,7 @@ Pjax.prototype = {
if (console && console.error) {
console.error("Pjax switch fail: ", e)
}
this.latestChance(href)
return
return this.latestChance(href)
}
else {
throw e

View File

@@ -1,5 +1,5 @@
module.exports = function(obj) {
if (null === obj || "object" != typeof obj) {
if (null === obj || "object" !== typeof obj) {
return obj
}
var copy = obj.constructor()

View File

@@ -13,12 +13,12 @@ module.exports = function(el) {
script.type = "text/javascript"
if (src != "") {
if (src !== "") {
script.src = src;
script.async = false; // force synchronous loading of peripheral js
}
if (code != "") {
if (code !== "") {
try {
script.appendChild(document.createTextNode(code))
}
@@ -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 (["head", "body"].indexOf(parent.tagName.toLowerCase()) > 0) {
parent.removeChild(script)
}

View File

@@ -13,7 +13,7 @@ var formAction = function(el, event) {
// Initialize requestOptions
options.requestOptions = {
requestUrl: el.getAttribute("action") || window.location.href,
requestMethod: el.getAttribute("method") || "GET",
requestMethod: el.getAttribute("method") || "GET"
}
// create a testable virtual link of the form action
@@ -93,7 +93,7 @@ module.exports = function(el) {
}
if (event.keyCode == 13) {
if (event.keyCode === 13) {
formAction.call(that, el, event)
}
}.bind(this))

View File

@@ -91,7 +91,7 @@ module.exports = function(el) {
return
}
if (event.keyCode == 13) {
if (event.keyCode === 13) {
linkAction.call(that, el, event)
}
}.bind(this))

View File

@@ -3,6 +3,7 @@
var defaultSwitches = require("../switches")
module.exports = function(options) {
options = options || {}
options.elements = options.elements || "a[href], form[action]"
options.selectors = options.selectors || ["title", ".js-Pjax"]
options.switches = options.switches || {}

View File

@@ -35,7 +35,7 @@ module.exports = function(location, options, callback) {
request.setRequestHeader("X-PJAX", "true")
// Add the request payload if available
if (options.requestPayloadString != undefined && options.requestPayloadString != "") {
if (options.requestPayloadString !== undefined && options.requestPayloadString !== "") {
// Send the proper header information along with the request
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}

View File

@@ -40,7 +40,7 @@ module.exports = {
var animationEventNames = "animationend webkitAnimationEnd MSAnimationEnd oanimationend"
var animatedElsNumber = 0
var sexyAnimationEnd = function(e) {
if (e.target != e.currentTarget) {
if (e.target !== e.currentTarget) {
// end triggered by an animation on a child
return
}

View File

@@ -18,8 +18,8 @@ if (!("responseURL" in XMLHttpRequest.prototype)) {
tape("test aborting xhr request", function(t) {
var requestCacheBust = sendRequest.bind({
options: {
cacheBust: true,
},
cacheBust: true
}
})
t.test("- pending request is aborted", function(t) {

View File

@@ -80,12 +80,11 @@ tape("test attach form preventDefaulted events", function(t) {
tape("test options are not modified by attachForm", function(t) {
var form = document.createElement("form")
var options = {foo: "bar"}
var loadUrl = () => {}
var loadUrl = function() {}
attachForm.call({options, loadUrl}, form)
attachForm.call({options: options, loadUrl: loadUrl}, form)
var internalUri = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search
form.action = internalUri
form.action = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search
form.method = "GET"
trigger(form, "submit")

View File

@@ -79,12 +79,11 @@ tape("test attach link preventDefaulted events", function(t) {
tape("test options are not modified by attachLink", function(t) {
var a = document.createElement("a")
var options = {foo: "bar"}
var loadUrl = () => {};
var loadUrl = function() {};
attachLink.call({options, loadUrl}, a)
attachLink.call({options: options, loadUrl: loadUrl}, a)
var internalUri = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search
a.href = internalUri
a.href = window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search
trigger(a, "click")

View File

@@ -20,8 +20,8 @@ tape("test xhr request", function(t) {
t.test("- request is made, gets a result, and is cache-busted", function(t) {
var requestCacheBust = sendRequest.bind({
options: {
cacheBust: true,
},
cacheBust: true
}
});
var r = requestCacheBust(url, {}, function(result) {
t.equal(r.responseURL.indexOf("?"), url.length, "XHR URL is cache-busted when configured to be")
@@ -38,8 +38,8 @@ tape("test xhr request", function(t) {
t.test("- request is not cache-busted when configured not to be", function(t) {
var requestNoCacheBust = sendRequest.bind({
options: {
cacheBust: false,
},
cacheBust: false
}
});
var r = requestNoCacheBust(url, {}, function() {
t.equal(r.responseURL, url, "XHR URL is left untouched")