Mercurial > libervia-web
annotate libervia/web/pages/_browser/tools.py @ 1625:698eaabfca0e
browser (chat): side/panel and keyword handling:
- `dialog.Modal` can now be used with a `position` argument. The default `center` keeps
the old behaviour of modal in the middle of the screen, while using one of the
direction makes the modal appear from top/bottom/right/left with an animation. The
closing cross has been removed in favor of clicking/touching any part outside of the
modal.
- A method to create mockup clones of elements is now used to make placeholders. It is
used for the input panel in the main area when it is moved to a sub-panel modal, this
way there is not element disappearing.
- Clicking on a keyword now shows a sub-messages panel with all messages with this
keyword, in a similar way as for threads. Writing a messages there will add the keyword
automatically.
- Sub-messages panel will auto-scroll when messages are added.
rel 458
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Jun 2025 11:08:05 +0200 |
parents | 3a60bf3762ef |
children |
rev | line source |
---|---|
1574
4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 """Common useful tools""" |
1625
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
2 from browser import window, html |
1574
4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 |
4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 def is_touch_device(): |
4ab4bc3ae462
browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 return hasattr(window, 'ontouchstart') |
1620
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
7 |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
8 |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
9 def remove_ids(element): |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
10 """Recursively remove "id" attribute of element and all its descendants.""" |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
11 element.removeAttribute('id') |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
12 |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
13 for child in element.children: |
3a60bf3762ef
browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
14 remove_ids(child) |
1625
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
15 |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
16 |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
17 def make_placeholder(original_elt, placeholder_class="visual-placeholder"): |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
18 """Create a visual placeholder that matches an element's appearance. |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
19 |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
20 The placeholder will be a clone of the original element but without any ID attributes |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
21 to prevent DOM conflicts. |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
22 |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
23 @param original_elt: Element to create placeholder for. |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
24 @param placeholder_class: CSS class to add to placeholder element. |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
25 @return: Placeholder element. |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
26 """ |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
27 placeholder = original_elt.cloneNode(True) |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
28 remove_ids(placeholder) |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
29 placeholder.classList.add(placeholder_class) |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
30 placeholder.attrs["aria-hidden"] = "true" |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
31 placeholder.attrs["data-placeholder-for"] = original_elt.id or "" |
698eaabfca0e
browser (chat): side/panel and keyword handling:
Goffi <goffi@goffi.org>
parents:
1620
diff
changeset
|
32 return placeholder |