Emi Matchu
0c615043f2
Using good ol'-fashioned cookies! The JS sets it, and then Rails reads it on pageload. That way, there's no flash of content for it to load in after JS loads.
24 lines
752 B
JavaScript
24 lines
752 B
JavaScript
function setFormStateCookie(value) {
|
|
const thirtyDays = 60 * 60 * 24 * 30;
|
|
document.cookie = `DTIItemPageUserListsFormState=open;max-age=${thirtyDays}`;
|
|
}
|
|
|
|
const headers = document.querySelectorAll(".item-header");
|
|
for (const header of headers) {
|
|
try {
|
|
const form = header.querySelector(".user-lists-form");
|
|
const opener = header.querySelector(".user-lists-form-opener");
|
|
opener.addEventListener("click", (event) => {
|
|
if (form.hasAttribute("hidden")) {
|
|
form.removeAttribute("hidden");
|
|
setFormStateCookie("open");
|
|
} else {
|
|
form.setAttribute("hidden", "");
|
|
setFormStateCookie("closed");
|
|
}
|
|
event.preventDefault();
|
|
});
|
|
} catch (error) {
|
|
console.error(`Error applying dialog behavior to item header:`, error);
|
|
}
|
|
}
|