From 12040e85274153ebc159a00f9ee6df85b59e1bb8 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 15 Sep 2026 09:51:15 +0100 Subject: add feed-condense-content.js --- http/src/js/feed-condense-content.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 http/src/js/feed-condense-content.js (limited to 'http') diff --git a/http/src/js/feed-condense-content.js b/http/src/js/feed-condense-content.js new file mode 100644 index 0000000..02361b5 --- /dev/null +++ b/http/src/js/feed-condense-content.js @@ -0,0 +1,25 @@ +const expandedClass = "e-content--expanded"; + +function toggleContentExpanded(id) { + const content = document.querySelector(`[data-content-id=${id}`); + if (!content) { + throw new Error(`No content found with ID: ${id}`); + } + const classes = content.getAttribute("class").split(" "); + if (classes.includes(expandedClass)) { + const newClasses = classes.filter((c) => c != expandedClass); + content.setAttribute("class", newClasses.join(" ")); + } else { + content.setAttribute("class", [...classes, expandedClass].join(" ")); + } +} + +function addExpandItemButtons() { + for (const content of document.querySelectorAll(".e-content")) { + const contentId = crypto.randomUUID(); + content.setAttribute("data-content-id", contentId); + const button = new HTMLButtonElement(); + button.onclick = `toggleContentExpanded(${contentId})`; + content.insertAdjacentElement("afterend", button); + } +} -- cgit v1.2.3