From e75f359483f0ccb0a1581db38f8b0e63cf355caf Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Wed, 23 Sep 2026 19:19:07 +0100 Subject: Delete feed-condense-content.js --- http/public/scripts/feed-condense-content.js | 67 ---------------------------- 1 file changed, 67 deletions(-) delete mode 100644 http/public/scripts/feed-condense-content.js (limited to 'http/public/scripts') diff --git a/http/public/scripts/feed-condense-content.js b/http/public/scripts/feed-condense-content.js deleted file mode 100644 index 984dbce..0000000 --- a/http/public/scripts/feed-condense-content.js +++ /dev/null @@ -1,67 +0,0 @@ -const expandedClass = "e-content--expanded"; - -export function toggleContentExpanded(id) { - const content = document.querySelector(`.e-content[data-content-id="${id}"]`); - const buttonBefore = document.querySelector( - `button:has(+ .e-content[data-content-id="${id}"])`, - ); - const buttonAfter = document.querySelector( - `.e-content[data-content-id="${id}"] + button`, - ); - - if (!content) { - throw new Error(`No content found with ID: ${id}`); - } - const classes = content.getAttribute("class").split(" "); - 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 (wasExpanded) { - if (!buttonBefore) { - console.warn("Tried to remove 'Read less' button but could not find it"); - } else { - buttonBefore.remove(); - } - if (!buttonAfter) { - console.warn( - "Tried to toggle 'Read less' button to say 'Read more' but could not find it", - ); - } else { - buttonAfter.textContent = "Read more"; - } - } else { - if (!buttonAfter) { - console.warn( - "Tried to toggle 'Read more' button to say 'Read less' but could not find it", - ); - } else { - buttonAfter.textContent = "Read less"; - } - if (buttonBefore) { - buttonBefore.remove(); - } - const newButtonBefore = createExpandCondenseButton(id, "Read less"); - content.insertAdjacentElement("beforebegin", newButtonBefore); - } -} - -export function addExpandItemButtons() { - for (const content of document.querySelectorAll(".e-content")) { - const contentId = crypto.randomUUID(); - content.setAttribute("data-content-id", contentId); - const button = createExpandCondenseButton(contentId, "Read more"); - content.insertAdjacentElement("afterend", button); - } -} - -function createExpandCondenseButton(contentId, initialText) { - const button = document.createElement("button"); - button.textContent = initialText; - button.addEventListener("click", () => toggleContentExpanded(contentId)); - return button; -} -- cgit v1.2.3