From 39cba5d25d45c439cbc9667f8cfbea008b0e6d86 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 28 Feb 2016 13:16:08 +0100 Subject: [PATCH] Remove `PDFThumbnailViewer_ensureThumbnailVisible` Functionality wise, `ensureThumbnailVisible` is essentially just a shorthand for `scrollThumbnailIntoView`. (And note that `PDFViewer` doesn't implement a `ensurePageVisible` method.) The only remaining usage of `PDFThumbnailViewer_ensureThumbnailVisible` is inside `PDFPresentationMode`, which introduces an otherwise unnecessary `PDFThumbnailViewer` dependency there. We're already relying on the `presentationmodechanged` event, in various files, to track the state of Presentation Mode. Thus we can simply listen for that event in `PDFSidebar` too, and update the thumbnails if necessary. --- web/pdf_presentation_mode.js | 7 ------- web/pdf_sidebar.js | 8 ++++++++ web/pdf_thumbnail_viewer.js | 7 ------- web/viewer.js | 1 - 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/web/pdf_presentation_mode.js b/web/pdf_presentation_mode.js index 5b492ce01..4da6f349c 100644 --- a/web/pdf_presentation_mode.js +++ b/web/pdf_presentation_mode.js @@ -25,8 +25,6 @@ var CONTROLS_SELECTOR = 'pdfPresentationModeControls'; * @property {HTMLDivElement} container - The container for the viewer element. * @property {HTMLDivElement} viewer - (optional) The viewer element. * @property {PDFViewer} pdfViewer - The document viewer. - * @property {PDFThumbnailViewer} pdfThumbnailViewer - (optional) The thumbnail - * viewer. * @property {Array} contextMenuItems - (optional) The menuitems that are added * to the context menu in Presentation Mode. */ @@ -43,7 +41,6 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() { this.container = options.container; this.viewer = options.viewer || options.container.firstElementChild; this.pdfViewer = options.pdfViewer; - this.pdfThumbnailViewer = options.pdfThumbnailViewer || null; var contextMenuItems = options.contextMenuItems || null; this.active = false; @@ -245,10 +242,6 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() { this._resetMouseScrollState(); this.container.removeAttribute('contextmenu'); this.contextMenuOpen = false; - - if (this.pdfThumbnailViewer) { - this.pdfThumbnailViewer.ensureThumbnailVisible(page); - } }, /** diff --git a/web/pdf_sidebar.js b/web/pdf_sidebar.js index 0490ef249..aa78803f5 100644 --- a/web/pdf_sidebar.js +++ b/web/pdf_sidebar.js @@ -317,6 +317,14 @@ var PDFSidebar = (function PDFSidebarClosure() { self.switchView(SidebarView.THUMBS); } }); + + // Update the thumbnailViewer, if visible, when exiting presentation mode. + window.addEventListener('presentationmodechanged', function(evt) { + if (!evt.detail.active && !evt.detail.switchInProgress && + self.isThumbnailViewVisible) { + self._updateThumbnailViewer(); + } + }); }, }; diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js index 816b31403..c76b9be6c 100644 --- a/web/pdf_thumbnail_viewer.js +++ b/web/pdf_thumbnail_viewer.js @@ -178,13 +178,6 @@ var PDFThumbnailViewer = (function PDFThumbnailViewerClosure() { return promise; }, - ensureThumbnailVisible: - function PDFThumbnailViewer_ensureThumbnailVisible(page) { - // Ensure that the thumbnail of the current page is visible - // when switching from another view. - scrollIntoView(document.getElementById('thumbnailContainer' + page)); - }, - forceRendering: function () { var visibleThumbs = this._getVisibleThumbs(); var thumbView = this.renderingQueue.getHighestPriority(visibleThumbs, diff --git a/web/viewer.js b/web/viewer.js index 1ab9ca30f..a478e11e9 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -229,7 +229,6 @@ var PDFViewerApplication = { container: container, viewer: viewer, pdfViewer: this.pdfViewer, - pdfThumbnailViewer: this.pdfThumbnailViewer, contextMenuItems: [ { element: document.getElementById('contextFirstPage'), handler: toolbar.firstPageClick.bind(toolbar) },