feat(options): Images tab conditional background-image options with server-side initial visibility (Prompt Q)

config.xml: Images background block reordered to backgroundimage,
bodybackgroundcolor, then the three image-detail children
(backgroundimagefixed/display/file, all parent="backgroundimage") —
the color stays directly below the Yes/No choice, the details only
matter when an image is shown.

options.twig: the .option-visibility wrapper now gets a server-side
d-none at render time when the parent buttons group's current value is
not the show-value, so the initial state matches the stored value even
before/without options.js; options.js updateVisibilityByParent() keeps
toggling on change (idempotent, verified by jsdom test).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-25 08:46:34 +01:00
commit 365b60a9b4
2 changed files with 23 additions and 4 deletions

View file

@ -126,11 +126,15 @@
<rightshowoncomputer type="checkbox" category="Images" width="12" title="Computer screen">on</rightshowoncomputer> <rightshowoncomputer type="checkbox" category="Images" width="12" title="Computer screen">on</rightshowoncomputer>
<rightshowontablet type="checkbox" category="Images" width="12" title="Tablet">on</rightshowontablet> <rightshowontablet type="checkbox" category="Images" width="12" title="Tablet">on</rightshowontablet>
<rightshowonmobile type="checkbox" category="Images" width="12" title="Mobile phone">off</rightshowonmobile> <rightshowonmobile type="checkbox" category="Images" width="12" title="Mobile phone">off</rightshowonmobile>
<!-- Prompt Q: order fixed — Background image, then Overall background color
(always relevant), then the three image-detail options which are only
relevant when a background image is shown (parent="backgroundimage",
shown/hidden via .option-visibility in options.twig/options.js). -->
<backgroundimage type="buttons" category="Images" width="4" title="Background image (behind body of page)" options="on|off" optionlabels="Yes|No">on</backgroundimage> <backgroundimage type="buttons" category="Images" width="4" title="Background image (behind body of page)" options="on|off" optionlabels="Yes|No">on</backgroundimage>
<backgroundimagefixed type="buttons" category="Images" width="4" title="Background image fixed or scroll" options="fixed|scroll" optionlabels="Fixed|Scroll">scroll</backgroundimagefixed>
<backgroundimagedisplay type="buttons" category="Images" width="4" title="Background image display" options="tile|cover" optionlabels="Tile|Cover">tile</backgroundimagedisplay>
<backgroundimagefile type="imagefile" category="Images" width="12" title="Background image file" parent="backgroundimage">./files/tiledtexture.png</backgroundimagefile>
<bodybackgroundcolor type="colorpicker" category="Images" width="8" title="Overall background color (when there is no picture in the background)" options="on|off" optionlabels="Yes|No">#dddddd</bodybackgroundcolor> <bodybackgroundcolor type="colorpicker" category="Images" width="8" title="Overall background color (when there is no picture in the background)" options="on|off" optionlabels="Yes|No">#dddddd</bodybackgroundcolor>
<backgroundimagefixed type="buttons" category="Images" width="4" title="Background image fixed or scroll" options="fixed|scroll" optionlabels="Fixed|Scroll" parent="backgroundimage">scroll</backgroundimagefixed>
<backgroundimagedisplay type="buttons" category="Images" width="4" title="Background image display" options="tile|cover" optionlabels="Tile|Cover" parent="backgroundimage">tile</backgroundimagedisplay>
<backgroundimagefile type="imagefile" category="Images" width="12" title="Background image file" parent="backgroundimage">./files/tiledtexture.png</backgroundimagefile>
<!-- Questions <!-- Questions
HOUSE-STYLE: the colorpicker options in this section (question HOUSE-STYLE: the colorpicker options in this section (question

View file

@ -310,7 +310,22 @@
{# parent != '': this field is only visible when the parent option is "on" {# parent != '': this field is only visible when the parent option is "on"
(options.js toggles .option-visibility via data-show-if-parent); (options.js toggles .option-visibility via data-show-if-parent);
the field itself is additionally disabled via data-parent/selector_radio_childfield #} the field itself is additionally disabled via data-parent/selector_radio_childfield #}
<div class="{{ wrapClass }} {% if attr.parent != '' %}option-visibility{% endif %}" {# Prompt Q: server-side INITIAL visibility — when the parent is a buttons
group, add d-none at render time unless the parent's current value is
the show-value ("on"). Same source of truth as currentValue (stored
options JSON, fallback oParentOptions). options.js updateVisibilityByParent()
toggles the same class on change (idempotent with this initial state).
Non-buttons parents (e.g. font's self-parent dropdown) have no radio
inputs -> options.js always shows them, so no d-none here. #}
{% set bParentHidden = false %}
{% if attr.parent != '' %}
{% set parentAttr = aOptionAttributes.optionAttributes[attr.parent] ?? null %}
{% if parentAttr is not null and parentAttr.type == 'buttons' %}
{% set parentValue = bGeneralInherit ? 'inherit' : (aCurrentOptions[attr.parent] is defined ? aCurrentOptions[attr.parent] : (oParentOptions[attr.parent] is defined ? oParentOptions[attr.parent] : '')) %}
{% if parentValue != 'on' %}{% set bParentHidden = true %}{% endif %}
{% endif %}
{% endif %}
<div class="{{ wrapClass }} {% if attr.parent != '' %}option-visibility{% if bParentHidden %} d-none{% endif %}{% endif %}"
{% if attr.parent != '' %}data-show-if-parent="{{ attr.parent }}" data-show-if-value="on"{% endif %}> {% if attr.parent != '' %}data-show-if-parent="{{ attr.parent }}" data-show-if-value="on"{% endif %}>
<div class="mb-3"> <div class="mb-3">
{# label ALWAYS above the control, for every type incl. checkbox (Prompt G) #} {# label ALWAYS above the control, for every type incl. checkbox (Prompt G) #}