From 5b348d21a79a7ecd9ac30d808edaa03c3f26dfef Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Thu, 30 Jul 2020 10:37:16 -0700 Subject: added option to follow link to external page --- src/client/apis/hypothesis/HypothesisUtils.ts | 5 ++--- src/client/views/linking/LinkEditor.tsx | 6 ++++++ src/client/views/linking/LinkMenuItem.tsx | 13 +++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts index e245552b1..8eaad2905 100644 --- a/src/client/apis/hypothesis/HypothesisUtils.ts +++ b/src/client/apis/hypothesis/HypothesisUtils.ts @@ -38,10 +38,9 @@ export namespace Hypothesis { })); }; - // Construct an URL which will scroll the web page to a specific annotation's position + // Construct an URL which will automatically scroll the web page to a specific annotation's position export const makeAnnotationUrl = (annotationId: string, baseUrl: string) => { - return `https://hyp.is/${annotationId}/${baseUrl}`; // embeds the generic version of Hypothes.is client, not the Dash version - // return baseUrl + '#annotations:' + annotationId; + return `${baseUrl}#annotations:${annotationId}`; }; // Extract username from Hypothe.is's userId format diff --git a/src/client/views/linking/LinkEditor.tsx b/src/client/views/linking/LinkEditor.tsx index 04329182e..737e0ca28 100644 --- a/src/client/views/linking/LinkEditor.tsx +++ b/src/client/views/linking/LinkEditor.tsx @@ -395,6 +395,12 @@ export class LinkEditor extends React.Component { onPointerDown={() => this.changeFollowBehavior("inTab")}> Always open in new tab + {this.props.linkDoc.linksToAnnotation ? +
this.changeFollowBehavior("openExternal")}> + Always open in external page +
+ : null} ; diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx index 475133010..079e130ea 100644 --- a/src/client/views/linking/LinkMenuItem.tsx +++ b/src/client/views/linking/LinkMenuItem.tsx @@ -153,15 +153,20 @@ export class LinkMenuItem extends React.Component { async followDefault() { DocumentLinksButton.EditLink = undefined; LinkDocPreview.LinkInfo = undefined; + const linkDoc = this.props.linkDoc; - if (this.props.linkDoc.followLinkLocation && this.props.linkDoc.followLinkLocation !== "Default") { - this.props.addDocTab(this.props.destinationDoc, StrCast(this.props.linkDoc.followLinkLocation)); + if (linkDoc.followLinkLocation === "openExternal" && this.props.destinationDoc.type === DocumentType.WEB) { + window.open(Hypothesis.makeAnnotationUrl(StrCast(this.props.linkDoc.annotationId), '_blank')); + return; + } + + if (linkDoc.followLinkLocation && linkDoc.followLinkLocation !== "Default") { + this.props.addDocTab(this.props.destinationDoc, StrCast(linkDoc.followLinkLocation)); } else { DocumentManager.Instance.FollowLink(this.props.linkDoc, this.props.sourceDoc, doc => this.props.addDocTab(doc, "onRight"), false); } - // this.props.linkDoc.linksToAnnotation && setTimeout(() => window.open(StrCast(this.props.linkDoc.annotationUrl), '_blank'), 1000); // open external page if hypothes.is annotation - this.props.linkDoc.linksToAnnotation && Hypothesis.scrollToAnnotation(StrCast(this.props.linkDoc.annotationId)); + linkDoc.linksToAnnotation && Hypothesis.scrollToAnnotation(StrCast(this.props.linkDoc.annotationId)); } @undoBatch -- cgit v1.2.3-70-g09d2