aboutsummaryrefslogtreecommitdiff
path: root/http/public/scripts
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-09-15 17:53:44 +0100
committerJoe Carstairs <me@joeac.net>2026-09-15 17:53:44 +0100
commit01b681d46ce0a5593f238eac291529bd7d67535d (patch)
tree53efbcb40c50ee1a016ef6222e0e58d9684aa6e8 /http/public/scripts
parentf4cf448a9c527f6281e4e91517d4b3de7a5b0bb1 (diff)
feed-condense-content.js: add button text content
Diffstat (limited to 'http/public/scripts')
-rw-r--r--http/public/scripts/feed-condense-content.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/http/public/scripts/feed-condense-content.js b/http/public/scripts/feed-condense-content.js
index d15deb0..7fd01b3 100644
--- a/http/public/scripts/feed-condense-content.js
+++ b/http/public/scripts/feed-condense-content.js
@@ -1,17 +1,32 @@
const expandedClass = "e-content--expanded";
export function toggleContentExpanded(id) {
- const content = document.querySelector(`[data-content-id=${id}`);
+ const content = document.querySelector(`[data-content-id=${id}]`);
+ const button = document.querySelector(`[data-content-id=${id}] + button`);
+
if (!content) {
throw new Error(`No content found with ID: ${id}`);
}
const classes = content.getAttribute("class").split(" ");
- if (classes.includes(expandedClass)) {
+ const wasExpanded = classes.includes(expandedClass);
+ if (wasExpanded) {
const newClasses = classes.filter((c) => c != expandedClass);
content.setAttribute("class", newClasses.join(" "));
} else {
content.setAttribute("class", [...classes, expandedClass].join(" "));
}
+
+ if (!button) {
+ console.warn(
+ `Toggled content expansion, but no button next to content with ID: ${id}`,
+ );
+ } else {
+ if (wasExpanded) {
+ button.textContent = "Read more";
+ } else {
+ button.textContent = "Read less";
+ }
+ }
}
export function addExpandItemButtons() {
@@ -19,6 +34,7 @@ export function addExpandItemButtons() {
const contentId = crypto.randomUUID();
content.setAttribute("data-content-id", contentId);
const button = document.createElement("button");
+ button.textContent = "Read more";
button.addEventListener("click", () => toggleContentExpanded(contentId));
content.insertAdjacentElement("afterend", button);
}