Fix linting errors

This commit is contained in:
Behind The Math
2018-01-09 00:44:20 -05:00
committed by BehindTheMath
parent e586440964
commit c0d64e41b8
8 changed files with 95 additions and 90 deletions

View File

@@ -5,16 +5,15 @@ var clone = require("../clone")
var attrClick = "data-pjax-click-state"
var formAction = function(el, event){
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);
// create a testable virtual link of the form action
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) {
@@ -35,7 +34,7 @@ var formAction = function(el, event){
}
// if declared as a full reload, just normally submit the form
if ( this.options.currentUrlFullReload) {
if (this.options.currentUrlFullReload) {
el.setAttribute(attrClick, "reload");
return;
}
@@ -43,17 +42,19 @@ var formAction = function(el, event){
event.preventDefault()
var paramObject = [];
for(var elementKey in el.elements) {
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) {
paramObject.push({ name: encodeURIComponent(element.name), value: encodeURIComponent(element.value)});
// 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('&');
// Creating a getString
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) {

View File

@@ -1,20 +1,20 @@
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')) {
this.attachLink(el)
}
break
case "a":
// only attach link if el does not already have link attached
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
break
default:
throw "Pjax can only be applied on <a> or <form> submit"
default:
throw "Pjax can only be applied on <a> or <form> submit"
}
}

View File

@@ -2,7 +2,7 @@
var defaultSwitches = require("../switches")
module.exports = function(options){
module.exports = function(options) {
this.options = options
this.options.elements = this.options.elements || "a[href], form[action]"
this.options.selectors = this.options.selectors || ["title", ".js-Pjax"]
@@ -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