[Pkg-javascript-commits] [pdf.js] 379/414: Various improvements for `GoToR` actions

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:42 UTC 2016


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

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

commit f3f825cc71020cc44f17745f7f58a7fc0c9058d9
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Thu Mar 3 13:26:51 2016 +0100

    Various improvements for `GoToR` actions
    
     - Add support for the 'NewWindow' property.
    
     - Ensure that destinations are applied to the *remote* document, instead of the current one.
    
     - Handle the `F` entry being a standard string, instead of a dictionary.
---
 src/core/annotation.js          | 28 ++++++++++++++++++++++------
 src/display/annotation_layer.js |  6 +++++-
 src/display/dom_utils.js        | 10 +++++-----
 3 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/core/annotation.js b/src/core/annotation.js
index 23769d0..83f4385 100644
--- a/src/core/annotation.js
+++ b/src/core/annotation.js
@@ -37,6 +37,7 @@ var AnnotationFlag = sharedUtil.AnnotationFlag;
 var AnnotationType = sharedUtil.AnnotationType;
 var OPS = sharedUtil.OPS;
 var Util = sharedUtil.Util;
+var isBool = sharedUtil.isBool;
 var isString = sharedUtil.isString;
 var isArray = sharedUtil.isArray;
 var isInt = sharedUtil.isInt;
@@ -729,14 +730,29 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
         case 'GoToR':
           var urlDict = action.get('F');
           if (isDict(urlDict)) {
-            // We assume that the 'url' is a Filspec dictionary
-            // and fetch the url without checking any further
-            url = urlDict.get('F') || '';
+            // We assume that we found a FileSpec dictionary
+            // and fetch the URL without checking any further.
+            url = urlDict.get('F') || null;
+          } else if (isString(urlDict)) {
+            url = urlDict;
           }
 
-          // TODO: pdf reference says that GoToR
-          // can also have 'NewWindow' attribute
-          dest = action.get('D');
+          // NOTE: the destination is relative to the *remote* document.
+          var remoteDest = action.get('D');
+          if (remoteDest) {
+            if (isName(remoteDest)) {
+              remoteDest = remoteDest.name;
+            }
+            if (isString(remoteDest) && isString(url)) {
+              var baseUrl = url.split('#')[0];
+              url = baseUrl + '#' + remoteDest;
+            }
+          }
+          // The 'NewWindow' property, equal to `LinkTarget.BLANK`.
+          var newWindow = action.get('NewWindow');
+          if (isBool(newWindow)) {
+            data.newWindow = newWindow;
+          }
           break;
 
         case 'Named':
diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js
index 5a6cba8..cef981d 100644
--- a/src/display/annotation_layer.js
+++ b/src/display/annotation_layer.js
@@ -31,6 +31,7 @@ var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
 var AnnotationType = sharedUtil.AnnotationType;
 var Util = sharedUtil.Util;
 var addLinkAttributes = displayDOMUtils.addLinkAttributes;
+var LinkTarget = displayDOMUtils.LinkTarget;
 var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
 var warn = sharedUtil.warn;
 var CustomStyle = displayDOMUtils.CustomStyle;
@@ -278,7 +279,10 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
       this.container.className = 'linkAnnotation';
 
       var link = document.createElement('a');
-      addLinkAttributes(link, { url: this.data.url });
+      addLinkAttributes(link, {
+        url: this.data.url,
+        target: (this.data.newWindow ? LinkTarget.BLANK : undefined),
+      });
 
       if (!this.data.url) {
         if (this.data.action) {
diff --git a/src/display/dom_utils.js b/src/display/dom_utils.js
index 65a2b74..efa2124 100644
--- a/src/display/dom_utils.js
+++ b/src/display/dom_utils.js
@@ -114,15 +114,15 @@ var LinkTargetStringMap = [
 /**
  * @typedef ExternalLinkParameters
  * @typedef {Object} ExternalLinkParameters
- * @property {string} url
- * @property {LinkTarget} target
- * @property {string} rel
+ * @property {string} url - An absolute URL.
+ * @property {LinkTarget} target - The link target.
+ * @property {string} rel - The link relationship.
  */
 
 /**
  * Adds various attributes (href, title, target, rel) to hyperlinks.
  * @param {HTMLLinkElement} link - The link element.
- * @param {ExternalLinkParameters} params - An object with the properties.
+ * @param {ExternalLinkParameters} params
  */
 function addLinkAttributes(link, params) {
   var url = params && params.url;
@@ -134,7 +134,7 @@ function addLinkAttributes(link, params) {
       target = getDefaultSetting('externalLinkTarget');
     }
     link.target = LinkTargetStringMap[target];
-    // Strip referrer from the URL.
+
     var rel = params.rel;
     if (typeof rel === 'undefined') {
       rel = getDefaultSetting('externalLinkRel');

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