Code style cleanup, remove redundant comments

This commit is contained in:
Robin North
2018-01-31 22:17:06 +00:00
parent 9971c4c4f0
commit 1eb43f73fe
15 changed files with 87 additions and 120 deletions

View File

@@ -8,7 +8,7 @@ var attrClick = "data-pjax-click-state"
var formAction = function(el, event) {
// Since loadUrl modifies options and we may add our own modifications below,
// clone it so the changes don't persist
var options = clone(this.options);
var options = clone(this.options)
// Initialize requestOptions
options.requestOptions = {
@@ -17,18 +17,18 @@ var formAction = function(el, event) {
}
// create a testable virtual link of the form action
var virtLinkElement = document.createElement("a");
virtLinkElement.setAttribute("href", options.requestOptions.requestUrl);
var virtLinkElement = document.createElement("a")
virtLinkElement.setAttribute("href", options.requestOptions.requestUrl)
// Ignore external links.
if (virtLinkElement.protocol !== window.location.protocol || virtLinkElement.host !== window.location.host) {
el.setAttribute(attrClick, "external");
el.setAttribute(attrClick, "external")
return
}
// Ignore click if we are on an anchor on the same page
if (virtLinkElement.pathname === window.location.pathname && virtLinkElement.hash.length > 0) {
el.setAttribute(attrClick, "anchor-present");
el.setAttribute(attrClick, "anchor-present")
return
}
@@ -40,41 +40,39 @@ var formAction = function(el, event) {
// if declared as a full reload, just normally submit the form
if (options.currentUrlFullReload) {
el.setAttribute(attrClick, "reload");
return;
el.setAttribute(attrClick, "reload")
return
}
event.preventDefault()
var paramObject = [];
var paramObject = []
for (var elementKey in el.elements) {
var element = el.elements[elementKey];
var element = el.elements[elementKey]
// 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)});
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("&")
options.requestOptions.requestPayload = paramObject;
options.requestOptions.requestPayloadString = paramsString;
options.requestOptions.requestPayload = paramObject
options.requestOptions.requestPayloadString = paramsString
el.setAttribute(attrClick, "submit");
el.setAttribute(attrClick, "submit")
options.triggerElement = el;
this.loadUrl(virtLinkElement.href, options);
};
options.triggerElement = el
this.loadUrl(virtLinkElement.href, options)
}
var isDefaultPrevented = function(event) {
return event.defaultPrevented || event.returnValue === false;
};
return event.defaultPrevented || event.returnValue === false
}
module.exports = function(el) {
var that = this
@@ -92,7 +90,6 @@ module.exports = function(el) {
return
}
if (event.keyCode === 13) {
formAction.call(that, el, event)
}

View File

@@ -9,10 +9,10 @@ var attrKey = "data-pjax-keyup-state"
var linkAction = function(el, event) {
// Since loadUrl modifies options and we may add our own modifications below,
// clone it so the changes don't persist
var options = clone(this.options);
var options = clone(this.options)
// Initialize requestOptions since loadUrl expects it to be an object
options.requestOptions = {};
options.requestOptions = {}
// Dont break browser special behavior on links (like page in new window)
if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
@@ -66,7 +66,7 @@ var linkAction = function(el, event) {
}
var isDefaultPrevented = function(event) {
return event.defaultPrevented || event.returnValue === false;
return event.defaultPrevented || event.returnValue === false
}
module.exports = function(el) {

View File

@@ -1,11 +1,11 @@
module.exports = function() {
if (this.options.debug && console) {
if (typeof console.log === "function") {
console.log.apply(console, arguments);
console.log.apply(console, arguments)
}
// ie is weird
else if (console.log) {
console.log(arguments);
console.log(arguments)
}
}
}

View File

@@ -19,7 +19,7 @@ module.exports = function(options) {
ga("send", "pageview", {page: location.pathname, title: document.title})
}
}
options.scrollTo = (typeof options.scrollTo === "undefined") ? 0 : options.scrollTo;
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
options.debug = options.debug || false