changeset 1358:3c5054a22e7a

browser (slideshow): better handling of controls hiding: - use `slideshow_control` class instead of `click_to_hide` - check parents for the presence of this class (when a click on comments icon happen, it's the parent which has the `slideshow_control` class - stop propagation of events when closing comments tab, to avoid hiding controls accidentally
author Goffi <goffi@goffi.org>
date Thu, 17 Sep 2020 22:50:27 +0200
parents dbd573b0bc9c
children 2da573bf3f8b
files libervia/pages/_browser/slideshow.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/pages/_browser/slideshow.py	Thu Sep 17 22:46:55 2020 +0200
+++ b/libervia/pages/_browser/slideshow.py	Thu Sep 17 22:50:27 2020 +0200
@@ -97,6 +97,7 @@
         window.addEventListener("keydown", self.on_key_down, True)
         self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close)
         self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment)
+
         # we don't use swiper.on for "click" and "dblclick" (or "doubleTap" in swiper
         # terms) because it breaks event propagation management, which cause trouble with
         # media player
@@ -182,10 +183,15 @@
 
     def toggle_hide_controls(self, evt):
         self.click_timer = None
-        if 'click_to_hide' in evt.target.classList:
-            # we don't want to hide controls when a control is clicked
-            return
-        for elt in self.slideshow_elt.select('.click_to_hide'):
+        # we don't want to hide controls when a control is clicked
+        # so we check all ancestors if we are not in a control
+        current = evt.target
+        while current and current != self.slideshow_elt:
+            print(f"current: {current}")
+            if 'slideshow_control' in current.classList:
+                return
+            current = current.parent
+        for elt in self.slideshow_elt.select('.slideshow_control'):
             elt.style.display = '' if self.control_hidden else 'none'
         self.control_hidden = not self.control_hidden
 
@@ -216,6 +222,7 @@
         self.quit()
 
     def on_comment_close(self, evt):
+        evt.stopPropagation()
         side_panel = self.comments_panel_elt.select_one('.comments_side_panel')
         side_panel.classList.remove('open')
         side_panel.bind("transitionend", lambda evt: self.comments_panel_elt.remove())