Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
calebporzio committed Jul 2, 2023
1 parent 5c12083 commit 2578870
Showing 1 changed file with 3 additions and 35 deletions.
38 changes: 3 additions & 35 deletions packages/navigate/src/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ export function whenThisLinkIsPressed(el, callback) {
export function whenThisLinkIsHoveredFor(el, ms = 60, callback) {
el.addEventListener('mouseenter', e => {
let timeout = setTimeout(() => {
callback(e)

}, ms)

let handler = () => {
clearTimeout(timeout)

clear
el.removeEventListener('mouseleave', handler)
}

el.addEventListener('mouseleave', handler)
callback(e)
})
}

Expand All @@ -50,35 +50,3 @@ export function extractDestinationFromLink(linkEl) {
export function createUrlObjectFromString(urlString) {
return new URL(urlString, document.baseURI)
}

let handleLinkClick = () => {}
let handleLinkHover = () => {}

export function whenALinkIsClicked(callback) {
handleLinkClick = callback

initializeLinksForClicking()
}

export function whenALinkIsHovered(callback) {
handleLinkHover = callback

initializeLinksForHovering()
}

export function extractDestinationFromLink(linkEl) {
return new URL(linkEl.getAttribute('href'), document.baseURI)
}

export function hijackNewLinksOnThePage() {
initializeLinksForClicking()
initializeLinksForHovering()
}

function initializeLinksForClicking() {
getLinks().forEach(el => {
el.addEventListener('click', e => {
e.preventDefault()

handleLinkClick(el)
}

0 comments on commit 2578870

Please sign in to comment.