Files
pjax/lib/proto/parse-options.js

41 lines
1.6 KiB
JavaScript
Raw Normal View History

/* global _gaq: true, ga: true */
var defaultSwitches = require("../switches")
2018-01-09 00:44:20 -05:00
module.exports = function(options) {
2018-01-29 23:20:00 -05:00
options = options || {}
2018-01-24 11:30:46 +00:00
options.elements = options.elements || "a[href], form[action]"
options.selectors = options.selectors || ["title", ".js-Pjax"]
options.switches = options.switches || {}
options.switchesOptions = options.switchesOptions || {}
options.history = options.history || true
options.analytics = (typeof options.analytics === "function" || options.analytics === false) ?
options.analytics :
function() {
if (window._gaq) {
_gaq.push(["_trackPageview"])
}
if (window.ga) {
ga("send", "pageview", {page: location.pathname, title: document.title})
}
}
2018-01-24 11:30:46 +00:00
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
options.timeout = options.timeout || 0
// we cant replace body.outerHTML or head.outerHTML
// it create a bug where new body or new head are created in the dom
// if you set head.outerHTML, a new body tag is appended, so the dom get 2 body
// & it break the switchFallback which replace head & body
2018-01-24 11:30:46 +00:00
if (!options.switches.head) {
options.switches.head = defaultSwitches.switchElementsAlt
}
2018-01-24 11:30:46 +00:00
if (!options.switches.body) {
options.switches.body = defaultSwitches.switchElementsAlt
}
2018-01-24 11:30:46 +00:00
this.options = options
}