Skip to content

Commit 24244d1

Browse files
authored
Merge pull request #25526 from github/repo-sync
repo sync
2 parents 1fa775c + a38d6de commit 24244d1

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/events/components/events.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ function initLinkEvent() {
305305
}
306306

307307
function initHoverEvent() {
308+
let timer: number | null = null
308309
document.documentElement.addEventListener('mouseover', (evt) => {
309310
const target = evt.target as HTMLElement
310311
const link = target.closest('a[href]') as HTMLAnchorElement | null
@@ -317,13 +318,27 @@ function initHoverEvent() {
317318
if (!mainContent || !mainContent.contains(link)) return
318319

319320
if (hoveredUrls.has(link.href)) return // Otherwise this is a flood of events
320-
const sameSite = link.origin === location.origin
321-
hoveredUrls.add(link.href)
322-
sendEvent({
323-
type: EventType.hover,
324-
hover_url: link.href,
325-
hover_samesite: sameSite,
326-
})
321+
322+
if (timer) {
323+
window.clearTimeout(timer)
324+
}
325+
timer = window.setTimeout(() => {
326+
const sameSite = link.origin === location.origin
327+
hoveredUrls.add(link.href)
328+
sendEvent({
329+
type: EventType.hover,
330+
hover_url: link.href,
331+
hover_samesite: sameSite,
332+
})
333+
}, 500)
334+
})
335+
336+
// Doesn't matter which link you hovered on that triggered a timer,
337+
// you're clearly not hovering over it any more.
338+
document.documentElement.addEventListener('mouseout', () => {
339+
if (timer) {
340+
window.clearTimeout(timer)
341+
}
327342
})
328343
}
329344

0 commit comments

Comments
 (0)