From 0ebb31fe87750e6b50a2cccc389c0170543af493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 10 Jun 2025 12:39:49 -0400 Subject: [PATCH] fix: #13484, clear tooltip if cursor leaves link and doesn't enter tooltip --- public/src/client/topic.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index 0480d3844c..3bb50a5da5 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -309,12 +309,14 @@ define('forum/topic', [ } let timeoutId = 0; let destroyed = false; + let cursorOnPreviewTooltip = false; const postCache = {}; function destroyTooltip() { clearTimeout(timeoutId); timeoutId = 0; $('#post-tooltip').remove(); destroyed = true; + cursorOnPreviewTooltip = false; } function onClickOutside(ev) { @@ -328,6 +330,14 @@ define('forum/topic', [ $('[component="topic"]').on('mouseenter', 'a[component="post/parent"], [component="post/parent/content"] a,[component="post/content"] a, [component="topic/event"] a', async function () { const link = $(this); link.one('mouseleave', function () { + setTimeout(() => { + // If the mouse leaves the link and it's not on a tooltip, destroy the tooltip after a short delay + if (!cursorOnPreviewTooltip) { + destroyTooltip(); + } + }, 300); + + // if mouse leaves the link before the tooltip is rendered, clear the timeout if (timeoutId > 0) { clearTimeout(timeoutId); timeoutId = 0; @@ -352,7 +362,9 @@ define('forum/topic', [ const linkRect = link.offset(); const { top } = link.get(0).getBoundingClientRect(); const dropup = top > window.innerHeight / 2; - + tooltip.on('mouseenter', function () { + onPreviewTooltip = true; + }); tooltip.one('mouseleave', destroyTooltip); $(window).off('click', onClickOutside).one('click', onClickOutside); tooltip.css({