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)
}