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
|
||||
const touch = e.changedTouches[0]
|
||||
// touchstart's preventDefault suppresses click
|
||||
// events; follow links directly
|
||||
const link = doc.elementFromPoint(touch.clientX, touch.clientY)
|
||||
?.closest('a')
|
||||
link?.click()
|
||||
// events; dispatch one so foliate's link handling and
|
||||
// the overlayer's highlight hit-testing (the edit
|
||||
// popover) behave as on desktop
|
||||
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('contextmenu', e => e.preventDefault())
|
||||
|
||||
Reference in New Issue
Block a user