mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-30 23:49:10 -04:00
Dispatch a synthetic click on quick taps
touchstart's preventDefault suppresses the click events that foliate's link handling and the overlayer's highlight hit-testing depend on; dispatch one at the tapped element so internal links and the highlight edit popover work on touch as on desktop.
This commit is contained in:
+7
-4
@@ -733,10 +733,13 @@ export class Paginator extends HTMLElement {
|
|||||||
if (wasSelecting || e.changedTouches.length !== 1) return
|
if (wasSelecting || e.changedTouches.length !== 1) return
|
||||||
const touch = e.changedTouches[0]
|
const touch = e.changedTouches[0]
|
||||||
// touchstart's preventDefault suppresses click
|
// touchstart's preventDefault suppresses click
|
||||||
// events; follow links directly
|
// events; dispatch one so foliate's link handling and
|
||||||
const link = doc.elementFromPoint(touch.clientX, touch.clientY)
|
// the overlayer's highlight hit-testing (the edit
|
||||||
?.closest('a')
|
// popover) behave as on desktop
|
||||||
link?.click()
|
const el = doc.elementFromPoint(touch.clientX, touch.clientY)
|
||||||
|
el?.dispatchEvent(new (doc.defaultView ?? window).MouseEvent(
|
||||||
|
'click', { clientX: touch.clientX, clientY: touch.clientY,
|
||||||
|
bubbles: true, cancelable: true }))
|
||||||
})
|
})
|
||||||
doc.addEventListener('touchcancel', clearGesture)
|
doc.addEventListener('touchcancel', clearGesture)
|
||||||
doc.addEventListener('contextmenu', e => e.preventDefault())
|
doc.addEventListener('contextmenu', e => e.preventDefault())
|
||||||
|
|||||||
Reference in New Issue
Block a user