Mercurial > libervia-web
annotate libervia/pages/_browser/slideshow.py @ 1422:027f5059e1e2
pages (lists/view_item): browser part was not in the repository
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 19:05:05 +0200 |
parents | ff5005783443 |
children |
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 |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
17 self._class_to_remove = set() |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
18 self._exit_callback = None |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 @property |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 def current_slide(self): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 if self.swiper is None: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 return None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 try: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 return DOMNode(self.swiper.slides[self.swiper.realIndex]) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 # getting missing item in JS arrays returns KeyError |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 except KeyError: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 return None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 @property |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 def current_item(self): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 """item attached to the current slide, if any""" |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 current = self.current_slide |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 if current is None: |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
35 return None |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 try: |
1357
dbd573b0bc9c
browser: updated code to work with new Brython 3.8.10:
Goffi <goffi@goffi.org>
parents:
1342
diff
changeset
|
37 return current._item |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 except AttributeError: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 return None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 @property |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
42 def current_options(self): |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
43 """options attached to the current slide, if any""" |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
44 current = self.current_slide |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
45 if current is None: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
46 return None |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
47 try: |
1357
dbd573b0bc9c
browser: updated code to work with new Brython 3.8.10:
Goffi <goffi@goffi.org>
parents:
1342
diff
changeset
|
48 return current._options |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
49 except AttributeError: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
50 return None |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
51 |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
52 @property |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 def index(self): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 if self.swiper is None: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 return None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 return self.swiper.realIndex |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 @index.setter |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 def index(self, idx): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 if self.swiper is not None: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.swiper.slideTo(idx, 0) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 def attach(self): |
1309
9344ca3b21a6
browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
64 # 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
|
65 for elt in document.body.children: |
1408
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
66 try: |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
67 self.hidden_elts[elt] = elt.style.display |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
68 except AttributeError: |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
69 pass |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
70 # FIXME: this is a workaround needed because Brython's children method |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
71 # is returning all nodes, |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
72 # cf. https://github.com/brython-dev/brython/issues/1657 |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
73 # to be removed when Brython is fixed. |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
74 else: |
ff5005783443
browser (slideshow): work around Brython's `children` wrong behavour:
Goffi <goffi@goffi.org>
parents:
1358
diff
changeset
|
75 elt.style.display = "none" |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 document.body <= self.slideshow_elt |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 self.swiper = Swiper.new( |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 ".swiper-container", |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 { |
1340
d5f6793dc17c
browser (slideshow): use non zero threshold to avoid accidental swipe
Goffi <goffi@goffi.org>
parents:
1334
diff
changeset
|
80 # default 0 value results in lot of accidental swipes, notably when media |
d5f6793dc17c
browser (slideshow): use non zero threshold to avoid accidental swipe
Goffi <goffi@goffi.org>
parents:
1334
diff
changeset
|
81 # player is used |
d5f6793dc17c
browser (slideshow): use non zero threshold to avoid accidental swipe
Goffi <goffi@goffi.org>
parents:
1334
diff
changeset
|
82 "threshold": 10, |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 "pagination": { |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 "el": ".swiper-pagination", |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 }, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 "navigation": { |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 "nextEl": ".swiper-button-next", |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 "prevEl": ".swiper-button-prev", |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 }, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 "scrollbar": { |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 "el": ".swiper-scrollbar", |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 }, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 "grabCursor": True, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 "keyboard": { |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 "enabled": True, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 "onlyInViewport": False, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 }, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 "mousewheel": True, |
1312
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
99 "zoom": { |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
100 "maxRatio": 15, |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
101 "toggle": False, |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
102 }, |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 } |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 ) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 window.addEventListener("keydown", self.on_key_down, True) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 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
|
107 self.slideshow_elt.select_one(".click_to_comment").bind("click", self.on_comment) |
1358
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
108 |
1341
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
109 # we don't use swiper.on for "click" and "dblclick" (or "doubleTap" in swiper |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
110 # terms) because it breaks event propagation management, which cause trouble with |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
111 # media player |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
112 self.slideshow_elt.bind("click", self.on_click) |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
113 self.slideshow_elt.bind("dblclick", self.on_dblclick) |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 self.swiper.on("slideChange", self.on_slide_change) |
1327
e35de70f5295
browser: updated swiper and use a limit on version
Goffi <goffi@goffi.org>
parents:
1320
diff
changeset
|
115 self.on_slide_change(self.swiper) |
1311
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
116 self.fullscreen(True) |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
118 def add_slide(self, elt, item_data=None, options=None): |
1312
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
119 slide_elt = html.DIV(Class="swiper-slide") |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
120 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
|
121 slide_elt <= zoom_cont_elt |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
122 zoom_cont_elt <= elt |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
123 slide_elt._item = item_data |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
124 if options is not None: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
125 slide_elt._options = options |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 self.swiper.appendSlide([slide_elt]) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 self.swiper.update() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 def quit(self): |
1309
9344ca3b21a6
browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
130 # we unhide |
9344ca3b21a6
browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
131 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
|
132 elt.style.display = display |
9344ca3b21a6
browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
133 self.hidden_elts.clear() |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 self.slideshow_elt.remove() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 self.slideshow_elt = None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 self.swiper.destroy(True, True) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 self.swiper = None |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 |
1311
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
139 def fullscreen(self, active=None): |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
140 """Activate/desactivate fullscreen |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
141 |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
142 @param acvite: can be: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
143 - True to activate |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
144 - False to desactivate |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
145 - Auto to switch fullscreen mode |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
146 """ |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
147 try: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
148 fullscreen_elt = document.fullscreenElement |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
149 request_fullscreen = self.slideshow_elt.requestFullscreen |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
150 except AttributeError: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
151 print("fullscreen is not available on this browser") |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
152 else: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
153 if active is None: |
1334
5ff6e187084f
browser (slideshow): fixed `active` value detection for fullscreen
Goffi <goffi@goffi.org>
parents:
1327
diff
changeset
|
154 active = fullscreen_elt == None |
1311
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
155 if active: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
156 request_fullscreen() |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
157 else: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
158 try: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
159 document.exitFullscreen() |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
160 except AttributeError: |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
161 print("exitFullscreen not available on this browser") |
9948598e7ec0
browser (slideshow): show slideshow in fullscreen
Goffi <goffi@goffi.org>
parents:
1310
diff
changeset
|
162 |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 def on_key_down(self, evt): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 if evt.key == 'Escape': |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 self.quit() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 else: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 return |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 evt.preventDefault() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 |
1327
e35de70f5295
browser: updated swiper and use a limit on version
Goffi <goffi@goffi.org>
parents:
1320
diff
changeset
|
170 def on_slide_change(self, swiper): |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
171 if self._exit_callback is not None: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
172 self._exit_callback() |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
173 self._exit_callback = None |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 item = self.current_item |
1342
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
175 if item is not None: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
176 comments_count = item.get('comments_count') |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
177 self.comments_count_elt.text = comments_count or '' |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
178 |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
179 for cls in self._class_to_remove: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
180 self.slideshow_elt.classList.remove(cls) |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
181 |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
182 self._class_to_remove.clear() |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
183 |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
184 options = self.current_options |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
185 if options is not None: |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
186 for flag in options.get('flags', []): |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
187 cls = f"flag_{flag.lower()}" |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
188 self.slideshow_elt.classList.add(cls) |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
189 self._class_to_remove.add(cls) |
1df0d1b28b83
browser (slideshow): options can now be attached to a slide:
Goffi <goffi@goffi.org>
parents:
1341
diff
changeset
|
190 self._exit_callback = options.get("exit_callback", None) |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
1310
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
192 def toggle_hide_controls(self, evt): |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
193 self.click_timer = None |
1358
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
194 # we don't want to hide controls when a control is clicked |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
195 # so we check all ancestors if we are not in a control |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
196 current = evt.target |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
197 while current and current != self.slideshow_elt: |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
198 print(f"current: {current}") |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
199 if 'slideshow_control' in current.classList: |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
200 return |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
201 current = current.parent |
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
202 for elt in self.slideshow_elt.select('.slideshow_control'): |
1310
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
203 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
|
204 self.control_hidden = not self.control_hidden |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
205 |
1341
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
206 def on_click(self, evt): |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
207 evt.stopPropagation() |
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
208 evt.preventDefault() |
1310
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
209 # 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
|
210 # this avoid double tap side effect |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
211 if self.click_timer is None: |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
212 self.click_timer = timer.set_timeout( |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
213 lambda: self.toggle_hide_controls(evt), 300) |
9e356f8eb62c
browser (slideshow): (un)hide controls on single click:
Goffi <goffi@goffi.org>
parents:
1309
diff
changeset
|
214 |
1341
a8bc1ee455ae
browser (slideshow): use standard click/dblclick instead of swiper equivalents:
Goffi <goffi@goffi.org>
parents:
1340
diff
changeset
|
215 def on_dblclick(self, evt): |
1312
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
216 evt.stopPropagation() |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
217 evt.preventDefault() |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
218 if self.click_timer is not None: |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
219 timer.clear_timeout(self.click_timer) |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
220 self.click_timer = None |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
221 if self.swiper.zoom.scale != 1: |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
222 self.swiper.zoom.toggle() |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
223 else: |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
224 # "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
|
225 self.swiper.zoom["in"]() |
39a87d9099c4
browser (slideshow): slides can now be zoomed:
Goffi <goffi@goffi.org>
parents:
1311
diff
changeset
|
226 |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 def on_close(self, evt): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 evt.stopPropagation() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 evt.preventDefault() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 self.quit() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 def on_comment_close(self, evt): |
1358
3c5054a22e7a
browser (slideshow): better handling of controls hiding:
Goffi <goffi@goffi.org>
parents:
1357
diff
changeset
|
233 evt.stopPropagation() |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 side_panel = self.comments_panel_elt.select_one('.comments_side_panel') |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 side_panel.classList.remove('open') |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 side_panel.bind("transitionend", lambda evt: self.comments_panel_elt.remove()) |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 def on_comments_panel_click(self, evt): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 # we stop stop propagation to avoid the closing of the panel |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 evt.stopPropagation() |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 def on_comment(self, evt): |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 item = self.current_item |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 if item is None: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 return |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 comments_panel_tpl = Template('blog/comments_panel.html') |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 try: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 comments = item['comments']['items'] |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 except KeyError: |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 comments = [] |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 self.comments_panel_elt = comments_panel_tpl.get_elt({ |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 "comments": comments, |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 "comments_service": item['comments_service'], |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 "comments_node": item['comments_node'], |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 }) |
1309
9344ca3b21a6
browser (slideshow): fixed scrolling issue with comment panel:
Goffi <goffi@goffi.org>
parents:
1307
diff
changeset
|
257 self.slideshow_elt <= self.comments_panel_elt |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 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
|
259 timer.set_timeout(lambda: side_panel.classList.add("open"), 0) |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 for close_elt in self.comments_panel_elt.select('.click_to_close'): |
1320
0cbf86b1dcca
browser (photos/album): invitation manager first draft.
Goffi <goffi@goffi.org>
parents:
1312
diff
changeset
|
261 close_elt.bind("click", self.on_comment_close) |
1307
0a6698714557
browser: `slideshow` module implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 side_panel.bind("click", self.on_comments_panel_click) |