#12241 followup - move event listener to PDFViewerApplication.load

This commit is contained in:
Aki Sasaki 2020-08-21 09:53:39 -07:00
parent 0d5ef5dd0a
commit b1423336c3
2 changed files with 14 additions and 12 deletions

View File

@ -1165,6 +1165,14 @@ 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;
@ -2951,6 +2959,12 @@ function webViewerKeyDown(evt) {
}
}
function beforeUnload(evt) {
evt.preventDefault();
evt.returnValue = "";
return false;
}
/**
* Converts API PageLayout values to the format used by `PDFViewer`.
* NOTE: This is supported to the extent that the viewer implements the

View File

@ -127,12 +127,6 @@ function isSameScale(oldScale, newScale) {
return false;
}
function beforeUnload(evt) {
evt.preventDefault();
evt.returnValue = "";
return false;
}
/**
* Simple viewer control to display PDF content/pages.
* @implements {IRenderableView}
@ -442,12 +436,6 @@ class BaseViewer {
const firstPagePromise = pdfDocument.getPage(1);
const annotationStorage = pdfDocument.annotationStorage;
annotationStorage.onSetModified = function () {
window.addEventListener("beforeunload", beforeUnload);
};
annotationStorage.onResetModified = function () {
window.removeEventListener("beforeunload", beforeUnload);
};
this._pagesCapability.promise.then(() => {
this.eventBus.dispatch("pagesloaded", {