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
+8
View File
@@ -180,6 +180,14 @@ html, body {
} }
} }
/* Long-press selects these tiles, so iOS mustn't open its link preview and menu */
#gallery a:has(.tile-check),
#gallery a:has(.tile-check) img {
-webkit-touch-callout: none;
-webkit-user-select: none;
user-select: none;
}
/* Touch outside select mode: no invisible tap target. Long-press selects */ /* Touch outside select mode: no invisible tap target. Long-press selects */
@media (hover: none) { @media (hover: none) {
#gallery:not(.select-mode) .tile-check { #gallery:not(.select-mode) .tile-check {
+6
View File
@@ -132,10 +132,12 @@ export function createTile (index: number): HTMLAnchorElement {
function attachLongPress (tile: HTMLAnchorElement, id: string) { function attachLongPress (tile: HTMLAnchorElement, id: string) {
let timer: ReturnType<typeof setTimeout> | null = null let timer: ReturnType<typeof setTimeout> | null = null
let pressed = false let pressed = false
let touch = false
const cancel = () => { const cancel = () => {
if (timer) { clearTimeout(timer); timer = null } if (timer) { clearTimeout(timer); timer = null }
} }
tile.addEventListener('pointerdown', (e) => { tile.addEventListener('pointerdown', (e) => {
touch = e.pointerType === 'touch'
// Ignore right/middle clicks // Ignore right/middle clicks
if (e.button !== undefined && e.button !== 0) return if (e.button !== undefined && e.button !== 0) return
pressed = false pressed = false
@@ -153,6 +155,10 @@ function attachLongPress (tile: HTMLAnchorElement, id: string) {
// Cancel long-press if pointer moves significantly (scroll, drag) // Cancel long-press if pointer moves significantly (scroll, drag)
if (Math.abs(e.movementX) + Math.abs(e.movementY) > 6) cancel() 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 // Swallow the synthetic click that follows a successful long-press so it
// doesn't open the lightbox. // doesn't open the lightbox.
tile.addEventListener('click', (e) => { tile.addEventListener('click', (e) => {