loadUrl enhancements (#134)
`loadUrl` enhancements - Make `options` parameter optional - Allow partial overriding of instance options when calling `loadUrl` directly - Make `requestOptions` optional - Document `loadUrl` usage and provide examples
This commit was merged in pull request #134.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/* global _gaq: true, ga: true */
|
||||
|
||||
var defaultSwitches = require("../switches")
|
||||
var defaultSwitches = require("./switches")
|
||||
|
||||
module.exports = function(options) {
|
||||
options = options || {}
|
||||
@@ -36,5 +36,5 @@ module.exports = function(options) {
|
||||
options.switches.body = defaultSwitches.switchElementsAlt
|
||||
}
|
||||
|
||||
this.options = options
|
||||
return options
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
var on = require("../events/on")
|
||||
var clone = require("../clone")
|
||||
var clone = require("../util/clone")
|
||||
|
||||
var attrClick = "data-pjax-click-state"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
var on = require("../events/on")
|
||||
var clone = require("../clone")
|
||||
var clone = require("../util/clone")
|
||||
|
||||
var attrClick = "data-pjax-click-state"
|
||||
var attrKey = "data-pjax-keyup-state"
|
||||
@@ -9,9 +9,6 @@ var linkAction = function(el, event) {
|
||||
// clone it so the changes don't persist
|
||||
var options = clone(this.options)
|
||||
|
||||
// Initialize requestOptions since loadUrl expects it to be an object
|
||||
options.requestOptions = {}
|
||||
|
||||
// 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) {
|
||||
el.setAttribute(attrClick, "modifier")
|
||||
|
||||
@@ -3,10 +3,12 @@ var updateQueryString = require("./util/update-query-string");
|
||||
module.exports = function(location, options, callback) {
|
||||
options = options || {}
|
||||
var queryString
|
||||
var requestMethod = (options.requestMethod || "GET").toUpperCase()
|
||||
var requestParams = options.requestParams || null
|
||||
var requestOptions = options.requestOptions || {}
|
||||
var requestMethod = (requestOptions.requestMethod || "GET").toUpperCase()
|
||||
var requestParams = requestOptions.requestParams || null
|
||||
var requestPayload = null
|
||||
var request = new XMLHttpRequest()
|
||||
var timeout = options.timeout || 0
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === 4) {
|
||||
@@ -51,12 +53,12 @@ module.exports = function(location, options, callback) {
|
||||
}
|
||||
|
||||
// Add a timestamp as part of the query string if cache busting is enabled
|
||||
if (this.options.cacheBust) {
|
||||
if (options.cacheBust) {
|
||||
location = updateQueryString(location, "t", Date.now())
|
||||
}
|
||||
|
||||
request.open(requestMethod, location, true)
|
||||
request.timeout = options.timeout
|
||||
request.timeout = timeout
|
||||
request.setRequestHeader("X-Requested-With", "XMLHttpRequest")
|
||||
request.setRequestHeader("X-PJAX", "true")
|
||||
|
||||
|
||||
21
lib/util/extend.js
Normal file
21
lib/util/extend.js
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports = function(target) {
|
||||
if (target == null) {
|
||||
return target
|
||||
}
|
||||
|
||||
var to = Object(target)
|
||||
|
||||
for (var i = 1; i < arguments.length; 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]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return to
|
||||
}
|
||||
Reference in New Issue
Block a user