Fix long-press issue for iPhone

This commit is contained in:
Alan Grainger
2026-10-05 11:22:22 +13:00
parent 588174f62e
commit 65958ae899
2 changed files with 14 additions and 0 deletions
+6
View File
@@ -132,10 +132,12 @@ export function createTile (index: number): HTMLAnchorElement {
function attachLongPress (tile: HTMLAnchorElement, id: string) {
let timer: ReturnType<typeof setTimeout> | null = null
let pressed = false
let touch = false
const cancel = () => {
if (timer) { clearTimeout(timer); timer = null }
}
tile.addEventListener('pointerdown', (e) => {
touch = e.pointerType === 'touch'
// Ignore right/middle clicks
if (e.button !== undefined && e.button !== 0) return
pressed = false
@@ -153,6 +155,10 @@ function attachLongPress (tile: HTMLAnchorElement, id: string) {
// Cancel long-press if pointer moves significantly (scroll, drag)
if (Math.abs(e.movementX) + Math.abs(e.movementY) > 6) cancel()
})
// A long touch selects, so Android mustn't open its link menu. Right-click keeps it.
tile.addEventListener('contextmenu', (e) => {
if (touch) e.preventDefault()
})
// Swallow the synthetic click that follows a successful long-press so it
// doesn't open the lightbox.
tile.addEventListener('click', (e) => {