From b04c3733627175d14335777fe685b1ba84d657c6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Mon, 25 Apr 2022 10:06:47 +0200 Subject: [PATCH] Stop bundling the openFile-buttons in the MOZCENTRAL build Note how both of the openFile-buttons are always hidden during viewer initialization in the MOZCENTRAL build, i.e. the *built-in* Firefox PDF Viewer. Despite that we still include HTML, CSS, and JavaScript code for these buttons in the build. This patch *reduces* the size of the `gulp mozcentral` output by `1679` bytes, which isn't a lot but still cannot hurt. --- gulpfile.js | 7 ++++++- web/app.js | 2 +- web/secondary_toolbar.js | 8 +++++++- web/toolbar.js | 4 +++- web/viewer.css | 6 +++--- web/viewer.html | 4 ++++ web/viewer.js | 10 ++++++++-- 7 files changed, 32 insertions(+), 9 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 4835c6ae7..e25e103c3 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1239,6 +1239,11 @@ gulp.task( MOZCENTRAL_DIR + "browser/locales/en-US/pdfviewer/", FIREFOX_CONTENT_DIR = EXTENSION_SRC_DIR + "/firefox/content/"; + const MOZCENTRAL_WEB_FILES = [ + ...COMMON_WEB_FILES, + "!web/images/toolbarButton-openFile.svg", + ]; + // Clear out everything in the firefox extension build directory rimraf.sync(MOZCENTRAL_DIR); @@ -1263,7 +1268,7 @@ gulp.task( gulp.dest(MOZCENTRAL_CONTENT_DIR + "web") ), gulp - .src(COMMON_WEB_FILES, { base: "web/" }) + .src(MOZCENTRAL_WEB_FILES, { base: "web/" }) .pipe(gulp.dest(MOZCENTRAL_CONTENT_DIR + "web")), createCMapBundle().pipe( gulp.dest(MOZCENTRAL_CONTENT_DIR + "web/cmaps") diff --git a/web/app.js b/web/app.js index 9b2217fba..6ae48d565 100644 --- a/web/app.js +++ b/web/app.js @@ -2192,7 +2192,7 @@ function webViewerInitialized() { fileInput: evt.dataTransfer, }); }); - } else { + } else if (!PDFJSDev.test("MOZCENTRAL")) { appConfig.toolbar.openFile.hidden = true; appConfig.secondaryToolbar.openFileButton.hidden = true; } diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js index 1ab88f874..31a296e0c 100644 --- a/web/secondary_toolbar.js +++ b/web/secondary_toolbar.js @@ -65,7 +65,6 @@ class SecondaryToolbar { eventName: "presentationmode", close: true, }, - { element: options.openFileButton, eventName: "openfile", close: true }, { element: options.printButton, eventName: "print", close: true }, { element: options.downloadButton, eventName: "download", close: true }, { element: options.viewBookmarkButton, eventName: null, close: true }, @@ -141,6 +140,13 @@ class SecondaryToolbar { close: true, }, ]; + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { + this.buttons.push({ + element: options.openFileButton, + eventName: "openfile", + close: true, + }); + } this.items = { firstPage: options.firstPageButton, lastPage: options.lastPageButton, diff --git a/web/toolbar.js b/web/toolbar.js index 48e89dc6b..8fa02f78b 100644 --- a/web/toolbar.js +++ b/web/toolbar.js @@ -62,7 +62,6 @@ class Toolbar { { element: options.next, eventName: "nextpage" }, { element: options.zoomIn, eventName: "zoomin" }, { element: options.zoomOut, eventName: "zoomout" }, - { element: options.openFile, eventName: "openfile" }, { element: options.print, eventName: "print" }, { element: options.presentationModeButton, @@ -71,6 +70,9 @@ class Toolbar { { element: options.download, eventName: "download" }, { element: options.viewBookmark, eventName: null }, ]; + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { + this.buttons.push({ element: options.openFile, eventName: "openfile" }); + } this.items = { numPages: options.numPages, pageNumber: options.pageNumber, diff --git a/web/viewer.css b/web/viewer.css index d3f9b3ed9..3c6f3998c 100644 --- a/web/viewer.css +++ b/web/viewer.css @@ -77,7 +77,7 @@ --toolbarButton-zoomIn-icon: url(images/toolbarButton-zoomIn.svg); --toolbarButton-presentationMode-icon: url(images/toolbarButton-presentationMode.svg); --toolbarButton-print-icon: url(images/toolbarButton-print.svg); - --toolbarButton-openFile-icon: url(images/toolbarButton-openFile.svg); + --toolbarButton-openFile-icon: url(images/toolbarButton-openFile.svg); /* -webkit-non-mozcentral */ --toolbarButton-download-icon: url(images/toolbarButton-download.svg); --toolbarButton-bookmark-icon: url(images/toolbarButton-bookmark.svg); --toolbarButton-viewThumbnail-icon: url(images/toolbarButton-viewThumbnail.svg); @@ -821,8 +821,8 @@ select { mask-image: var(--toolbarButton-print-icon); } -.toolbarButton.openFile::before, -.secondaryToolbarButton.openFile::before { +.toolbarButton.openFile::before, /* -webkit-non-mozcentral */ +.secondaryToolbarButton.openFile::before /* -webkit-non-mozcentral */ { mask-image: var(--toolbarButton-openFile-icon); } diff --git a/web/viewer.html b/web/viewer.html index ab465f0e8..5b8b1a676 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -153,9 +153,11 @@ See https://github.com/adobe-type-tools/cmap-resources Presentation Mode + + + +