From 5c26e5e2cd3fc01e3eb717a5ca5b119422fe8ef5 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 4 Aug 2015 22:57:51 +0200 Subject: [PATCH] Move handling of the 'pagemode' hash parameter into `viewer.js` to restore the functionality This regressed in https://github.com/mozilla/pdf.js/commit/0ef6212b646427604b6968b8bc3cf2d6c048f012. Since the 'pagemode' hash parameter requires certain viewer functionality (e.g. thumbnails and an outline) in order to work, it seemed reasonable to move the functionality from `pdf_link_service.js` into `viewer.js`. Similar to `namedaction`, this patch makes use of an event to forward the 'pagemode' parameter. --- web/pdf_link_service.js | 12 +++++------- web/viewer.js | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index a89cdd72a..2f1485598 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -228,13 +228,11 @@ var PDFLinkService = (function () { this.page = pageNumber; // simple page } if ('pagemode' in params) { - if (params.pagemode === 'thumbs' || params.pagemode === 'bookmarks' || - params.pagemode === 'attachments') { - this.switchSidebarView((params.pagemode === 'bookmarks' ? - 'outline' : params.pagemode), true); - } else if (params.pagemode === 'none' && this.sidebarOpen) { - document.getElementById('sidebarToggle').click(); - } + var event = document.createEvent('CustomEvent'); + event.initCustomEvent('pagemode', true, true, { + mode: params.pagemode, + }); + this.pdfViewer.container.dispatchEvent(event); } } else if (/^\d+$/.test(hash)) { // page number this.page = hash; diff --git a/web/viewer.js b/web/viewer.js index cbeda49ef..f5d82b5ca 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -1566,6 +1566,30 @@ document.addEventListener('textlayerrendered', function (e) { //#endif }, true); +document.addEventListener('pagemode', function (evt) { + if (!PDFViewerApplication.initialized) { + return; + } + // Handle the 'pagemode' hash parameter, see also `PDFLinkService_setHash`. + var mode = evt.detail.mode; + switch (mode) { + case 'bookmarks': + // Note: Our code calls this property 'outline', even though the + // Open Parameter specification calls it 'bookmarks'. + mode = 'outline'; + /* falls through */ + case 'thumbs': + case 'attachments': + PDFViewerApplication.switchSidebarView(mode, true); + break; + case 'none': + if (PDFViewerApplication.sidebarOpen) { + document.getElementById('sidebarToggle').click(); + } + break; + } +}, true); + document.addEventListener('namedaction', function (e) { // Processing couple of named actions that might be useful. // See also PDFLinkService.executeNamedAction