]> git.parisson.com Git - pdf.js.git/commitdiff
Fix the bookmark button and redo the anchor prefix.
authorBrendan Dahl <brendan.dahl@gmail.com>
Tue, 24 Jan 2012 23:46:53 +0000 (15:46 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Tue, 24 Jan 2012 23:46:53 +0000 (15:46 -0800)
web/viewer.js

index 131d12b42ed18457de330128cb0d1a216e5cbdea..b784e6f5ad710fa6949425e88d66630d76ff83e7 100644 (file)
@@ -269,18 +269,15 @@ var PDFView = {
   },
 
   getDestinationHash: function pdfViewGetDestinationHash(dest) {
-    // We add the full url for the extension so the anchor links don't come up
-    // as resource:// urls and so open in new tab/window works.
-    var url = PDFJS.isFirefoxExtension ? this.url.split('#')[0] : '';
     if (typeof dest === 'string')
-      return url + '#' + escape(dest);
+      return PDFView.getAnchorUrl('#' + escape(dest));
     if (dest instanceof Array) {
       var destRef = dest[0]; // see navigateTo method for dest format
       var pageNumber = destRef instanceof Object ?
         this.pagesRefMap[destRef.num + ' ' + destRef.gen + ' R'] :
         (destRef + 1);
       if (pageNumber) {
-        var pdfOpenParams = url + '#page=' + pageNumber;
+        var pdfOpenParams = PDFView.getAnchorUrl('#page=' + pageNumber);
         var destKind = dest[1];
         if ('name' in destKind && destKind.name == 'XYZ') {
           var scale = (dest[4] || this.currentScale);
@@ -295,6 +292,17 @@ var PDFView = {
     return '';
   },
 
+  /**
+   * For the firefox extension we prefix the full url on anchor links so they
+   * don't come up as resource:// urls and so open in new tab/window works.
+   * @param {String} anchor The anchor hash include the #.
+   */
+  getAnchorUrl: function getAnchorUrl(anchor) {
+    if (PDFJS.isFirefoxExtension)
+      return this.url.split('#')[0] + anchor;
+    return anchor;
+  },
+
   /**
    * Show the error box.
    * @param {String} message A message that is human readable.
@@ -1087,8 +1095,8 @@ function updateViewarea() {
   store.set('zoom', normalizedScaleValue);
   store.set('scrollLeft', Math.round(topLeft.x));
   store.set('scrollTop', Math.round(topLeft.y));
-
-  document.getElementById('viewBookmark').href = pdfOpenParams;
+  var href = PDFView.getAnchorUrl(pdfOpenParams);
+  document.getElementById('viewBookmark').href = href;
 }
 
 window.addEventListener('scroll', function webViewerScroll(evt) {