[PDFHistory] Reduce unnecessary duplication, by introducing a helper-method for validating pageNumbers
This commit is contained in:
parent
9d0ce6e79f
commit
685a60055e
@ -205,13 +205,7 @@ class PDFHistory {
|
||||
`"${explicitDest}" is not a valid explicitDest parameter.`
|
||||
);
|
||||
return;
|
||||
} else if (
|
||||
!(
|
||||
Number.isInteger(pageNumber) &&
|
||||
pageNumber > 0 &&
|
||||
pageNumber <= this.linkService.pagesCount
|
||||
)
|
||||
) {
|
||||
} else if (!this._isValidPage(pageNumber)) {
|
||||
// Allow an unset `pageNumber` if and only if the history is still empty;
|
||||
// please refer to the `this._destination.page = null;` comment above.
|
||||
if (pageNumber !== null || this._destination) {
|
||||
@ -281,13 +275,7 @@ class PDFHistory {
|
||||
if (!this._initialized) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!(
|
||||
Number.isInteger(pageNumber) &&
|
||||
pageNumber > 0 &&
|
||||
pageNumber <= this.linkService.pagesCount
|
||||
)
|
||||
) {
|
||||
if (!this._isValidPage(pageNumber)) {
|
||||
console.error(
|
||||
`PDFHistory.pushPage: "${pageNumber}" is not a valid page number.`
|
||||
);
|
||||
@ -479,6 +467,15 @@ class PDFHistory {
|
||||
this._pushOrReplaceState(position, forceReplace);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_isValidPage(val) {
|
||||
return (
|
||||
Number.isInteger(val) && val > 0 && val <= this.linkService.pagesCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@ -548,14 +545,7 @@ class PDFHistory {
|
||||
const nameddest = params.nameddest || "";
|
||||
let page = params.page | 0;
|
||||
|
||||
if (
|
||||
!(
|
||||
Number.isInteger(page) &&
|
||||
page > 0 &&
|
||||
page <= this.linkService.pagesCount
|
||||
) ||
|
||||
(checkNameddest && nameddest.length > 0)
|
||||
) {
|
||||
if (!this._isValidPage(page) || (checkNameddest && nameddest.length > 0)) {
|
||||
page = null;
|
||||
}
|
||||
return { hash, page, rotation: this.linkService.rotation };
|
||||
|
Loading…
x
Reference in New Issue
Block a user