This repository was archived by the owner on Jun 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
This repository was archived by the owner on Jun 26, 2025. It is now read-only.
Tinro should rewrite links on auxclick event too #111
Copy link
Copy link
Open
Description
When clicking a link, tinro aitomatically prepend the link with #/
to ensure we stay on the same page. This works well except when middle-clicking. In that case, Tinro should listen to the auxclick event to perform the same task.
https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event
The current implementation:
Lines 62 to 81 in 32038e7
function aClickListener(go){ | |
const h = e => { | |
const a = e.target.closest('a[href]'); | |
const target = a && getAttr(a,'target',false,'_self'); | |
const ignore = a && getAttr(a,'tinro-ignore'); | |
const key = e.ctrlKey || e.metaKey || e.altKey || e.shiftKey; | |
if(target == '_self' && !ignore && !key && a){ | |
const href = a.getAttribute('href').replace(/^\/#/,''); | |
if(!/^\/\/|^#|^[a-zA-Z]+:/.test(href)) { | |
e.preventDefault(); | |
go(href.startsWith('/') ? href : a.href.replace(window.location.origin,'')); | |
} | |
} | |
} | |
addEventListener('click', h); | |
return () => removeEventListener('click', h); | |
} |
Metadata
Metadata
Assignees
Labels
No labels