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.
This commit is contained in:
parent
b63ef7a8b6
commit
f3f825cc71
@ -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':
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user