2014-11-20 16:21:19 -08:00
|
|
|
|
/* global _gaq: true, ga: true */
|
|
|
|
|
|
|
2019-02-11 23:17:28 -05:00
|
|
|
|
var defaultSwitches = require("./switches");
|
2017-12-19 15:56:48 -05:00
|
|
|
|
|
2018-01-09 00:44:20 -05:00
|
|
|
|
module.exports = function(options) {
|
2019-02-11 23:17:28 -05:00
|
|
|
|
options = options || {};
|
|
|
|
|
|
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 =
|
|
|
|
|
|
typeof options.history === "undefined" ? true : options.history;
|
|
|
|
|
|
options.analytics =
|
|
|
|
|
|
typeof options.analytics === "function" || options.analytics === false
|
|
|
|
|
|
? options.analytics
|
|
|
|
|
|
: defaultAnalytics;
|
|
|
|
|
|
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;
|
|
|
|
|
|
options.currentUrlFullReload =
|
|
|
|
|
|
typeof options.currentUrlFullReload === "undefined"
|
|
|
|
|
|
? false
|
|
|
|
|
|
: options.currentUrlFullReload;
|
2014-11-20 14:39:48 -08:00
|
|
|
|
|
2018-02-02 09:52:44 -05:00
|
|
|
|
// We can’t replace body.outerHTML or head.outerHTML.
|
|
|
|
|
|
// It creates a bug where a new body or head are created in the DOM.
|
|
|
|
|
|
// If you set head.outerHTML, a new body tag is appended, so the DOM has 2 body nodes, and vice versa
|
2018-01-24 11:30:46 +00:00
|
|
|
|
if (!options.switches.head) {
|
2019-02-11 23:17:28 -05:00
|
|
|
|
options.switches.head = defaultSwitches.switchElementsAlt;
|
2014-11-20 14:39:48 -08:00
|
|
|
|
}
|
2018-01-24 11:30:46 +00:00
|
|
|
|
if (!options.switches.body) {
|
2019-02-11 23:17:28 -05:00
|
|
|
|
options.switches.body = defaultSwitches.switchElementsAlt;
|
2014-11-20 14:39:48 -08:00
|
|
|
|
}
|
2018-01-24 11:30:46 +00:00
|
|
|
|
|
2019-02-11 23:17:28 -05:00
|
|
|
|
return options;
|
|
|
|
|
|
};
|
2018-04-09 23:36:32 -04:00
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore next */
|
|
|
|
|
|
function defaultAnalytics() {
|
|
|
|
|
|
if (window._gaq) {
|
2019-02-11 23:17:28 -05:00
|
|
|
|
_gaq.push(["_trackPageview"]);
|
2018-04-09 23:36:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
if (window.ga) {
|
2019-02-11 23:17:28 -05:00
|
|
|
|
ga("send", "pageview", { page: location.pathname, title: document.title });
|
2018-04-09 23:36:32 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|