comparison libervia/pages/_browser/slideshow.py @ 1309:9344ca3b21a6

browser (slideshow): fixed scrolling issue with comment panel: all elements present in body before slideshow is added are hidden, and comments panel is now added to slideshow itself.
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:47:21 +0200
parents 0a6698714557
children 9e356f8eb62c
comparison
equal deleted inserted replaced
1308:7a4a92cf5b2b 1309:9344ca3b21a6
9 self.swiper = None 9 self.swiper = None
10 slideshow_tpl = Template('photo/slideshow.html') 10 slideshow_tpl = Template('photo/slideshow.html')
11 self.slideshow_elt = slideshow_tpl.get_elt() 11 self.slideshow_elt = slideshow_tpl.get_elt()
12 self.comments_count_elt = self.slideshow_elt.select_one('.comments__count') 12 self.comments_count_elt = self.slideshow_elt.select_one('.comments__count')
13 self.wrapper = self.slideshow_elt.select_one(".swiper-wrapper") 13 self.wrapper = self.slideshow_elt.select_one(".swiper-wrapper")
14 self.hidden_elts = {}
14 15
15 @property 16 @property
16 def current_slide(self): 17 def current_slide(self):
17 if self.swiper is None: 18 if self.swiper is None:
18 return None 19 return None
43 def index(self, idx): 44 def index(self, idx):
44 if self.swiper is not None: 45 if self.swiper is not None:
45 self.swiper.slideTo(idx, 0) 46 self.swiper.slideTo(idx, 0)
46 47
47 def attach(self): 48 def attach(self):
49 # we hide other elts to avoid scrolling issues
50 for elt in document.body.children:
51 self.hidden_elts[elt] = elt.style.display
52 elt.style.display = "none"
48 document.body <= self.slideshow_elt 53 document.body <= self.slideshow_elt
49 self.swiper = Swiper.new( 54 self.swiper = Swiper.new(
50 ".swiper-container", 55 ".swiper-container",
51 { 56 {
52 "pagination": { 57 "pagination": {
77 def add_slide(self, slide_elt): 82 def add_slide(self, slide_elt):
78 self.swiper.appendSlide([slide_elt]) 83 self.swiper.appendSlide([slide_elt])
79 self.swiper.update() 84 self.swiper.update()
80 85
81 def quit(self): 86 def quit(self):
87 # we unhide
88 for elt, display in self.hidden_elts.items():
89 elt.style.display = display
90 self.hidden_elts.clear()
82 self.slideshow_elt.remove() 91 self.slideshow_elt.remove()
83 self.slideshow_elt = None 92 self.slideshow_elt = None
84 self.swiper.destroy(True, True) 93 self.swiper.destroy(True, True)
85 self.swiper = None 94 self.swiper = None
86 95
125 "comments": comments, 134 "comments": comments,
126 "comments_service": item['comments_service'], 135 "comments_service": item['comments_service'],
127 "comments_node": item['comments_node'], 136 "comments_node": item['comments_node'],
128 137
129 }) 138 })
130 document.body <= self.comments_panel_elt 139 self.slideshow_elt <= self.comments_panel_elt
131 side_panel = self.comments_panel_elt.select_one('.comments_side_panel') 140 side_panel = self.comments_panel_elt.select_one('.comments_side_panel')
132 window.setTimeout(lambda: side_panel.classList.add("open")) 141 window.setTimeout(lambda: side_panel.classList.add("open"))
133 for close_elt in self.comments_panel_elt.select('.click_to_close'): 142 for close_elt in self.comments_panel_elt.select('.click_to_close'):
134 close_elt.bind("click", self.on_comment_close) 143 close_elt.bind("click", self.on_comment_close)
135 side_panel.bind("click", self.on_comments_panel_click) 144 side_panel.bind("click", self.on_comments_panel_click)