diff --git a/app/public/style.css b/app/public/style.css index 0342c99..2f7a703 100644 --- a/app/public/style.css +++ b/app/public/style.css @@ -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 */ @media (hover: none) { #gallery:not(.select-mode) .tile-check { diff --git a/app/src/client/tiles.ts b/app/src/client/tiles.ts index cf7fe38..7cffcda 100644 --- a/app/src/client/tiles.ts +++ b/app/src/client/tiles.ts @@ -132,10 +132,12 @@ export function createTile (index: number): HTMLAnchorElement { function attachLongPress (tile: HTMLAnchorElement, id: string) { let timer: ReturnType | 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) => {