Mercurial > libervia-web
view libervia/web/pages/_browser/components.py @ 1621:d7c8a986f4fb default tip
doc (chat): chat documentation first draft:
Include documentation for thread/reply.
fix 457
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 06 May 2025 00:40:53 +0200 |
parents | a2cd4222c702 |
children |
line wrap: on
line source
from browser import document def init_collapsible_cards(parent_elt=None) -> None: """Initialize cards which can be collapsed.""" parent = parent_elt or document cards = parent.select('.collapsible-card') for card in cards: header = card.select_one('.collapsible-header') content = card.select_one('.collapsible-content') content.style.maxHeight = 'none' natural_height = content.scrollHeight content.dataset.natural_height = natural_height header.bind('click', lambda ev: _toggle_card(ev)) def _toggle_card(event): """Collapse/expand the card.""" header = event.currentTarget card = header.closest('.collapsible-card') content = card.select_one('.collapsible-content') if content.style.maxHeight == '0px': # Expand content.style.maxHeight = f"{content.dataset.natural_height}px" header.classList.remove('collapsed') else: # Collapse content.style.maxHeight = '0px' header.classList.add('collapsed')