From 8627ab4dee89ce1f116a2c00823171f54e7ae33e Mon Sep 17 00:00:00 2001
From: Austin Anderson <angerson@google.com>
Date: Tue, 9 May 2023 13:22:11 -0700
Subject: [PATCH] Handle live focus differently

---
 tf_oss_dashboard/script.js | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/tf_oss_dashboard/script.js b/tf_oss_dashboard/script.js
index 187752d..4182d60 100644
--- a/tf_oss_dashboard/script.js
+++ b/tf_oss_dashboard/script.js
@@ -106,15 +106,19 @@ $(function () {
      // Empty!
   // If the hash matches a Category on the page, then scroll to it
   } else if (document.getElementById(unescaped)) {
-    let scrolled = false
-    $(window).focus(function() {
-      if (!scrolled) {
-        setTimeout(function () {
-          document.getElementById(unescaped).scrollIntoView();
-        }, 100);
-        scrolled = true
-      }
-    })
+    if (document.hasFocus()) {
+      document.getElementById(unescaped).scrollIntoView();
+    } else {
+      let scrolled = false
+      $(window).focus(function() {
+        if (!scrolled) {
+          setTimeout(function () {
+            document.getElementById(unescaped).scrollIntoView();
+          }, 100);
+          scrolled = true
+        }
+      })
+    }
   // If the hash is exactly 41 chars (hash sign # plus a 40-char sha hash),
   // just show that modal.
   } else if (window.location.hash.length == 41) {
-- 
GitLab