2014-11-20 16:21:19 -08:00
|
|
|
|
/* global _gaq: true, ga: true */
|
|
|
|
|
|
|
2017-12-19 15:56:48 -05:00
|
|
|
|
var defaultSwitches = require("../switches")
|
|
|
|
|
|
|
2018-01-09 00:44:20 -05:00
|
|
|
|
module.exports = function(options) {
|
2014-11-20 14:39:48 -08:00
|
|
|
|
this.options = options
|
|
|
|
|
|
this.options.elements = this.options.elements || "a[href], form[action]"
|
|
|
|
|
|
this.options.selectors = this.options.selectors || ["title", ".js-Pjax"]
|
|
|
|
|
|
this.options.switches = this.options.switches || {}
|
|
|
|
|
|
this.options.switchesOptions = this.options.switchesOptions || {}
|
|
|
|
|
|
this.options.history = this.options.history || true
|
2018-01-24 11:26:13 +00:00
|
|
|
|
this.options.analytics = (typeof this.options.analytics === "function" || this.options.analytics === false) ?
|
|
|
|
|
|
this.options.analytics :
|
|
|
|
|
|
function() {
|
|
|
|
|
|
if (window._gaq) {
|
|
|
|
|
|
_gaq.push(["_trackPageview"])
|
|
|
|
|
|
}
|
|
|
|
|
|
if (window.ga) {
|
|
|
|
|
|
ga("send", "pageview", {page: location.pathname, title: document.title})
|
|
|
|
|
|
}
|
2014-11-20 14:39:48 -08:00
|
|
|
|
}
|
2018-01-09 00:44:20 -05:00
|
|
|
|
this.options.scrollTo = (typeof this.options.scrollTo === "undefined") ? 0 : this.options.scrollTo;
|
|
|
|
|
|
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust
|
2014-11-20 14:39:48 -08:00
|
|
|
|
this.options.debug = this.options.debug || false
|
2018-01-07 23:56:11 -05:00
|
|
|
|
this.options.timeout = this.options.timeout || 0
|
2018-01-22 18:56:22 -05:00
|
|
|
|
this.options.scrollRestoration = (typeof this.options.scrollRestoration !== "undefined") ? this.options.scrollRestoration : true
|
2014-11-20 14:39:48 -08:00
|
|
|
|
|
|
|
|
|
|
// we can’t 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
|
|
|
|
|
|
if (!this.options.switches.head) {
|
2017-12-19 15:56:48 -05:00
|
|
|
|
this.options.switches.head = defaultSwitches.switchElementsAlt
|
2014-11-20 14:39:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
if (!this.options.switches.body) {
|
2017-12-19 15:56:48 -05:00
|
|
|
|
this.options.switches.body = defaultSwitches.switchElementsAlt
|
2014-11-20 14:39:48 -08:00
|
|
|
|
}
|
2018-01-07 23:56:11 -05:00
|
|
|
|
}
|