Mercurial > libervia-web
view libervia/web/pages/_browser/tools.py @ 1629:961468588131 default tip
doc (chat): Add documentation for message origin:
fix 459
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 08 Jun 2025 17:29:39 +0200 |
parents | 698eaabfca0e |
children |
line wrap: on
line source
"""Common useful tools""" from browser import window, html def is_touch_device(): return hasattr(window, 'ontouchstart') def remove_ids(element): """Recursively remove "id" attribute of element and all its descendants.""" element.removeAttribute('id') for child in element.children: remove_ids(child) def make_placeholder(original_elt, placeholder_class="visual-placeholder"): """Create a visual placeholder that matches an element's appearance. The placeholder will be a clone of the original element but without any ID attributes to prevent DOM conflicts. @param original_elt: Element to create placeholder for. @param placeholder_class: CSS class to add to placeholder element. @return: Placeholder element. """ placeholder = original_elt.cloneNode(True) remove_ids(placeholder) placeholder.classList.add(placeholder_class) placeholder.attrs["aria-hidden"] = "true" placeholder.attrs["data-placeholder-for"] = original_elt.id or "" return placeholder