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:
parent
958ea2be8b
commit
517af6b6ab
26
web/app.js
26
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 } = {}
|
||||
|
Loading…
Reference in New Issue
Block a user