annotate libervia/web/pages/_browser/tools.py @ 1620:3a60bf3762ef

browser: threads and replies implementation: rel 457
author Goffi <goffi@goffi.org>
date Tue, 06 May 2025 00:40:07 +0200
parents 4ab4bc3ae462
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"""
4ab4bc3ae462 browser: new `tools` module with a first method to detect touch devices
Goffi <goffi@goffi.org>
parents:
diff changeset
2 from browser import window
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
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
10 def remove_ids(element):
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
11 """Recursively remove "id" attribute of element and all its descendants."""
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
12 element.removeAttribute('id')
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
13
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
14 for child in element.children:
3a60bf3762ef browser: threads and replies implementation:
Goffi <goffi@goffi.org>
parents: 1574
diff changeset
15 remove_ids(child)