[Pkg-javascript-commits] [pdf.js] 06/109: Move handling of the 'pagemode' hash parameter into `viewer.js` to restore the functionality

David Prévot taffit at moszumanska.debian.org
Fri Sep 25 03:04:10 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 5c26e5e2cd3fc01e3eb717a5ca5b119422fe8ef5
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Tue Aug 4 22:57:51 2015 +0200

    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 a89cdd7..2f14855 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 cbeda49..f5d82b5 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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list