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 AnnotationType = sharedUtil.AnnotationType;
|
||||||
var OPS = sharedUtil.OPS;
|
var OPS = sharedUtil.OPS;
|
||||||
var Util = sharedUtil.Util;
|
var Util = sharedUtil.Util;
|
||||||
|
var isBool = sharedUtil.isBool;
|
||||||
var isString = sharedUtil.isString;
|
var isString = sharedUtil.isString;
|
||||||
var isArray = sharedUtil.isArray;
|
var isArray = sharedUtil.isArray;
|
||||||
var isInt = sharedUtil.isInt;
|
var isInt = sharedUtil.isInt;
|
||||||
@ -729,14 +730,29 @@ var LinkAnnotation = (function LinkAnnotationClosure() {
|
|||||||
case 'GoToR':
|
case 'GoToR':
|
||||||
var urlDict = action.get('F');
|
var urlDict = action.get('F');
|
||||||
if (isDict(urlDict)) {
|
if (isDict(urlDict)) {
|
||||||
// We assume that the 'url' is a Filspec dictionary
|
// We assume that we found a FileSpec dictionary
|
||||||
// and fetch the url without checking any further
|
// and fetch the URL without checking any further.
|
||||||
url = urlDict.get('F') || '';
|
url = urlDict.get('F') || null;
|
||||||
|
} else if (isString(urlDict)) {
|
||||||
|
url = urlDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: pdf reference says that GoToR
|
// NOTE: the destination is relative to the *remote* document.
|
||||||
// can also have 'NewWindow' attribute
|
var remoteDest = action.get('D');
|
||||||
dest = 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;
|
break;
|
||||||
|
|
||||||
case 'Named':
|
case 'Named':
|
||||||
|
@ -31,6 +31,7 @@ var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
|
|||||||
var AnnotationType = sharedUtil.AnnotationType;
|
var AnnotationType = sharedUtil.AnnotationType;
|
||||||
var Util = sharedUtil.Util;
|
var Util = sharedUtil.Util;
|
||||||
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
var addLinkAttributes = displayDOMUtils.addLinkAttributes;
|
||||||
|
var LinkTarget = displayDOMUtils.LinkTarget;
|
||||||
var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
|
var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
|
||||||
var warn = sharedUtil.warn;
|
var warn = sharedUtil.warn;
|
||||||
var CustomStyle = displayDOMUtils.CustomStyle;
|
var CustomStyle = displayDOMUtils.CustomStyle;
|
||||||
@ -278,7 +279,10 @@ var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
|
|||||||
this.container.className = 'linkAnnotation';
|
this.container.className = 'linkAnnotation';
|
||||||
|
|
||||||
var link = document.createElement('a');
|
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.url) {
|
||||||
if (this.data.action) {
|
if (this.data.action) {
|
||||||
|
@ -114,15 +114,15 @@ var LinkTargetStringMap = [
|
|||||||
/**
|
/**
|
||||||
* @typedef ExternalLinkParameters
|
* @typedef ExternalLinkParameters
|
||||||
* @typedef {Object} ExternalLinkParameters
|
* @typedef {Object} ExternalLinkParameters
|
||||||
* @property {string} url
|
* @property {string} url - An absolute URL.
|
||||||
* @property {LinkTarget} target
|
* @property {LinkTarget} target - The link target.
|
||||||
* @property {string} rel
|
* @property {string} rel - The link relationship.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds various attributes (href, title, target, rel) to hyperlinks.
|
* Adds various attributes (href, title, target, rel) to hyperlinks.
|
||||||
* @param {HTMLLinkElement} link - The link element.
|
* @param {HTMLLinkElement} link - The link element.
|
||||||
* @param {ExternalLinkParameters} params - An object with the properties.
|
* @param {ExternalLinkParameters} params
|
||||||
*/
|
*/
|
||||||
function addLinkAttributes(link, params) {
|
function addLinkAttributes(link, params) {
|
||||||
var url = params && params.url;
|
var url = params && params.url;
|
||||||
@ -134,7 +134,7 @@ function addLinkAttributes(link, params) {
|
|||||||
target = getDefaultSetting('externalLinkTarget');
|
target = getDefaultSetting('externalLinkTarget');
|
||||||
}
|
}
|
||||||
link.target = LinkTargetStringMap[target];
|
link.target = LinkTargetStringMap[target];
|
||||||
// Strip referrer from the URL.
|
|
||||||
var rel = params.rel;
|
var rel = params.rel;
|
||||||
if (typeof rel === 'undefined') {
|
if (typeof rel === 'undefined') {
|
||||||
rel = getDefaultSetting('externalLinkRel');
|
rel = getDefaultSetting('externalLinkRel');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user