aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/apis/hypothesis/HypothesisUtils.ts22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts
index e15620a91..e245552b1 100644
--- a/src/client/apis/hypothesis/HypothesisUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisUtils.ts
@@ -69,9 +69,23 @@ export namespace Hypothesis {
};
export const scrollToAnnotation = (annotationId: string) => {
- document.dispatchEvent(new CustomEvent("scrollToAnnotation", {
- detail: annotationId,
- bubbles: true
- }));
+ var success = false;
+ const onSuccess = () => {
+ console.log("scroll success!!");
+ document.removeEventListener('scrollSuccess', onSuccess);
+ clearTimeout(interval);
+ success = true;
+ };
+
+ const interval = setInterval(() => { // keep trying to scroll every 200ms until annotations have loaded and scrolling is successful
+ console.log("send scroll");
+ document.dispatchEvent(new CustomEvent('scrollToAnnotation', {
+ detail: annotationId,
+ bubbles: true
+ }));
+ }, 200);
+
+ document.addEventListener('scrollSuccess', onSuccess); // listen for success message from client
+ setTimeout(() => !success && clearTimeout(interval), 10000); // give up if no success after 10s
};
} \ No newline at end of file