Move the initialization of "page labels" out of PDFViewerApplication.load
Over time, with more and more API-functionality added, the `PDFViewerApplication.load` method has become quite large and complex. In an attempt to improve the current situation somewhat, this patch moves the fetching and initialization of "page labels" out into its own (private) helper method instead.
This commit is contained in:
parent
9dedaa5eb9
commit
32f1d0de76
76
web/app.js
76
web/app.js
@ -1185,39 +1185,6 @@ const PDFViewerApplication = {
|
||||
});
|
||||
});
|
||||
|
||||
pdfDocument.getPageLabels().then(labels => {
|
||||
if (!labels || AppOptions.get("disablePageLabels")) {
|
||||
return;
|
||||
}
|
||||
const numLabels = labels.length;
|
||||
if (numLabels !== this.pagesCount) {
|
||||
console.error(
|
||||
"The number of Page Labels does not match " +
|
||||
"the number of pages in the document."
|
||||
);
|
||||
return;
|
||||
}
|
||||
let i = 0;
|
||||
// Ignore page labels that correspond to standard page numbering.
|
||||
while (i < numLabels && labels[i] === (i + 1).toString()) {
|
||||
i++;
|
||||
}
|
||||
if (i === numLabels) {
|
||||
return;
|
||||
}
|
||||
|
||||
pdfViewer.setPageLabels(labels);
|
||||
pdfThumbnailViewer.setPageLabels(labels);
|
||||
|
||||
// Changing toolbar page display to use labels and we need to set
|
||||
// the label of the current page.
|
||||
this.toolbar.setPagesCount(pdfDocument.numPages, true);
|
||||
this.toolbar.setPageNumber(
|
||||
pdfViewer.currentPageNumber,
|
||||
pdfViewer.currentPageLabel
|
||||
);
|
||||
});
|
||||
|
||||
pagesPromise.then(async () => {
|
||||
const [openAction, javaScript] = await Promise.all([
|
||||
openActionPromise,
|
||||
@ -1269,6 +1236,8 @@ const PDFViewerApplication = {
|
||||
});
|
||||
});
|
||||
|
||||
this._initializePageLabels(pdfDocument);
|
||||
|
||||
pdfDocument
|
||||
.getMetadata()
|
||||
.then(({ info, metadata, contentDispositionFilename }) => {
|
||||
@ -1408,6 +1377,47 @@ const PDFViewerApplication = {
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
async _initializePageLabels(pdfDocument) {
|
||||
const labels = await pdfDocument.getPageLabels();
|
||||
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
return; // The document was closed while the page labels resolved.
|
||||
}
|
||||
if (!labels || AppOptions.get("disablePageLabels")) {
|
||||
return;
|
||||
}
|
||||
const numLabels = labels.length;
|
||||
if (numLabels !== this.pagesCount) {
|
||||
console.error(
|
||||
"The number of Page Labels does not match the number of pages in the document."
|
||||
);
|
||||
return;
|
||||
}
|
||||
let i = 0;
|
||||
// Ignore page labels that correspond to standard page numbering.
|
||||
while (i < numLabels && labels[i] === (i + 1).toString()) {
|
||||
i++;
|
||||
}
|
||||
if (i === numLabels) {
|
||||
return;
|
||||
}
|
||||
const { pdfViewer, pdfThumbnailViewer, toolbar } = this;
|
||||
|
||||
pdfViewer.setPageLabels(labels);
|
||||
pdfThumbnailViewer.setPageLabels(labels);
|
||||
|
||||
// Changing toolbar page display to use labels and we need to set
|
||||
// the label of the current page.
|
||||
toolbar.setPagesCount(numLabels, true);
|
||||
toolbar.setPageNumber(
|
||||
pdfViewer.currentPageNumber,
|
||||
pdfViewer.currentPageLabel
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user