From 92dffa85356b1f55020c3bf549881c8b67a5ce0c Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:17:25 +1300 Subject: [PATCH] persist post options fieldset state --- app/static/js/coolfieldset.js | 5 ++++- app/static/js/scripts.js | 17 +++++++++++++++++ app/templates/post/add_reply.html | 2 +- app/templates/post/post_edit.html | 4 ++-- app/templates/post/post_reply_edit.html | 2 +- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/static/js/coolfieldset.js b/app/static/js/coolfieldset.js index 836a2d95..c3d021fc 100644 --- a/app/static/js/coolfieldset.js +++ b/app/static/js/coolfieldset.js @@ -44,8 +44,10 @@ function doToggle(fieldset, setting) { if (fieldset.classList.contains('collapsed')) { showFieldsetContent(fieldset, setting); + setCookie(`fieldset_${fieldset.id}_state`, 'expanded', 365); } else if (fieldset.classList.contains('expanded')) { hideFieldsetContent(fieldset, setting); + setCookie(`fieldset_${fieldset.id}_state`, 'collapsed', 365); } } @@ -73,5 +75,6 @@ // coolfieldset('.coolfieldset', { collapsed: true, animation: true, speed: 'slow' }); document.addEventListener('DOMContentLoaded', function () { - coolfieldset('.coolfieldset', { collapsed: true, animation: true, speed: 'slow' }); + coolfieldset('.coolfieldset.collapsed', { collapsed: true, animation: true, speed: 'slow' }); + coolfieldset('.coolfieldset:not(.collapsed)', { collapsed: false, animation: true, speed: 'slow' }); }); diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index 1b552911..4aeb7ebd 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -806,6 +806,23 @@ function getCookie(name) { return null; } +function setCookie(name, value, days) { + var expires; + + if (days) { + var date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + expires = "; expires=" + date.toGMTString(); + } else { + expires = ""; + } + document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; +} + +function eraseCookie(name) { + setCookie(name, "", -1); +} + /* register a service worker */ if ('serviceWorker' in navigator) { window.addEventListener('load', function() { diff --git a/app/templates/post/add_reply.html b/app/templates/post/add_reply.html index 4e6f5bef..d1f412c6 100644 --- a/app/templates/post/add_reply.html +++ b/app/templates/post/add_reply.html @@ -6,7 +6,7 @@ {% from 'bootstrap/form.html' import render_form %} {% block app_content %} - +
Original post diff --git a/app/templates/post/post_edit.html b/app/templates/post/post_edit.html index e426fb85..5fb13cba 100644 --- a/app/templates/post/post_edit.html +++ b/app/templates/post/post_edit.html @@ -6,7 +6,7 @@ {% from 'bootstrap/form.html' import render_form, render_field %} {% block app_content %} - +
{% block title %}

{{ _('Edit post') }}

{% endblock %} @@ -116,7 +116,7 @@ {{ render_field(form.tags) }} {{ _('Separate each tag with a comma.') }} -