mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
[api-minor] Add a wrapper around the addLinkAttributes
-function, in the API, to the PDFLinkService
implementations
This patch helps reduce some duplication, given that we now have a few essentially identical `addLinkAttributes` call-sites in the code-base. To prevent runtime errors in the Annotation/XFA-layer code, we'll warn if a custom/incomplete `PDFLinkService` is being used (limited to GENERIC builds).
This commit is contained in:
parent
bb9c905c5d
commit
8cb6efec2d
9 changed files with 67 additions and 45 deletions
|
@ -1358,7 +1358,6 @@ class BaseViewer {
|
|||
* @param {PDFPage} pdfPage
|
||||
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
|
||||
* data in forms.
|
||||
* @property {IPDFLinkService} linkService
|
||||
* @returns {XfaLayerBuilder}
|
||||
*/
|
||||
createXfaLayerBuilder(pageDiv, pdfPage, annotationStorage = null) {
|
||||
|
|
|
@ -63,6 +63,13 @@ class IPDFLinkService {
|
|||
*/
|
||||
goToPage(val) {}
|
||||
|
||||
/**
|
||||
* @param {HTMLAnchorElement} link
|
||||
* @param {string} url
|
||||
* @param {boolean} [newWindow]
|
||||
*/
|
||||
addLinkAttributes(link, url, newWindow = false) {}
|
||||
|
||||
/**
|
||||
* @param dest - The PDF destination object.
|
||||
* @returns {string} The hyperlink to the PDF object.
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
|
||||
|
||||
import { addLinkAttributes, LinkTarget } from "pdfjs-lib";
|
||||
import { parseQueryString } from "./ui_utils.js";
|
||||
|
||||
/**
|
||||
|
@ -227,6 +228,21 @@ class PDFLinkService {
|
|||
this.pdfViewer.scrollPageIntoView({ pageNumber });
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around the `addLinkAttributes`-function in the API.
|
||||
* @param {HTMLAnchorElement} link
|
||||
* @param {string} url
|
||||
* @param {boolean} [newWindow]
|
||||
*/
|
||||
addLinkAttributes(link, url, newWindow = false) {
|
||||
addLinkAttributes(link, {
|
||||
url,
|
||||
target: newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
|
||||
rel: this.externalLinkRel,
|
||||
enabled: this.externalLinkEnabled,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|Array} dest - The PDF destination object.
|
||||
* @returns {string} The hyperlink to the PDF object.
|
||||
|
@ -514,10 +530,7 @@ function isValidExplicitDestination(dest) {
|
|||
*/
|
||||
class SimpleLinkService {
|
||||
constructor() {
|
||||
this.externalLinkTarget = null;
|
||||
this.externalLinkRel = null;
|
||||
this.externalLinkEnabled = true;
|
||||
this._ignoreDestinationZoom = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -561,6 +574,15 @@ class SimpleLinkService {
|
|||
*/
|
||||
goToPage(val) {}
|
||||
|
||||
/**
|
||||
* @param {HTMLAnchorElement} link
|
||||
* @param {string} url
|
||||
* @param {boolean} [newWindow]
|
||||
*/
|
||||
addLinkAttributes(link, url, newWindow = false) {
|
||||
addLinkAttributes(link, { url, enabled: this.externalLinkEnabled });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dest - The PDF destination object.
|
||||
* @returns {string} The hyperlink to the PDF object.
|
||||
|
|
|
@ -13,12 +13,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
addLinkAttributes,
|
||||
createPromiseCapability,
|
||||
LinkTarget,
|
||||
} from "pdfjs-lib";
|
||||
import { BaseTreeViewer } from "./base_tree_viewer.js";
|
||||
import { createPromiseCapability } from "pdfjs-lib";
|
||||
import { SidebarView } from "./ui_utils.js";
|
||||
|
||||
/**
|
||||
|
@ -115,12 +111,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
|
|||
const { linkService } = this;
|
||||
|
||||
if (url) {
|
||||
addLinkAttributes(element, {
|
||||
url,
|
||||
target: newWindow ? LinkTarget.BLANK : linkService.externalLinkTarget,
|
||||
rel: linkService.externalLinkRel,
|
||||
enabled: linkService.externalLinkEnabled,
|
||||
});
|
||||
linkService.addLinkAttributes(element, url, newWindow);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,8 @@ import { PDFSinglePageViewer } from "./pdf_single_page_viewer.js";
|
|||
* @property {HTMLButtonElement} printButton - Button to print the document.
|
||||
* @property {HTMLButtonElement} downloadButton - Button to download the
|
||||
* document.
|
||||
* @property {HTMLLinkElement} viewBookmarkButton - Button to obtain a bookmark
|
||||
* link to the current location in the document.
|
||||
* @property {HTMLAnchorElement} viewBookmarkButton - Button to obtain a
|
||||
* bookmark link to the current location in the document.
|
||||
* @property {HTMLButtonElement} firstPageButton - Button to go to the first
|
||||
* page in the document.
|
||||
* @property {HTMLButtonElement} lastPageButton - Button to go to the last page
|
||||
|
|
|
@ -43,8 +43,8 @@ const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading";
|
|||
* @property {HTMLButtonElement} presentationModeButton - Button to switch to
|
||||
* presentation mode.
|
||||
* @property {HTMLButtonElement} download - Button to download the document.
|
||||
* @property {HTMLAElement} viewBookmark - Element to link current url of
|
||||
* the page view.
|
||||
* @property {HTMLAnchorElement} viewBookmark - Button to obtain a bookmark link
|
||||
* to the current location in the document.
|
||||
*/
|
||||
|
||||
class Toolbar {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue