Fix clicks on bar being handled by container

This commit is contained in:
Kovid Goyal 2023-10-24 13:33:04 +05:30
parent fcc8795078
commit 79062e8a8c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -100,6 +100,7 @@ class ReadAudioEbook:
]:
bar_container.appendChild(x)
bar_container.addEventListener("click", self.on_bar_clicked, {"passive": False})
self.container.appendChild(E.audio(data_component='audio', style="display:none"))
ap = self.container.lastChild
@ -126,10 +127,11 @@ class ReadAudioEbook:
ap = self.audio_player
if ap.duration:
rect = self.progress_bar.getBoundingClientRect()
clickX = event.clientX - rect.left
x = event.clientX - rect.left
total_width = rect.width
skip_time = (clickX / total_width) * ap.duration
ap.currentTime = skip_time
if total_width:
skip_time = (x / total_width) * ap.duration
ap.currentTime = skip_time
)
@property
@ -293,6 +295,10 @@ class ReadAudioEbook:
elif self.state is PAUSED:
self.play()
def on_bar_clicked(self, ev):
# prevent the container click handler from handling this
ev.stopPropagation(), ev.preventDefault()
def on_container_clicked(self, ev):
if ev.button is not 0:
return