Fix async switches #110

Merged
BehindTheMath merged 3 commits from fix/async-switches into master 2018-01-22 10:55:30 -05:00
Showing only changes of commit 1957526273 - Show all commits

View File

@@ -175,7 +175,7 @@ Pjax.prototype = {
href = request.getResponseHeader("X-XHR-Redirected-To") href = request.getResponseHeader("X-XHR-Redirected-To")
} }
this.state.href = href this.state.href = href
this.state.options = options this.state.options = clone(options)
try { try {
this.loadContent(html, options) this.loadContent(html, options)
@@ -215,7 +215,9 @@ Pjax.prototype = {
}) })
}) })
if (this.state.options.history) { var state = this.state
if (state.options.history) {
if (this.firstrun) { if (this.firstrun) {
this.lastUid = this.maxUid = newUid() this.lastUid = this.maxUid = newUid()
this.firstrun = false this.firstrun = false
@@ -230,7 +232,6 @@ Pjax.prototype = {
// Update browser history // Update browser history
this.lastUid = this.maxUid = newUid() this.lastUid = this.maxUid = newUid()
var state = this.state
window.history.pushState({ window.history.pushState({
url: state.href, url: state.href,
title: state.options.title, title: state.options.title,
@@ -245,17 +246,17 @@ Pjax.prototype = {
}, this) }, this)
// Fire Events // Fire Events
trigger(document,"pjax:complete pjax:success", this.state.options) trigger(document,"pjax:complete pjax:success", state.options)
this.state.options.analytics() state.options.analytics()
// Scroll page to top on new page load // Scroll page to top on new page load
if (this.state.options.scrollTo !== false) { if (state.options.scrollTo !== false) {
if (this.state.options.scrollTo.length > 1) { if (state.options.scrollTo.length > 1) {
window.scrollTo(this.state.options.scrollTo[0], this.state.options.scrollTo[1]) window.scrollTo(state.options.scrollTo[0], state.options.scrollTo[1])
} }
else { else {
window.scrollTo(0, this.state.options.scrollTo) window.scrollTo(0, state.options.scrollTo)
} }
} }