Add scrollRestoration option
This commit is contained in:
@@ -377,6 +377,10 @@ It's called every time a page is switched, even for history buttons.
|
|||||||
|
|
||||||
Value (in px) to scrollTo when a page is switched.
|
Value (in px) to scrollTo when a page is switched.
|
||||||
|
|
||||||
|
##### `scrollRestoration` (Boolean, default true)
|
||||||
|
|
||||||
|
When set to true, attempt to restore the scroll position when navigating backwards or forwards.
|
||||||
|
|
||||||
##### `cacheBust` (Boolean, default true)
|
##### `cacheBust` (Boolean, default true)
|
||||||
|
|
||||||
When set to true,
|
When set to true,
|
||||||
|
|||||||
2
index.js
2
index.js
@@ -306,7 +306,7 @@ Pjax.prototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (state.options.scrollRestoration && state.options.scrollPos) {
|
||||||
window.scrollTo(state.options.scrollPos[0], state.options.scrollPos[1])
|
window.scrollTo(state.options.scrollPos[0], state.options.scrollPos[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ module.exports = function(options) {
|
|||||||
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust
|
this.options.cacheBust = (typeof this.options.cacheBust === "undefined") ? true : this.options.cacheBust
|
||||||
this.options.debug = this.options.debug || false
|
this.options.debug = this.options.debug || false
|
||||||
this.options.timeout = this.options.timeout || 0
|
this.options.timeout = this.options.timeout || 0
|
||||||
|
this.options.scrollRestoration = (typeof this.options.scrollRestoration !== "undefined") ? this.options.scrollRestoration : true
|
||||||
|
|
||||||
// we can’t replace body.outerHTML or head.outerHTML
|
// we can’t replace body.outerHTML or head.outerHTML
|
||||||
// it create a bug where new body or new head are created in the dom
|
// it create a bug where new body or new head are created in the dom
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ tape("test parse initalization options function", function(t) {
|
|||||||
t.deepEqual(body1.options.scrollTo, 0);
|
t.deepEqual(body1.options.scrollTo, 0);
|
||||||
t.deepEqual(body1.options.cacheBust, true);
|
t.deepEqual(body1.options.cacheBust, true);
|
||||||
t.deepEqual(body1.options.debug, false);
|
t.deepEqual(body1.options.debug, false);
|
||||||
|
t.deepEqual(body1.options.scrollRestoration, true)
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user