Prettier fixes
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
var forEachEls = require("../foreach-els")
|
||||
var forEachEls = require("../foreach-els");
|
||||
|
||||
module.exports = function(els, events, listener, useCapture) {
|
||||
events = (typeof events === "string" ? events.split(" ") : events)
|
||||
events = typeof events === "string" ? events.split(" ") : events;
|
||||
|
||||
events.forEach(function(e) {
|
||||
forEachEls(els, function(el) {
|
||||
el.removeEventListener(e, listener, useCapture)
|
||||
})
|
||||
})
|
||||
}
|
||||
el.removeEventListener(e, listener, useCapture);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
var forEachEls = require("../foreach-els")
|
||||
var forEachEls = require("../foreach-els");
|
||||
|
||||
module.exports = function(els, events, listener, useCapture) {
|
||||
events = (typeof events === "string" ? events.split(" ") : events)
|
||||
events = typeof events === "string" ? events.split(" ") : events;
|
||||
|
||||
events.forEach(function(e) {
|
||||
forEachEls(els, function(el) {
|
||||
el.addEventListener(e, listener, useCapture)
|
||||
})
|
||||
})
|
||||
}
|
||||
el.addEventListener(e, listener, useCapture);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
var forEachEls = require("../foreach-els")
|
||||
var forEachEls = require("../foreach-els");
|
||||
|
||||
module.exports = function(els, events, opts) {
|
||||
events = (typeof events === "string" ? events.split(" ") : events)
|
||||
events = typeof events === "string" ? events.split(" ") : events;
|
||||
|
||||
events.forEach(function(e) {
|
||||
var event
|
||||
event = document.createEvent("HTMLEvents")
|
||||
event.initEvent(e, true, true)
|
||||
event.eventName = e
|
||||
var event;
|
||||
event = document.createEvent("HTMLEvents");
|
||||
event.initEvent(e, true, true);
|
||||
event.eventName = e;
|
||||
if (opts) {
|
||||
Object.keys(opts).forEach(function(key) {
|
||||
event[key] = opts[key]
|
||||
})
|
||||
event[key] = opts[key];
|
||||
});
|
||||
}
|
||||
|
||||
forEachEls(els, function(el) {
|
||||
var domFix = false
|
||||
var domFix = false;
|
||||
if (!el.parentNode && el !== document && el !== window) {
|
||||
// THANK YOU IE (9/10/11)
|
||||
// dispatchEvent doesn't work if the element is not in the DOM
|
||||
domFix = true
|
||||
document.body.appendChild(el)
|
||||
domFix = true;
|
||||
document.body.appendChild(el);
|
||||
}
|
||||
el.dispatchEvent(event)
|
||||
el.dispatchEvent(event);
|
||||
if (domFix) {
|
||||
el.parentNode.removeChild(el)
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,123 +1,139 @@
|
||||
var on = require("../events/on")
|
||||
var clone = require("../util/clone")
|
||||
var on = require("../events/on");
|
||||
var clone = require("../util/clone");
|
||||
|
||||
var attrState = "data-pjax-state"
|
||||
var attrState = "data-pjax-state";
|
||||
|
||||
var formAction = function(el, event) {
|
||||
if (isDefaultPrevented(event)) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 = {
|
||||
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", options.requestOptions.requestUrl)
|
||||
var virtLinkElement = document.createElement("a");
|
||||
virtLinkElement.setAttribute("href", options.requestOptions.requestUrl);
|
||||
|
||||
var attrValue = checkIfShouldAbort(virtLinkElement, options)
|
||||
var attrValue = checkIfShouldAbort(virtLinkElement, options);
|
||||
if (attrValue) {
|
||||
el.setAttribute(attrState, attrValue)
|
||||
return
|
||||
el.setAttribute(attrState, attrValue);
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.preventDefault();
|
||||
|
||||
if (el.enctype === "multipart/form-data") {
|
||||
options.requestOptions.formData = new FormData(el)
|
||||
}
|
||||
else {
|
||||
options.requestOptions.requestParams = parseFormElements(el)
|
||||
options.requestOptions.formData = new FormData(el);
|
||||
} else {
|
||||
options.requestOptions.requestParams = parseFormElements(el);
|
||||
}
|
||||
|
||||
el.setAttribute(attrState, "submit")
|
||||
el.setAttribute(attrState, "submit");
|
||||
|
||||
options.triggerElement = el
|
||||
this.loadUrl(virtLinkElement.href, options)
|
||||
}
|
||||
options.triggerElement = el;
|
||||
this.loadUrl(virtLinkElement.href, options);
|
||||
};
|
||||
|
||||
function parseFormElements(el) {
|
||||
var requestParams = []
|
||||
var formElements = el.elements
|
||||
var requestParams = [];
|
||||
var formElements = el.elements;
|
||||
|
||||
for (var i = 0; i < formElements.length; i++) {
|
||||
var element = formElements[i]
|
||||
var tagName = element.tagName.toLowerCase()
|
||||
var element = formElements[i];
|
||||
var tagName = element.tagName.toLowerCase();
|
||||
// jscs:disable disallowImplicitTypeConversion
|
||||
if (!!element.name && element.attributes !== undefined && tagName !== "button") {
|
||||
if (
|
||||
!!element.name &&
|
||||
element.attributes !== undefined &&
|
||||
tagName !== "button"
|
||||
) {
|
||||
// jscs:enable disallowImplicitTypeConversion
|
||||
var type = element.attributes.type
|
||||
var type = element.attributes.type;
|
||||
|
||||
if ((!type || type.value !== "checkbox" && type.value !== "radio") || element.checked) {
|
||||
if (
|
||||
!type ||
|
||||
(type.value !== "checkbox" && type.value !== "radio") ||
|
||||
element.checked
|
||||
) {
|
||||
// Build array of values to submit
|
||||
var values = []
|
||||
var values = [];
|
||||
|
||||
if (tagName === "select") {
|
||||
var opt
|
||||
var opt;
|
||||
|
||||
for (var j = 0; j < element.options.length; j++) {
|
||||
opt = element.options[j]
|
||||
opt = element.options[j];
|
||||
if (opt.selected && !opt.disabled) {
|
||||
values.push(opt.hasAttribute("value") ? opt.value : opt.text)
|
||||
values.push(opt.hasAttribute("value") ? opt.value : opt.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
values.push(element.value)
|
||||
} else {
|
||||
values.push(element.value);
|
||||
}
|
||||
|
||||
for (var k = 0; k < values.length; k++) {
|
||||
requestParams.push({
|
||||
name: encodeURIComponent(element.name),
|
||||
value: encodeURIComponent(values[k])
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return requestParams
|
||||
return requestParams;
|
||||
}
|
||||
|
||||
function checkIfShouldAbort(virtLinkElement, options) {
|
||||
// Ignore external links.
|
||||
if (virtLinkElement.protocol !== window.location.protocol || virtLinkElement.host !== window.location.host) {
|
||||
return "external"
|
||||
if (
|
||||
virtLinkElement.protocol !== window.location.protocol ||
|
||||
virtLinkElement.host !== window.location.host
|
||||
) {
|
||||
return "external";
|
||||
}
|
||||
|
||||
// Ignore click if we are on an anchor on the same page
|
||||
if (virtLinkElement.hash && virtLinkElement.href.replace(virtLinkElement.hash, "") === window.location.href.replace(location.hash, "")) {
|
||||
return "anchor"
|
||||
if (
|
||||
virtLinkElement.hash &&
|
||||
virtLinkElement.href.replace(virtLinkElement.hash, "") ===
|
||||
window.location.href.replace(location.hash, "")
|
||||
) {
|
||||
return "anchor";
|
||||
}
|
||||
|
||||
// Ignore empty anchor "foo.html#"
|
||||
if (virtLinkElement.href === window.location.href.split("#")[0] + "#") {
|
||||
return "anchor-empty"
|
||||
return "anchor-empty";
|
||||
}
|
||||
|
||||
// if declared as a full reload, just normally submit the form
|
||||
if (options.currentUrlFullReload && virtLinkElement.href === window.location.href.split("#")[0]) {
|
||||
return "reload"
|
||||
if (
|
||||
options.currentUrlFullReload &&
|
||||
virtLinkElement.href === window.location.href.split("#")[0]
|
||||
) {
|
||||
return "reload";
|
||||
}
|
||||
}
|
||||
|
||||
var isDefaultPrevented = function(event) {
|
||||
return event.defaultPrevented || event.returnValue === false
|
||||
}
|
||||
return event.defaultPrevented || event.returnValue === false;
|
||||
};
|
||||
|
||||
module.exports = function(el) {
|
||||
var that = this
|
||||
var that = this;
|
||||
|
||||
el.setAttribute(attrState, "")
|
||||
el.setAttribute(attrState, "");
|
||||
|
||||
on(el, "submit", function(event) {
|
||||
formAction.call(that, el, event)
|
||||
})
|
||||
}
|
||||
formAction.call(that, el, event);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,82 +1,99 @@
|
||||
var on = require("../events/on")
|
||||
var clone = require("../util/clone")
|
||||
var on = require("../events/on");
|
||||
var clone = require("../util/clone");
|
||||
|
||||
var attrState = "data-pjax-state"
|
||||
var attrState = "data-pjax-state";
|
||||
|
||||
var linkAction = function(el, event) {
|
||||
if (isDefaultPrevented(event)) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
var attrValue = checkIfShouldAbort(el, event)
|
||||
var attrValue = checkIfShouldAbort(el, event);
|
||||
if (attrValue) {
|
||||
el.setAttribute(attrState, attrValue)
|
||||
return
|
||||
el.setAttribute(attrState, attrValue);
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
event.preventDefault();
|
||||
|
||||
// don’t do "nothing" if user try to reload the page by clicking the same link twice
|
||||
if (
|
||||
this.options.currentUrlFullReload &&
|
||||
el.href === window.location.href.split("#")[0]
|
||||
) {
|
||||
el.setAttribute(attrState, "reload")
|
||||
this.reload()
|
||||
return
|
||||
el.setAttribute(attrState, "reload");
|
||||
this.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
el.setAttribute(attrState, "load")
|
||||
el.setAttribute(attrState, "load");
|
||||
|
||||
options.triggerElement = el
|
||||
this.loadUrl(el.href, options)
|
||||
}
|
||||
options.triggerElement = el;
|
||||
this.loadUrl(el.href, options);
|
||||
};
|
||||
|
||||
function checkIfShouldAbort(el, event) {
|
||||
// Don’t break browser special behavior on links (like page in new window)
|
||||
if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
||||
return "modifier"
|
||||
if (
|
||||
event.which > 1 ||
|
||||
event.metaKey ||
|
||||
event.ctrlKey ||
|
||||
event.shiftKey ||
|
||||
event.altKey
|
||||
) {
|
||||
return "modifier";
|
||||
}
|
||||
|
||||
// we do test on href now to prevent unexpected behavior if for some reason
|
||||
// user have href that can be dynamically updated
|
||||
|
||||
// Ignore external links.
|
||||
if (el.protocol !== window.location.protocol || el.host !== window.location.host) {
|
||||
return "external"
|
||||
if (
|
||||
el.protocol !== window.location.protocol ||
|
||||
el.host !== window.location.host
|
||||
) {
|
||||
return "external";
|
||||
}
|
||||
|
||||
// Ignore anchors on the same page (keep native behavior)
|
||||
if (el.hash && el.href.replace(el.hash, "") === window.location.href.replace(location.hash, "")) {
|
||||
return "anchor"
|
||||
if (
|
||||
el.hash &&
|
||||
el.href.replace(el.hash, "") ===
|
||||
window.location.href.replace(location.hash, "")
|
||||
) {
|
||||
return "anchor";
|
||||
}
|
||||
|
||||
// Ignore empty anchor "foo.html#"
|
||||
if (el.href === window.location.href.split("#")[0] + "#") {
|
||||
return "anchor-empty"
|
||||
return "anchor-empty";
|
||||
}
|
||||
}
|
||||
|
||||
var isDefaultPrevented = function(event) {
|
||||
return event.defaultPrevented || event.returnValue === false
|
||||
}
|
||||
return event.defaultPrevented || event.returnValue === false;
|
||||
};
|
||||
|
||||
module.exports = function(el) {
|
||||
var that = this
|
||||
var that = this;
|
||||
|
||||
el.setAttribute(attrState, "")
|
||||
el.setAttribute(attrState, "");
|
||||
|
||||
on(el, "click", function(event) {
|
||||
linkAction.call(that, el, event)
|
||||
})
|
||||
linkAction.call(that, el, event);
|
||||
});
|
||||
|
||||
on(el, "keyup", function(event) {
|
||||
if (event.keyCode === 13) {
|
||||
linkAction.call(that, el, event)
|
||||
}
|
||||
}.bind(this))
|
||||
}
|
||||
on(
|
||||
el,
|
||||
"keyup",
|
||||
function(event) {
|
||||
if (event.keyCode === 13) {
|
||||
linkAction.call(that, el, event);
|
||||
}
|
||||
}.bind(this)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
var attrState = "data-pjax-state"
|
||||
var attrState = "data-pjax-state";
|
||||
|
||||
module.exports = function(el) {
|
||||
switch (el.tagName.toLowerCase()) {
|
||||
case "a":
|
||||
// only attach link if el does not already have link attached
|
||||
if (!el.hasAttribute(attrState)) {
|
||||
this.attachLink(el)
|
||||
this.attachLink(el);
|
||||
}
|
||||
break
|
||||
break;
|
||||
|
||||
case "form":
|
||||
// only attach link if el does not already have link attached
|
||||
if (!el.hasAttribute(attrState)) {
|
||||
this.attachForm(el)
|
||||
this.attachForm(el);
|
||||
}
|
||||
break
|
||||
break;
|
||||
|
||||
default:
|
||||
throw "Pjax can only be applied on <a> or <form> submit"
|
||||
throw "Pjax can only be applied on <a> or <form> submit";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
module.exports = function(obj) {
|
||||
/* istanbul ignore if */
|
||||
if (null === obj || "object" !== typeof obj) {
|
||||
return obj
|
||||
return obj;
|
||||
}
|
||||
var copy = obj.constructor()
|
||||
var copy = obj.constructor();
|
||||
for (var attr in obj) {
|
||||
if (obj.hasOwnProperty(attr)) {
|
||||
copy[attr] = obj[attr]
|
||||
copy[attr] = obj[attr];
|
||||
}
|
||||
}
|
||||
return copy
|
||||
}
|
||||
return copy;
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
module.exports = function contains(doc, selectors, el) {
|
||||
for (var i = 0; i < selectors.length; i++) {
|
||||
var selectedEls = doc.querySelectorAll(selectors[i])
|
||||
var selectedEls = doc.querySelectorAll(selectors[i]);
|
||||
for (var j = 0; j < selectedEls.length; j++) {
|
||||
if (selectedEls[j].contains(el)) {
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
module.exports = function(target) {
|
||||
if (target == null) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
|
||||
var to = Object(target)
|
||||
var to = Object(target);
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i]
|
||||
var source = arguments[i];
|
||||
|
||||
if (source != null) {
|
||||
for (var key in source) {
|
||||
// Avoid bugs when hasOwnProperty is shadowed
|
||||
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||||
to[key] = source[key]
|
||||
to[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return to
|
||||
}
|
||||
return to;
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
module.exports = function() {}
|
||||
module.exports = function() {};
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
module.exports = function(uri, key, value) {
|
||||
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i")
|
||||
var separator = uri.indexOf("?") !== -1 ? "&" : "?"
|
||||
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
|
||||
var separator = uri.indexOf("?") !== -1 ? "&" : "?";
|
||||
if (uri.match(re)) {
|
||||
return uri.replace(re, "$1" + key + "=" + value + "$2")
|
||||
return uri.replace(re, "$1" + key + "=" + value + "$2");
|
||||
} else {
|
||||
return uri + separator + key + "=" + value;
|
||||
}
|
||||
else {
|
||||
return uri + separator + key + "=" + value
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user