Fix linting errors
This commit is contained in:
4
index.js
4
index.js
@@ -1,5 +1,5 @@
|
||||
var clone = require('./lib/clone.js')
|
||||
var executeScripts = require('./lib/execute-scripts.js')
|
||||
var clone = require("./lib/clone.js")
|
||||
var executeScripts = require("./lib/execute-scripts.js")
|
||||
|
||||
var forEachEls = require("./lib/foreach-els.js")
|
||||
|
||||
|
||||
@@ -6,15 +6,14 @@ var clone = require("../clone")
|
||||
var attrClick = "data-pjax-click-state"
|
||||
|
||||
var formAction = function(el, event) {
|
||||
|
||||
this.options.requestOptions = {
|
||||
requestUrl : el.getAttribute('action') || window.location.href,
|
||||
requestMethod : el.getAttribute('method') || 'GET',
|
||||
requestUrl: el.getAttribute("action") || window.location.href,
|
||||
requestMethod: el.getAttribute("method") || "GET",
|
||||
}
|
||||
|
||||
// create a testable virtual link of the form action
|
||||
var virtLinkElement = document.createElement('a');
|
||||
virtLinkElement.setAttribute('href', this.options.requestOptions.requestUrl);
|
||||
var virtLinkElement = document.createElement("a");
|
||||
virtLinkElement.setAttribute("href", this.options.requestOptions.requestUrl);
|
||||
|
||||
// Ignore external links.
|
||||
if (virtLinkElement.protocol !== window.location.protocol || virtLinkElement.host !== window.location.host) {
|
||||
@@ -45,15 +44,17 @@ var formAction = function(el, event){
|
||||
var paramObject = [];
|
||||
for (var elementKey in el.elements) {
|
||||
var element = el.elements[elementKey];
|
||||
if (!!element.name && element.attributes !== undefined && element.tagName.toLowerCase() !== 'button'){
|
||||
if ((element.attributes.type !== 'checkbox' && element.attributes.type !== 'radio') || element.checked) {
|
||||
// jscs:disable disallowImplicitTypeConversion
|
||||
if (!!element.name && element.attributes !== undefined && element.tagName.toLowerCase() !== "button") {
|
||||
// jscs:enable disallowImplicitTypeConversion
|
||||
if ((element.attributes.type !== "checkbox" && element.attributes.type !== "radio") || element.checked) {
|
||||
paramObject.push({name: encodeURIComponent(element.name), value: encodeURIComponent(element.value)});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Creating a getString
|
||||
var paramsString = (paramObject.map(function(value){return value.name+"="+value.value;})).join('&');
|
||||
var paramsString = (paramObject.map(function(value) {return value.name + "=" + value.value;})).join("&");
|
||||
|
||||
this.options.requestOptions.requestPayload = paramObject;
|
||||
this.options.requestOptions.requestPayloadString = paramsString;
|
||||
@@ -63,7 +64,6 @@ var formAction = function(el, event){
|
||||
const options = clone(this.options);
|
||||
options.triggerElement = el;
|
||||
this.loadUrl(virtLinkElement.href, options);
|
||||
|
||||
};
|
||||
|
||||
var isDefaultPrevented = function(event) {
|
||||
|
||||
@@ -2,14 +2,14 @@ module.exports = function(el) {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case "a":
|
||||
// only attach link if el does not already have link attached
|
||||
if (!el.hasAttribute('data-pjax-click-state')) {
|
||||
if (!el.hasAttribute("data-pjax-click-state")) {
|
||||
this.attachLink(el)
|
||||
}
|
||||
break
|
||||
|
||||
case "form":
|
||||
// only attach link if el does not already have link attached
|
||||
if (!el.hasAttribute('data-pjax-click-state')) {
|
||||
if (!el.hasAttribute("data-pjax-click-state")) {
|
||||
this.attachForm(el)
|
||||
}
|
||||
break
|
||||
|
||||
@@ -20,8 +20,8 @@ module.exports = function(options){
|
||||
ga("send", "pageview", {page: location.pathname, title: document.title})
|
||||
}
|
||||
}
|
||||
this.options.scrollTo = (typeof this.options.scrollTo === 'undefined') ? 0 : this.options.scrollTo;
|
||||
this.options.cacheBust = (typeof this.options.cacheBust === 'undefined') ? true : this.options.cacheBust
|
||||
this.options.scrollTo = (typeof this.options.scrollTo === "undefined") ? 0 : this.options.scrollTo;
|
||||
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust
|
||||
this.options.debug = this.options.debug || false
|
||||
this.options.timeout = this.options.timeout || 0
|
||||
|
||||
|
||||
@@ -46,12 +46,12 @@ tape("test attach form prototype method", function(t) {
|
||||
// see reload defined above
|
||||
|
||||
form.action = window.location.protocol + "//" + window.location.host + "/internal"
|
||||
form.method = 'POST'
|
||||
form.method = "POST"
|
||||
trigger(form, "submit")
|
||||
// see post defined above
|
||||
|
||||
form.action = window.location.protocol + "//" + window.location.host + "/internal"
|
||||
form.method = 'GET'
|
||||
form.method = "GET"
|
||||
trigger(form, "submit")
|
||||
// see post defined above
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ tape("test parse initalization options function", function(t) {
|
||||
// via http://stackoverflow.com/questions/1173549/how-to-determine-if-an-object-is-an-object-literal-in-javascript
|
||||
function isObjLiteral(_obj) {
|
||||
var _test = _obj;
|
||||
return ( typeof _obj !== 'object' || _obj === null ?
|
||||
return (typeof _obj !== "object" || _obj === null ?
|
||||
false :
|
||||
(
|
||||
(function() {
|
||||
@@ -19,54 +19,59 @@ tape("test parse initalization options function", function(t) {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function enumerableKeys(_obj) {
|
||||
var c = 0;
|
||||
for(var n in _obj){ n = n; c++; }
|
||||
for (var n in _obj) {
|
||||
n = n;
|
||||
c++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
t.test("- default options", function(t) {
|
||||
var body_1 = {};
|
||||
var options_1 = {};
|
||||
parseOptions.apply(body_1,[options_1]);
|
||||
var body1 = {};
|
||||
var options1 = {};
|
||||
parseOptions.apply(body1, [options1]);
|
||||
|
||||
t.deepEqual(body_1.options.elements,"a[href], form[action]");
|
||||
t.deepEqual(body_1.options.selectors.length,2,"selectors length");
|
||||
t.deepEqual(body_1.options.selectors[0],"title");
|
||||
t.deepEqual(body_1.options.selectors[1],".js-Pjax");
|
||||
t.deepEqual(body1.options.elements, "a[href], form[action]");
|
||||
t.deepEqual(body1.options.selectors.length, 2, "selectors length");
|
||||
t.deepEqual(body1.options.selectors[0], "title");
|
||||
t.deepEqual(body1.options.selectors[1], ".js-Pjax");
|
||||
|
||||
t.deepEqual(isObjLiteral(body_1.options.switches),true);
|
||||
t.deepEqual(enumerableKeys(body_1.options.switches),2);//head and body
|
||||
t.deepEqual(isObjLiteral(body1.options.switches), true);
|
||||
t.deepEqual(enumerableKeys(body1.options.switches), 2);// head and body
|
||||
|
||||
t.deepEqual(isObjLiteral(body_1.options.switchesOptions),true);
|
||||
t.deepEqual(enumerableKeys(body_1.options.switchesOptions),0);
|
||||
t.deepEqual(isObjLiteral(body1.options.switchesOptions), true);
|
||||
t.deepEqual(enumerableKeys(body1.options.switchesOptions), 0);
|
||||
|
||||
t.deepEqual(body_1.options.history,true);
|
||||
t.deepEqual(body1.options.history, true);
|
||||
|
||||
// TODO analytics is a little weird right now
|
||||
t.deepEqual(typeof body_1.options.analytics,"function");
|
||||
t.deepEqual(typeof body1.options.analytics, "function");
|
||||
|
||||
t.deepEqual(body_1.options.scrollTo,0);
|
||||
t.deepEqual(body_1.options.cacheBust,true);
|
||||
t.deepEqual(body_1.options.debug,false);
|
||||
t.deepEqual(body1.options.scrollTo, 0);
|
||||
t.deepEqual(body1.options.cacheBust, true);
|
||||
t.deepEqual(body1.options.debug, false);
|
||||
t.end();
|
||||
});
|
||||
|
||||
// verify analytics always ends up as a function even when passed not a function
|
||||
t.test("- analytics is a function", function(t) {
|
||||
var body_2 = {};
|
||||
var options_2 = {analytics:"some string"};
|
||||
parseOptions.apply(body_2,[options_2]);
|
||||
var body2 = {};
|
||||
var options2 = {analytics: "some string"};
|
||||
parseOptions.apply(body2, [options2]);
|
||||
|
||||
t.deepEqual(typeof body_2.options.analytics,"function");
|
||||
t.deepEqual(typeof body2.options.analytics, "function");
|
||||
t.end();
|
||||
});
|
||||
// verify that the value false for scrollTo is not squashed
|
||||
t.test("- scrollTo remains false", function(t) {
|
||||
var body_3 = {};
|
||||
var options_3 = {scrollTo:false};
|
||||
parseOptions.apply(body_3,[options_3]);
|
||||
var body3 = {};
|
||||
var options3 = {scrollTo: false};
|
||||
parseOptions.apply(body3, [options3]);
|
||||
|
||||
t.deepEqual( body_3.options.scrollTo,false);
|
||||
t.deepEqual(body3.options.scrollTo, false);
|
||||
t.end();
|
||||
});
|
||||
t.end()
|
||||
|
||||
@@ -6,7 +6,7 @@ var request = require("../../lib/request.js")
|
||||
// just for the purposes of this test
|
||||
// This polyfill is not complete; it won't show the updated location if a
|
||||
// redirection occurred, but it's fine for our purposes.
|
||||
if (!('responseURL' in XMLHttpRequest.prototype)) {
|
||||
if (!("responseURL" in XMLHttpRequest.prototype)) {
|
||||
var nativeOpen = XMLHttpRequest.prototype.open
|
||||
XMLHttpRequest.prototype.open = function(method, url) {
|
||||
this.responseURL = url
|
||||
|
||||
@@ -8,7 +8,7 @@ tape("test switchesSelectors", function(t) {
|
||||
// should really be passed in instead so I'll leave it here as a TODO:
|
||||
var pjax = {
|
||||
onSwitch: function() {
|
||||
console.log('Switched')
|
||||
console.log("Switched")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ tape("test switchesSelectors", function(t) {
|
||||
switchesSelectors.bind(pjax)(
|
||||
{}, // switches
|
||||
{}, // switchesOptions
|
||||
['p'], //selectors,
|
||||
["p"], // selectors,
|
||||
tmpEl, // fromEl
|
||||
document, // toEl,
|
||||
{} // options
|
||||
)
|
||||
|
||||
t.equals(container.innerHTML, '<p>New Text</p><span>No Change</span>', 'Elements correctly switched')
|
||||
t.equals(container.innerHTML, "<p>New Text</p><span>No Change</span>", "Elements correctly switched")
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user