« get me outta code hell

client: hide tooltip right away when clicking elsewhere - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-09 13:21:57 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-09 13:21:57 -0400
commitebeac7ba40450962bfba46c9c7b9d7eefb829225 (patch)
tree694d0d375ed0f30c67f6deab838839ab2c679d1f /src/static
parent708698289ab1a544c2ce066ade7171ff87108f82 (diff)
client: hide tooltip right away when clicking elsewhere
Diffstat (limited to 'src/static')
-rw-r--r--src/static/client3.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/static/client3.js b/src/static/client3.js
index 35d9ab6..deeac6a 100644
--- a/src/static/client3.js
+++ b/src/static/client3.js
@@ -1032,6 +1032,33 @@ function addHoverableTooltipPageListeners() {
       hideCurrentlyShownTooltip();
     }
   });
+
+  document.body.addEventListener('click', domEvent => {
+    const {clientX, clientY} = domEvent;
+
+    const pointIsOverHoverableOrTooltip =
+      pointIsOverAnyOf(getHoverablesAndTooltips());
+
+    if (!pointIsOverHoverableOrTooltip(clientX, clientY)) {
+      // Hide with "intent to replace" - we aren't actually going to replace
+      // the tooltip with a new one, but this intent indicates that it should
+      // be hidden right away, instead of showing. What we're really replacing,
+      // or rather removing, is the state of interacting with tooltips at all.
+      hideCurrentlyShownTooltip(true);
+
+      // Part of that state is fast hovering, which should be canceled out.
+      state.fastHovering = false;
+      if (state.endFastHoveringTimeout) {
+        clearTimeout(state.endFastHoveringTimeout);
+        state.endFastHoveringTimeout = null;
+      }
+
+      // Also cancel out of transitioning a tooltip hidden - this isn't caught
+      // by `hideCurrentlyShownTooltip` because a transitioning-hidden tooltip
+      // doesn't count as "shown" anymore.
+      cancelTransitioningTooltipHidden();
+    }
+  });
 }
 
 clientSteps.addPageListeners.push(addHoverableTooltipPageListeners);