refactor(post-form): derive disclosure default from rendered markup

initDisclosure hardcoded blueprint defaults into a field-name regex
(/\[published\]$/) to decide which toggle state counts as a deviation worth
auto-expanding "More options". Read each toggle's default from the HTML
`checked` attribute instead — Grav's toggle template stamps it on the default
option, and prefill/edit only ever set the live `.checked` property — so a
future default-ON advanced toggle Just Works. Rebuilt bundle.

Code review F4 (maintainability).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mpdu3Dt1iVoozHwAMyjrbn
This commit is contained in:
2026-07-07 08:31:59 +02:00
co-authored by Claude Opus 4.8
parent 8db3ffeafc
commit 7f6bf9e3f3
2 changed files with 15 additions and 11 deletions
+14 -10
View File
@@ -327,19 +327,23 @@ function initDisclosure() {
wrappers.forEach(function (w) { details.appendChild(w); });
// A toggle only counts as an "advanced value" worth auto-expanding for when
// it DEVIATES from its blueprint default. `published` defaults ON, so a plain
// create form would otherwise trip this on every load and render More options
// expanded. `published` is the sole default-ON toggle here, so its notable
// state is OFF (a deliberate draft); the others (force_connect/featured)
// default OFF, so theirs is ON. (Edit mode force-opens the panel elsewhere —
// see initEditMode — so this only governs the create / draft-restore case.)
// it DEVIATES from its blueprint default — otherwise `published` (default ON)
// would trip this on every plain create and render More options expanded.
// Read each toggle's default straight from the markup rather than hardcoding
// field names: Grav's toggle template stamps the HTML `checked` attribute on
// the default option (value ?? default ?? highlight), and prefill/edit only
// ever set the live `.checked` property — never the attribute — so `[checked]`
// still points at the blueprint default while `:checked` is the current state.
// This stays correct if a future advanced toggle defaults ON. (Edit mode
// force-opens the panel elsewhere — see initEditMode — so this only governs
// the create / draft-restore case.)
var hasValue = wrappers.some(function (w) {
var text = w.querySelector('input[type="text"]');
if (text && text.value.trim()) return true;
var toggle = w.querySelector('input[type="radio"]:checked');
if (!toggle || !toggle.value) return false;
var isPublished = /\[published\]$/.test(toggle.name || '');
return isPublished ? toggle.value === '0' : toggle.value !== '0';
var current = w.querySelector('input[type="radio"]:checked');
if (!current || !current.value) return false;
var def = w.querySelector('input[type="radio"][checked]');
return def ? current.value !== def.value : current.value !== '0';
});
if (hasValue) details.open = true;
}