Event delegation for dynamic content (SSE, OOB, fragments).
hx-onis bound at parse time; content swapped by htmx (SSE, OOB,
fragments) does not get new handlers. This script uses event delegation
ondocumentso handlers work for dynamically inserted elements.
Handles:
.copy-btn— copies text from ancestor[data-copy-text]to clipboard.compare-switch— togglesaria-checkedand syncsinput[name=compare],select[name=model_b]in the same form
Injected into full-page HTML responses viaHTMLInjectmiddleware.
Controlled byAppConfig(delegation=True) (default: False).
server.delegation
| Name | Type | Default | Description |
|---|---|---|---|
type
|
|
— | |
qualified_name
|
|
— | |
element_type
|
|
— | |
description
|
|
— | |
source_file
|
|
— | |
line_number
|
|
— | |
is_autodoc
|
|
— | |
autodoc_element
|
|
— | |
_autodoc_template
|
|
— | |
_autodoc_url_path
|
|
— | |
_autodoc_page_type
|
|
— | |
title
|
|
— | |
doc_content_hash
|
|
— |
Symbols on this page
delegation_snippet
function
def delegation_snippet(nonce: str = '') -> str
Build the event-delegation inline<script>.
When nonce is non-empty the<script> carries a nonce="..."
attribute so it survives a nonce-based CSP that no longer ships
'unsafe-inline'.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
nonce
|
str
|
''
|
View source · /home/runner/work/chirp/chirp/site/../src/chirp/server/delegation.py:1