damus.io

damus.io website
git clone git://jb55.com/damus.io
Log | Files | Refs | README | LICENSE

commit e6644043df31de713b619cb5131eb11a782b2e9c
parent 45b36a9945836801bb21f283763f045f8cea331b
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 20 Nov 2022 14:07:10 -0800

cw: use ontoggle instead of event handlers

Diffstat:
Mweb/js/damus.js | 18++----------------
1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/web/js/damus.js b/web/js/damus.js @@ -924,19 +924,6 @@ function redraw_events(damus, view) { const events_el = damus.view_el.querySelector(`#${view.name}-view > .events`) events_el.innerHTML = render_events(damus, view) - - setup_timeline_event_handlers(events_el) -} - -function setup_timeline_event_handlers(events_el) -{ - // TODO use ontoggle instead for cw? - // TODO check if CW state needs to be stored in memory - // Is there a way we can just use the HTML/CSS state instead does it matter - // if we have them closed by default. I think this is only a problem - // because we draw the entire timeline. - for (const el of events_el.querySelectorAll(".cw")) - el.addEventListener("toggle", toggle_content_warning.bind(null)) } function redraw_timeline_events(damus, name) { @@ -1421,9 +1408,8 @@ function get_content_warning(tags) return null } -function toggle_content_warning(e) +function toggle_content_warning(el) { - const el = e.target const id = el.id.split("_")[1] const ev = DAMUS.all_events[id] @@ -1456,7 +1442,7 @@ function format_content(ev, show_media) } const open = !!DAMUS.cw_open[ev.id]? "open" : "" return ` - <details class="cw" id="cw_${ev.id}" ${open}> + <details ontoggle="toggle_content_warning(this)" class="cw" id="cw_${ev.id}" ${open}> <summary class="event-message">${cwHTML}</summary> ${body} </details>