[Pkg-javascript-commits] [pdf.js] 63/106: Make PDFHistory optional in PDFLinkService

David Prévot taffit at moszumanska.debian.org
Sat Jun 20 21:34:22 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 20881dc99abd520274766e9161d772c6277d8b17
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Fri May 29 13:37:28 2015 +0200

    Make PDFHistory optional in PDFLinkService
    
    Currently `PDFLinkService` requires access to a `PDFHistory` instance in order for it to work correctly (and to avoid errors). If we want `PDFLinkService` to be more useful in custom viewers, I don't think that we actually want to force it to have a `PDFHistory` instance.
    Hence this patch, which contains a very simply approach to make `PDFHistory` optional.
---
 web/pdf_link_service.js | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js
index 4e3213a..54244e1 100644
--- a/web/pdf_link_service.js
+++ b/web/pdf_link_service.js
@@ -89,12 +89,14 @@ var PDFLinkService = (function () {
           }
           self.pdfViewer.scrollPageIntoView(pageNumber, dest);
 
-          // Update the browsing history.
-          self.pdfHistory.push({
-            dest: dest,
-            hash: destString,
-            page: pageNumber
-          });
+          if (self.pdfHistory) {
+            // Update the browsing history.
+            self.pdfHistory.push({
+              dest: dest,
+              hash: destString,
+              page: pageNumber
+            });
+          }
         } else {
           self.pdfDocument.getPageIndex(destRef).then(function (pageIndex) {
             var pageNum = pageIndex + 1;
@@ -173,7 +175,9 @@ var PDFLinkService = (function () {
         var params = parseQueryString(hash);
         // borrowing syntax from "Parameters for Opening PDF Files"
         if ('nameddest' in params) {
-          this.pdfHistory.updateNextHashParam(params.nameddest);
+          if (this.pdfHistory) {
+            this.pdfHistory.updateNextHashParam(params.nameddest);
+          }
           this.navigateTo(params.nameddest);
           return;
         }
@@ -233,7 +237,9 @@ var PDFLinkService = (function () {
       } else if (/^\d+$/.test(hash)) { // page number
         this.page = hash;
       } else { // named destination
-        this.pdfHistory.updateNextHashParam(unescape(hash));
+        if (this.pdfHistory) {
+          this.pdfHistory.updateNextHashParam(unescape(hash));
+        }
         this.navigateTo(unescape(hash));
       }
     },
@@ -245,11 +251,15 @@ var PDFLinkService = (function () {
       // See PDF reference, table 8.45 - Named action
       switch (action) {
         case 'GoBack':
-          this.pdfHistory.back();
+          if (this.pdfHistory) {
+            this.pdfHistory.back();
+          }
           break;
 
         case 'GoForward':
-          this.pdfHistory.forward();
+          if (this.pdfHistory) {
+            this.pdfHistory.forward();
+          }
           break;
 
         case 'NextPage':

-- 
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