Skip to content

Commit

Permalink
Merge pull request #12256 from escapewindow/12241-followup
Browse files Browse the repository at this point in the history
#12241 followup - move event listener to PDFViewerApplication.load
  • Loading branch information
timvandermeij authored Aug 21, 2020
2 parents 3c79093 + b142333 commit 909c5af
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 14 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 0 additions & 12 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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", {
Expand Down

0 comments on commit 909c5af

Please sign in to comment.