Simplify options assignment
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
var defaultSwitches = require("../switches")
|
||||
|
||||
module.exports = function(options) {
|
||||
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
|
||||
this.options.analytics = (typeof this.options.analytics === "function" || this.options.analytics === false) ?
|
||||
this.options.analytics :
|
||||
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"])
|
||||
@@ -19,20 +18,22 @@ module.exports = function(options) {
|
||||
ga("send", "pageview", {page: location.pathname, title: document.title})
|
||||
}
|
||||
}
|
||||
this.options.scrollTo = (typeof this.options.scrollTo === "undefined") ? 0 : this.options.scrollTo;
|
||||
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust
|
||||
this.options.debug = this.options.debug || false
|
||||
this.options.timeout = this.options.timeout || 0
|
||||
this.options.scrollRestoration = (typeof this.options.scrollRestoration !== "undefined") ? this.options.scrollRestoration : true
|
||||
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 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) {
|
||||
this.options.switches.head = defaultSwitches.switchElementsAlt
|
||||
if (!options.switches.head) {
|
||||
options.switches.head = defaultSwitches.switchElementsAlt
|
||||
}
|
||||
if (!this.options.switches.body) {
|
||||
this.options.switches.body = defaultSwitches.switchElementsAlt
|
||||
if (!options.switches.body) {
|
||||
options.switches.body = defaultSwitches.switchElementsAlt
|
||||
}
|
||||
|
||||
this.options = options
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user