aboutsummaryrefslogtreecommitdiff
path: root/http/public/scripts/feed-condense-content.js
diff options
context:
space:
mode:
Diffstat (limited to 'http/public/scripts/feed-condense-content.js')
-rw-r--r--http/public/scripts/feed-condense-content.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/http/public/scripts/feed-condense-content.js b/http/public/scripts/feed-condense-content.js
new file mode 100644
index 0000000..02361b5
--- /dev/null
+++ b/http/public/scripts/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);
+ }
+}