Mercurial > libervia-web
comparison libervia/pages/_browser/slideshow.py @ 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 | ff5005783443 |
comparison
equal
deleted
inserted
replaced
1357:dbd573b0bc9c | 1358:3c5054a22e7a |
---|---|
95 } | 95 } |
96 ) | 96 ) |
97 window.addEventListener("keydown", self.on_key_down, True) | 97 window.addEventListener("keydown", self.on_key_down, True) |
98 self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close) | 98 self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close) |
99 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment) | 99 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment) |
100 | |
100 # we don't use swiper.on for "click" and "dblclick" (or "doubleTap" in swiper | 101 # we don't use swiper.on for "click" and "dblclick" (or "doubleTap" in swiper |
101 # terms) because it breaks event propagation management, which cause trouble with | 102 # terms) because it breaks event propagation management, which cause trouble with |
102 # media player | 103 # media player |
103 self.slideshow_elt.bind("click", self.on_click) | 104 self.slideshow_elt.bind("click", self.on_click) |
104 self.slideshow_elt.bind("dblclick", self.on_dblclick) | 105 self.slideshow_elt.bind("dblclick", self.on_dblclick) |
180 self._class_to_remove.add(cls) | 181 self._class_to_remove.add(cls) |
181 self._exit_callback = options.get("exit_callback", None) | 182 self._exit_callback = options.get("exit_callback", None) |
182 | 183 |
183 def toggle_hide_controls(self, evt): | 184 def toggle_hide_controls(self, evt): |
184 self.click_timer = None | 185 self.click_timer = None |
185 if 'click_to_hide' in evt.target.classList: | 186 # we don't want to hide controls when a control is clicked |
186 # we don't want to hide controls when a control is clicked | 187 # so we check all ancestors if we are not in a control |
187 return | 188 current = evt.target |
188 for elt in self.slideshow_elt.select('.click_to_hide'): | 189 while current and current != self.slideshow_elt: |
190 print(f"current: {current}") | |
191 if 'slideshow_control' in current.classList: | |
192 return | |
193 current = current.parent | |
194 for elt in self.slideshow_elt.select('.slideshow_control'): | |
189 elt.style.display = '' if self.control_hidden else 'none' | 195 elt.style.display = '' if self.control_hidden else 'none' |
190 self.control_hidden = not self.control_hidden | 196 self.control_hidden = not self.control_hidden |
191 | 197 |
192 def on_click(self, evt): | 198 def on_click(self, evt): |
193 evt.stopPropagation() | 199 evt.stopPropagation() |
214 evt.stopPropagation() | 220 evt.stopPropagation() |
215 evt.preventDefault() | 221 evt.preventDefault() |
216 self.quit() | 222 self.quit() |
217 | 223 |
218 def on_comment_close(self, evt): | 224 def on_comment_close(self, evt): |
225 evt.stopPropagation() | |
219 side_panel = self.comments_panel_elt.select_one('.comments_side_panel') | 226 side_panel = self.comments_panel_elt.select_one('.comments_side_panel') |
220 side_panel.classList.remove('open') | 227 side_panel.classList.remove('open') |
221 side_panel.bind("transitionend", lambda evt: self.comments_panel_elt.remove()) | 228 side_panel.bind("transitionend", lambda evt: self.comments_panel_elt.remove()) |
222 | 229 |
223 def on_comments_panel_click(self, evt): | 230 def on_comments_panel_click(self, evt): |