Delay initialization of the AnnotationStorage callbacks slightly in the default viewer

These callbacks should not be necessary *before* the document has been initialized. Furthermore, move the functionality to a new helper-method since `PDFViewerApplication.load` is already quite large.
This commit is contained in:
Jonas Jenwald 2020-12-19 12:49:12 +01:00
parent 958ea2be8b
commit 517af6b6ab

View File

@ -1287,14 +1287,6 @@ const PDFViewerApplication = {
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
this.pdfDocumentProperties.setDocument(pdfDocument, this.url); this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
const annotationStorage = pdfDocument.annotationStorage;
annotationStorage.onSetModified = function () {
window.addEventListener("beforeunload", beforeUnload);
};
annotationStorage.onResetModified = function () {
window.removeEventListener("beforeunload", beforeUnload);
};
const pdfViewer = this.pdfViewer; const pdfViewer = this.pdfViewer;
pdfViewer.setDocument(pdfDocument); pdfViewer.setDocument(pdfDocument);
const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer; const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer;
@ -1322,6 +1314,7 @@ const PDFViewerApplication = {
firstPagePromise.then(pdfPage => { firstPagePromise.then(pdfPage => {
this.loadingBar.setWidth(this.appConfig.viewerContainer); this.loadingBar.setWidth(this.appConfig.viewerContainer);
this._initializeAnnotationStorageCallbacks(pdfDocument);
Promise.all([ Promise.all([
animationStarted, animationStarted,
@ -1878,6 +1871,23 @@ const PDFViewerApplication = {
} }
}, },
/**
* @private
*/
_initializeAnnotationStorageCallbacks(pdfDocument) {
if (pdfDocument !== this.pdfDocument) {
return;
}
const { annotationStorage } = pdfDocument;
annotationStorage.onSetModified = function () {
window.addEventListener("beforeunload", beforeUnload);
};
annotationStorage.onResetModified = function () {
window.removeEventListener("beforeunload", beforeUnload);
};
},
setInitialView( setInitialView(
storedHash, storedHash,
{ rotation, sidebarView, scrollMode, spreadMode } = {} { rotation, sidebarView, scrollMode, spreadMode } = {}