Files
Evection/static/js/stream.js
T
ksmithandClaude Sonnet 5.5 7afda7d0ba Fix inline article expand and back-to-stream scope in production
Clicking an article title opened the detail page instead of expanding
it inline, and "Back to stream" then reset to every feed. Cause: the
title (and the new-articles banner) used inline onclick= handlers,
which production's CSP (script-src 'self') blocks — dev sends no CSP,
so it worked there. The title link just fell through to its href.

Behavior moves to delegated listeners in static/js/stream.js (modified
clicks still open in a new tab). A test now fails if any template gains
an inline on*= handler. The stream also passes its filter/tag/feed
scope through the article link so the detail page's back link returns
to it. Verified in a dev server enforcing the same CSP: title click
expands and collapses in place, URL unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-01 09:02:51 -07:00

48 lines
1.5 KiB
JavaScript

// Delegated listeners, not inline onclick="" attributes: production's
// Content Security Policy (config/settings/prod.py, script-src 'self')
// blocks inline event handlers, which silently turned the title click into
// a plain link to the detail page and the new-articles banner into a no-op.
function toggleArticle(link) {
var row = link.closest("li.article-row");
var body = row.querySelector(".article-inline-body");
var wasOpen = row.classList.contains("is-expanded");
document.querySelectorAll("li.article-row.is-expanded").forEach(function (openRow) {
openRow.classList.remove("is-expanded");
var openBody = openRow.querySelector(".article-inline-body");
if (openBody) {
openBody.hidden = true;
}
});
if (!wasOpen) {
row.classList.add("is-expanded");
body.hidden = false;
if (!body.dataset.loaded) {
body.dataset.loaded = "1";
htmx.ajax("GET", link.dataset.inlineUrl, { target: body, swap: "innerHTML" }).then(
function () {
row.classList.add("is-read");
}
);
}
}
}
document.addEventListener("click", function (event) {
var link = event.target.closest("a.article-title[data-inline-url]");
if (link) {
// Leave modified clicks alone so "open in new tab" still works.
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) {
return;
}
event.preventDefault();
toggleArticle(link);
return;
}
if (event.target.closest(".new-articles-banner")) {
location.reload();
}
});