1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Add a way to disable external links.

This commit is contained in:
Brendan Dahl 2019-08-20 14:43:24 -07:00
parent 852fc955bd
commit 98e989116c
6 changed files with 29 additions and 3 deletions

View file

@ -300,6 +300,7 @@ class LinkAnnotationElement extends AnnotationElement {
target: (data.newWindow ?
LinkTarget.BLANK : linkService.externalLinkTarget),
rel: linkService.externalLinkRel,
enabled: linkService.externalLinkEnabled,
});
if (!data.url) {

View file

@ -344,6 +344,8 @@ const LinkTargetStringMap = [
* The default value is `LinkTarget.NONE`.
* @property {string} rel - (optional) The link relationship.
* The default value is `DEFAULT_LINK_REL`.
* @property {boolean} enabled - (optional) Whether the link should be enabled.
* The default value is true.
*/
/**
@ -351,8 +353,17 @@ const LinkTargetStringMap = [
* @param {HTMLLinkElement} link - The link element.
* @param {ExternalLinkParameters} params
*/
function addLinkAttributes(link, { url, target, rel, } = {}) {
link.href = link.title = (url ? removeNullCharacters(url) : '');
function addLinkAttributes(link, { url, target, rel, enabled = true, } = {}) {
const urlNullRemoved = (url ? removeNullCharacters(url) : '');
if (enabled) {
link.href = link.title = urlNullRemoved;
} else {
link.href = '';
link.title = `Disabled: ${urlNullRemoved}`;
link.onclick = () => {
return false;
};
}
if (url) {
const LinkTargetValues = Object.values(LinkTarget);