diff options
| author | Joe Carstairs <me@joeac.net> | 2026-09-15 09:51:15 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-09-15 09:51:15 +0100 |
| commit | 12040e85274153ebc159a00f9ee6df85b59e1bb8 (patch) | |
| tree | 73b0eb89fa6ad75a50fc3c5cdbe9365c3ff557cb /http/src/js | |
| parent | 721be368f5b1b4d8cbf0d3cd7221908bafa7e508 (diff) | |
add feed-condense-content.js
Diffstat (limited to 'http/src/js')
| -rw-r--r-- | http/src/js/feed-condense-content.js | 25 |
1 files changed, 25 insertions, 0 deletions
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); + } +} |
