annotate libervia/pages/_browser/slideshow.py @ 1316:d0575e9abf7d

pages (files/list): use new `FISAffiliationsGet` to get `directory_affiliation`
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:47:24 +0200
parents 39a87d9099c4
children 0cbf86b1dcca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1310
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
1 from browser import document, window, html, timer, DOMNode
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from js_modules.swiper import Swiper
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from template import Template
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 class SlideShow:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 def __init__(self):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 self.swiper = None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 slideshow_tpl = Template('photo/slideshow.html')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 self.slideshow_elt = slideshow_tpl.get_elt()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 self.comments_count_elt = self.slideshow_elt.select_one('.comments__count')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 self.wrapper = self.slideshow_elt.select_one(".swiper-wrapper")
1309
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
14 self.hidden_elts = {}
1310
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
15 self.control_hidden = False
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
16 self.click_timer = None
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 @property
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 def current_slide(self):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 if self.swiper is None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 return None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 try:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 return DOMNode(self.swiper.slides[self.swiper.realIndex])
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 # getting missing item in JS arrays returns KeyError
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 except KeyError:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 return None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 @property
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def current_item(self):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 """item attached to the current slide, if any"""
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 current = self.current_slide
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 if current is None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 return
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 try:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 return current.js._item
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 except AttributeError:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 return None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 @property
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def index(self):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 if self.swiper is None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 return None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 return self.swiper.realIndex
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
44
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 @index.setter
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 def index(self, idx):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 if self.swiper is not None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.swiper.slideTo(idx, 0)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def attach(self):
1309
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
51 # we hide other elts to avoid scrolling issues
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
52 for elt in document.body.children:
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
53 self.hidden_elts[elt] = elt.style.display
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
54 elt.style.display = "none"
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 document.body <= self.slideshow_elt
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.swiper = Swiper.new(
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 ".swiper-container",
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 {
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "pagination": {
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 "el": ".swiper-pagination",
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 },
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 "navigation": {
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 "nextEl": ".swiper-button-next",
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 "prevEl": ".swiper-button-prev",
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 },
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 "scrollbar": {
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 "el": ".swiper-scrollbar",
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 },
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 "grabCursor": True,
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 "keyboard": {
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "enabled": True,
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 "onlyInViewport": False,
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 },
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 "mousewheel": True,
1312
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
75 "zoom": {
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
76 "maxRatio": 15,
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
77 "toggle": False,
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
78 },
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 }
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 )
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 window.addEventListener("keydown", self.on_key_down, True)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.slideshow_elt.select_one(".click_to_close").bind("click", self.on_close)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.swiper.on("slideChange", self.on_slide_change)
1310
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
85 self.swiper.on("click", self.on_click)
1312
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
86 self.swiper.on("doubleTap", self.on_double_tap)
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.on_slide_change()
1311
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
88 self.fullscreen(True)
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
1312
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
90 def add_slide(self, elt, item_data=None):
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
91 slide_elt = html.DIV(Class="swiper-slide")
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
92 zoom_cont_elt = html.DIV(Class="swiper-zoom-container")
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
93 slide_elt <= zoom_cont_elt
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
94 zoom_cont_elt <= elt
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
95 slide_elt._item = item_data
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.swiper.appendSlide([slide_elt])
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.swiper.update()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 def quit(self):
1309
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
100 # we unhide
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
101 for elt, display in self.hidden_elts.items():
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
102 elt.style.display = display
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
103 self.hidden_elts.clear()
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.slideshow_elt.remove()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 self.slideshow_elt = None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.swiper.destroy(True, True)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.swiper = None
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
1311
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
109 def fullscreen(self, active=None):
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
110 """Activate/desactivate fullscreen
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
111
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
112 @param acvite: can be:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
113 - True to activate
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
114 - False to desactivate
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
115 - Auto to switch fullscreen mode
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
116 """
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
117 try:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
118 fullscreen_elt = document.fullscreenElement
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
119 request_fullscreen = self.slideshow_elt.requestFullscreen
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
120 except AttributeError:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
121 print("fullscreen is not available on this browser")
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
122 else:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
123 if active is None:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
124 active = fullscreen_elt != None
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
125 if active:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
126 request_fullscreen()
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
127 else:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
128 try:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
129 document.exitFullscreen()
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
130 except AttributeError:
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
131 print("exitFullscreen not available on this browser")
9948598e7ec0 browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents: 1310
diff changeset
132
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 def on_key_down(self, evt):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 if evt.key == 'Escape':
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 self.quit()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 else:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 return
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 evt.preventDefault()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 def on_slide_change(self):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 item = self.current_item
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 if item is None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 return
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 comments_count = item.get('comments_count')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self.comments_count_elt.text = comments_count or ''
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
146
1310
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
147 def toggle_hide_controls(self, evt):
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
148 self.click_timer = None
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
149 if 'click_to_hide' in evt.target.classList:
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
150 # we don't want to hide controls when a control is clicked
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
151 return
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
152 for elt in self.slideshow_elt.select('.click_to_hide'):
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
153 elt.style.display = '' if self.control_hidden else 'none'
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
154 self.control_hidden = not self.control_hidden
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
155
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
156 def on_click(self, evt):
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
157 # we use a timer so double tap can cancel the click
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
158 # this avoid double tap side effect
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
159 if self.click_timer is None:
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
160 self.click_timer = timer.set_timeout(
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
161 lambda: self.toggle_hide_controls(evt), 300)
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
162
1312
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
163 def on_double_tap(self, evt):
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
164 evt.stopPropagation()
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
165 evt.preventDefault()
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
166 if self.click_timer is not None:
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
167 timer.clear_timeout(self.click_timer)
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
168 self.click_timer = None
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
169 if self.swiper.zoom.scale != 1:
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
170 self.swiper.zoom.toggle()
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
171 else:
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
172 # "in" is reserved in Python, so we call it using dict syntax
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
173 self.swiper.zoom["in"]()
39a87d9099c4 browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents: 1311
diff changeset
174
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 def on_close(self, evt):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 evt.stopPropagation()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 evt.preventDefault()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.quit()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 def on_comment_close(self, evt):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 side_panel = self.comments_panel_elt.select_one('.comments_side_panel')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 side_panel.classList.remove('open')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 side_panel.bind("transitionend", lambda evt: self.comments_panel_elt.remove())
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
184
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 def on_comments_panel_click(self, evt):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 # we stop stop propagation to avoid the closing of the panel
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 evt.stopPropagation()
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
188
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def on_comment(self, evt):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 item = self.current_item
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if item is None:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 return
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 comments_panel_tpl = Template('blog/comments_panel.html')
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 try:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 comments = item['comments']['items']
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 except KeyError:
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 comments = []
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 self.comments_panel_elt = comments_panel_tpl.get_elt({
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "comments": comments,
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 "comments_service": item['comments_service'],
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 "comments_node": item['comments_node'],
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
202
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 })
1309
9344ca3b21a6 browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents: 1307
diff changeset
204 self.slideshow_elt <= self.comments_panel_elt
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 side_panel = self.comments_panel_elt.select_one('.comments_side_panel')
1310
9e356f8eb62c browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents: 1309
diff changeset
206 timer.set_timeout(lambda: side_panel.classList.add("open"), 0)
1307
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 for close_elt in self.comments_panel_elt.select('.click_to_close'):
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 close_elt.bind("click", self.on_comment_close)
0a6698714557 browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 side_panel.bind("click", self.on_comments_panel_click)