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