diff --git a/web/app.js b/web/app.js index 7eb431c7d..80a67da55 100644 --- a/web/app.js +++ b/web/app.js @@ -1287,14 +1287,6 @@ const PDFViewerApplication = { this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl); 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; pdfViewer.setDocument(pdfDocument); const { firstPagePromise, onePageRendered, pagesPromise } = pdfViewer; @@ -1322,6 +1314,7 @@ const PDFViewerApplication = { firstPagePromise.then(pdfPage => { this.loadingBar.setWidth(this.appConfig.viewerContainer); + this._initializeAnnotationStorageCallbacks(pdfDocument); Promise.all([ 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( storedHash, { rotation, sidebarView, scrollMode, spreadMode } = {}