Skip to content

Commit

Permalink
A couple of small (viewer) tweaks of tooltip-only Annotations (PR 123…
Browse files Browse the repository at this point in the history
…33 follow-up)

Ensure that these tooltip-only Annotations are handled as "internalLink"s, to ensure that they behave as expected in PresentationMode (e.g. they should still use a `pointer`-cursor).

Ensure that `PDFLinkService.getDestinationHash` won't create links with empty hashes, since those don't really make a lot of sense in general (this improves things for tooltip-only Annotations).

This PDF file can be used for testing: http://mirrors.ctan.org/macros/latex/contrib/pdfcomment/doc/pdfcomment.pdf#page=14
  • Loading branch information
Snuffleupagus committed Oct 23, 2020
1 parent 1eaf9c9 commit 9f8d980
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/display/annotation_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class LinkAnnotationElement extends AnnotationElement {
}
return false;
};
if (destination) {
if (destination || destination === /* isTooltipOnly = */ "") {
link.className = "internalLink";
}
}
Expand Down
13 changes: 8 additions & 5 deletions web/pdf_link_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,22 @@ class PDFLinkService {
*/
getDestinationHash(dest) {
if (typeof dest === "string") {
return this.getAnchorUrl("#" + escape(dest));
}
if (Array.isArray(dest)) {
if (dest.length > 0) {
return this.getAnchorUrl("#" + escape(dest));
}
} else if (Array.isArray(dest)) {
const str = JSON.stringify(dest);
return this.getAnchorUrl("#" + escape(str));
if (str.length > 0) {
return this.getAnchorUrl("#" + escape(str));
}
}
return this.getAnchorUrl("");
}

/**
* Prefix the full url on anchor links to make sure that links are resolved
* relative to the current URL instead of the one defined in <base href>.
* @param {string} anchor The anchor hash, including the #.
* @param {string} anchor - The anchor hash, including the #.
* @returns {string} The hyperlink to the PDF object.
*/
getAnchorUrl(anchor) {
Expand Down

0 comments on commit 9f8d980

Please sign in to comment.