const expandedClass = "e-content--expanded"; export 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(" ")); } } export 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.addEventListener("click", () => toggleContentExpanded(contentId)); content.insertAdjacentElement("afterend", button); } }