comparison libervia/pages/_browser/slideshow.py @ 1341:a8bc1ee455ae

browser (slideshow): use standard click/dblclick instead of swiper equivalents: using swiper events cause troubles will managing event propagation (notably with media player)
author Goffi <goffi@goffi.org>
date Mon, 24 Aug 2020 22:49:24 +0200
parents d5f6793dc17c
children 1df0d1b28b83
comparison
equal deleted inserted replaced
1340:d5f6793dc17c 1341:a8bc1ee455ae
82 } 82 }
83 ) 83 )
84 window.addEventListener("keydown", self.on_key_down, True) 84 window.addEventListener("keydown", self.on_key_down, True)
85 self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close) 85 self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close)
86 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment) 86 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment)
87 # we don't use swiper.on for "click" and "dblclick" (or "doubleTap" in swiper
88 # terms) because it breaks event propagation management, which cause trouble with
89 # media player
90 self.slideshow_elt.bind("click", self.on_click)
91 self.slideshow_elt.bind("dblclick", self.on_dblclick)
87 self.swiper.on("slideChange", self.on_slide_change) 92 self.swiper.on("slideChange", self.on_slide_change)
88 self.swiper.on("click", self.on_click)
89 self.swiper.on("doubleTap", self.on_double_tap)
90 self.on_slide_change(self.swiper) 93 self.on_slide_change(self.swiper)
91 self.fullscreen(True) 94 self.fullscreen(True)
92 95
93 def add_slide(self, elt, item_data=None): 96 def add_slide(self, elt, item_data=None):
94 slide_elt = html.DIV(Class="swiper-slide") 97 slide_elt = html.DIV(Class="swiper-slide")
154 return 157 return
155 for elt in self.slideshow_elt.select('.click_to_hide'): 158 for elt in self.slideshow_elt.select('.click_to_hide'):
156 elt.style.display = '' if self.control_hidden else 'none' 159 elt.style.display = '' if self.control_hidden else 'none'
157 self.control_hidden = not self.control_hidden 160 self.control_hidden = not self.control_hidden
158 161
159 def on_click(self, swiper, evt): 162 def on_click(self, evt):
163 evt.stopPropagation()
164 evt.preventDefault()
160 # we use a timer so double tap can cancel the click 165 # we use a timer so double tap can cancel the click
161 # this avoid double tap side effect 166 # this avoid double tap side effect
162 if self.click_timer is None: 167 if self.click_timer is None:
163 self.click_timer = timer.set_timeout( 168 self.click_timer = timer.set_timeout(
164 lambda: self.toggle_hide_controls(evt), 300) 169 lambda: self.toggle_hide_controls(evt), 300)
165 170
166 def on_double_tap(self, swiper, evt): 171 def on_dblclick(self, evt):
167 evt.stopPropagation() 172 evt.stopPropagation()
168 evt.preventDefault() 173 evt.preventDefault()
169 if self.click_timer is not None: 174 if self.click_timer is not None:
170 timer.clear_timeout(self.click_timer) 175 timer.clear_timeout(self.click_timer)
171 self.click_timer = None 176 self.click_timer = None