From 79062e8a8c39eb1a35ff7ad82267488ba775dc67 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 24 Oct 2023 13:33:04 +0530 Subject: [PATCH] Fix clicks on bar being handled by container --- src/pyj/read_book/read_audio_ebook.pyj | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pyj/read_book/read_audio_ebook.pyj b/src/pyj/read_book/read_audio_ebook.pyj index d726fa68b2..ed873ec071 100644 --- a/src/pyj/read_book/read_audio_ebook.pyj +++ b/src/pyj/read_book/read_audio_ebook.pyj @@ -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