Move the parseCurrentHash
helper function into PDFHistory
Looking at the `parseCurrentHash` function again it's now difficult for me to understand *what* I was thinking, since having a helper function that needs to be manually passed a `linkService` reference just looks weird.
This commit is contained in:
parent
d621899d50
commit
c5f2f870cb
@ -50,17 +50,6 @@ function getCurrentHash() {
|
||||
return document.location.hash;
|
||||
}
|
||||
|
||||
function parseCurrentHash(linkService) {
|
||||
let hash = unescape(getCurrentHash()).substring(1);
|
||||
let params = parseQueryString(hash);
|
||||
|
||||
let page = params.page | 0;
|
||||
if (!(Number.isInteger(page) && page > 0 && page <= linkService.pagesCount)) {
|
||||
page = null;
|
||||
}
|
||||
return { hash, page, rotation: linkService.rotation, };
|
||||
}
|
||||
|
||||
class PDFHistory {
|
||||
/**
|
||||
* @param {PDFHistoryOptions} options
|
||||
@ -125,7 +114,7 @@ class PDFHistory {
|
||||
this._position = null;
|
||||
|
||||
if (!this._isValidState(state, /* checkReload = */ true) || resetHistory) {
|
||||
let { hash, page, rotation, } = parseCurrentHash(this.linkService);
|
||||
const { hash, page, rotation, } = this._parseCurrentHash();
|
||||
|
||||
if (!hash || reInitialized || resetHistory) {
|
||||
// Ensure that the browser history is reset on PDF document load.
|
||||
@ -458,6 +447,20 @@ class PDFHistory {
|
||||
this._numPositionUpdates = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_parseCurrentHash() {
|
||||
const hash = unescape(getCurrentHash()).substring(1);
|
||||
let page = parseQueryString(hash).page | 0;
|
||||
|
||||
if (!(Number.isInteger(page) &&
|
||||
page > 0 && page <= this.linkService.pagesCount)) {
|
||||
page = null;
|
||||
}
|
||||
return { hash, page, rotation: this.linkService.rotation, };
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -530,7 +533,7 @@ class PDFHistory {
|
||||
// This case corresponds to the user changing the hash of the document.
|
||||
this._uid++;
|
||||
|
||||
let { hash, page, rotation, } = parseCurrentHash(this.linkService);
|
||||
const { hash, page, rotation, } = this._parseCurrentHash();
|
||||
this._pushOrReplaceState({ hash, page, rotation, },
|
||||
/* forceReplace = */ true);
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user