From 958ea2be8be36b08eb4672031335235d1512645d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 19 Dec 2020 12:38:10 +0100 Subject: [PATCH] Move the functionality of the `webViewerDownloadOrSave` function into a new `PDFViewerApplication` method instead Given that this relies on accessing properties on the `PDFDocumentProxy`-instance, it seems more appropriate for this code to live in `PDFViewerApplication`. --- web/app.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/web/app.js b/web/app.js index df37f0c66..7eb431c7d 100644 --- a/web/app.js +++ b/web/app.js @@ -1060,6 +1060,14 @@ const PDFViewerApplication = { }); }, + downloadOrSave(options) { + if (this.pdfDocument?.annotationStorage.size > 0) { + this.save(options); + } else { + this.download(options); + } + }, + /** * For PDF documents that contain e.g. forms and javaScript, we should only * trigger the fallback bar once the user has interacted with the page. @@ -2712,21 +2720,11 @@ function webViewerPresentationMode() { function webViewerPrint() { PDFViewerApplication.triggerPrinting(); } -function webViewerDownloadOrSave(sourceEventType) { - if ( - PDFViewerApplication.pdfDocument && - PDFViewerApplication.pdfDocument.annotationStorage.size > 0 - ) { - PDFViewerApplication.save({ sourceEventType }); - } else { - PDFViewerApplication.download({ sourceEventType }); - } -} function webViewerDownload() { - webViewerDownloadOrSave("download"); + PDFViewerApplication.downloadOrSave({ sourceEventType: "download" }); } function webViewerSave() { - webViewerDownloadOrSave("save"); + PDFViewerApplication.downloadOrSave({ sourceEventType: "save" }); } function webViewerFirstPage() { if (PDFViewerApplication.pdfDocument) {