From 7cce41c26d5ba55be6165a721d992f293d8f9076 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 29 Apr 2022 17:04:56 +0200 Subject: [PATCH 1/2] Inline the `webViewerOpenFileViaURL` function in `webViewerInitialized` Given that `webViewerOpenFileViaURL` only has a single call-site, and also isn't a particularly large/complex function, it doesn't seem necessary for this to be a separate function and hence it's simply inlined instead. Also, changes the "no valid build-target was set"-case to throw unconditionally since the only way that it could ever be hit is if there are bugs in the `gulpfile`-code. --- web/app.js | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/web/app.js b/web/app.js index 6ae48d565..ab58e0a29 100644 --- a/web/app.js +++ b/web/app.js @@ -2229,7 +2229,18 @@ function webViewerInitialized() { ); try { - webViewerOpenFileViaURL(file); + if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { + if (file) { + PDFViewerApplication.open(file); + } else { + PDFViewerApplication._hideViewBookmark(); + } + } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { + PDFViewerApplication.setTitleUsingUrl(file, /* downloadUrl = */ file); + PDFViewerApplication.initPassiveLoading(); + } else { + throw new Error("Not implemented: webViewerInitialized"); + } } catch (reason) { PDFViewerApplication.l10n.get("loading_error").then(msg => { PDFViewerApplication._documentError(msg, reason); @@ -2237,25 +2248,6 @@ function webViewerInitialized() { } } -function webViewerOpenFileViaURL(file) { - if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - if (file) { - PDFViewerApplication.open(file); - } else { - PDFViewerApplication._hideViewBookmark(); - } - } else if (PDFJSDev.test("MOZCENTRAL || CHROME")) { - PDFViewerApplication.setTitleUsingUrl(file, /* downloadUrl = */ file); - PDFViewerApplication.initPassiveLoading(); - } else { - if (file) { - throw new Error("Not implemented: webViewerOpenFileViaURL"); - } else { - PDFViewerApplication._hideViewBookmark(); - } - } -} - function webViewerPageRendered({ pageNumber, error }) { // If the page is still visible when it has finished rendering, // ensure that the page number input loading indicator is hidden. From 9268924a1592a6b7c922b8de8447c1d80ce1c25e Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 29 Apr 2022 17:36:52 +0200 Subject: [PATCH 2/2] Only define the `webViewerFileInputChange`/`webViewerOpenFile` variables in GENERIC builds There's no point in having these variables defined (implicitly) as `undefined` in e.g. the Firefox PDF Viewer. By defining them with `var` and using ESList ignores, rather than `let`, we can move them into the relevant pre-processor block instead. Note that since the entire viewer-code is placed, by Webpack, in a top-level closure these variables will thus *not* become globally accessible. --- web/app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/app.js b/web/app.js index ab58e0a29..a34449fe8 100644 --- a/web/app.js +++ b/web/app.js @@ -2424,9 +2424,9 @@ function webViewerHashchange(evt) { } } -let webViewerFileInputChange, webViewerOpenFile; if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - webViewerFileInputChange = function (evt) { + // eslint-disable-next-line no-var + var webViewerFileInputChange = function (evt) { if (PDFViewerApplication.pdfViewer?.isInPresentationMode) { return; // Opening a new PDF file isn't supported in Presentation Mode. } @@ -2439,7 +2439,8 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { PDFViewerApplication.open(url); }; - webViewerOpenFile = function (evt) { + // eslint-disable-next-line no-var + var webViewerOpenFile = function (evt) { const fileInput = PDFViewerApplication.appConfig.openFileInput; fileInput.click(); };