mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 10:15:37 +02:00
[api-minor] Add basic support for the SetOCGState
action (issue 15372)
Note that this patch implements the `SetOCGState`-handling in `PDFLinkService`, rather than as a new method in `OptionalContentConfig`[1], since this action is nothing but a series of `setVisibility`-calls and that it seems quite uncommon in real-world PDF documents. The new functionality also required some tweaks in the `PDFLayerViewer`, to ensure that the `layersView` in the sidebar is updated correctly when the optional-content visibility changes from "outside" of `PDFLayerViewer`. --- [1] We can obviously move this code into `OptionalContentConfig` instead, if deemed necessary, but for an initial implementation I figured that doing it this way might be acceptable.
This commit is contained in:
parent
e9bdbe4574
commit
cc4baa2fe9
10 changed files with 185 additions and 31 deletions
|
@ -597,6 +597,9 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||
} else if (data.action) {
|
||||
this._bindNamedAction(link, data.action);
|
||||
isBound = true;
|
||||
} else if (data.setOCGState) {
|
||||
this.#bindSetOCGState(link, data.setOCGState);
|
||||
isBound = true;
|
||||
} else if (data.dest) {
|
||||
this._bindLink(link, data.dest);
|
||||
isBound = true;
|
||||
|
@ -678,6 +681,20 @@ class LinkAnnotationElement extends AnnotationElement {
|
|||
link.className = "internalLink";
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind SetOCGState actions to the link element.
|
||||
* @param {Object} link
|
||||
* @param {Object} action
|
||||
*/
|
||||
#bindSetOCGState(link, action) {
|
||||
link.href = this.linkService.getAnchorUrl("");
|
||||
link.onclick = () => {
|
||||
this.linkService.executeSetOCGState(action);
|
||||
return false;
|
||||
};
|
||||
link.className = "internalLink";
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind JS actions to the link element.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue