feat(options): menu item color as preset dropdown with persistent custom color (working example)

navbarfontcolor (Top of the page tab, column 2) changes from a plain
colorpicker to a dropdown: Same as default font color | Color 1 | Color 2 |
Color 3 | Other. The new navbarfontcolorcustom colorpicker stays visible but
grayed out (disabled + aria-disabled) unless 'Other' is chosen, and keeps its
value across saves (data-keep-value) so switching back to 'Other' restores the
last picked color. Dropdown option labels show the live hex of each preset and
clickable swatch chips select a preset; an effective-color swatch next to the
picker shows the color actually applied. A legacy stored hex is migrated to
mode 'other' + custom field (options.js) and accepted directly in
custom_header.twig, so nothing is lost before a theme reset. Views map
default->fontcolor, color1/2/3->primary/secondary/tertiarycolor,
other->navbarfontcolorcustom. headerbackgroundcolor/bodybackgroundcolor stay
plain colorpickers, default #ffffff. build.php maps a legacy hex
navbarfontcolor in variant jsons to other+custom for when variants are built.
Verified: jsdom suite 6/6 (new options_navbar_color_mode test: migration,
gray-out, keep-value on save, chips, swatches), live survey render for all 5
modes, export check exit 0.

NOTE (owner 2026-11-26): variant builds are intentionally DEFERRED — no
customer is waiting; the on-disk variant folders were left at their
pre-feature state and no variant theme was reset. Run
variants/build.php per variant only after the open prompts are done.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-26 13:51:55 +01:00
commit f2ebf24270
6 changed files with 263 additions and 16 deletions

View file

@ -133,7 +133,7 @@
Prompt P: all five width=12 — the Images pane renders them stacked in
column 1 of a three-column grid (only that column is used). -->
<backgroundimage type="buttons" category="Images" width="12" title="Background image (behind body of page)" options="on|off" optionlabels="Yes|No">on</backgroundimage>
<bodybackgroundcolor type="colorpicker" category="Images" width="12" 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="12" title="Overall background color (when there is no picture in the background)" options="on|off" optionlabels="Yes|No">#ffffff</bodybackgroundcolor>
<backgroundimagefixed type="buttons" category="Images" width="12" title="Background image fixed or scroll" options="fixed|scroll" optionlabels="Fixed|Scroll" parent="backgroundimage">scroll</backgroundimagefixed>
<backgroundimagedisplay type="buttons" category="Images" width="12" 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>
@ -203,8 +203,28 @@
Colors pane: sliderhandlecolor + privacybackgroundcolor (final
Colors layout = Prompt T, still open). -->
<!-- Various colors -->
<headerbackgroundcolor type="colorpicker" category="Colors" width="12" title="Header background color" options="on|off" optionlabels="Yes|No">#eeeeee</headerbackgroundcolor>
<navbarfontcolor type="colorpicker" category="Colors" width="12" title="Menu item text color in the top bar (should contrast with the header background color)" options="on|off" optionlabels="Yes|No">#444444</navbarfontcolor>
<!-- Backgrounds of navbar/page stay plain colorpickers (owner decision
2026-11-26, row 115): they are mostly NOT one of the default colors,
default white #ffffff. -->
<headerbackgroundcolor type="colorpicker" category="Colors" width="12" title="Header background color" options="on|off" optionlabels="Yes|No">#ffffff</headerbackgroundcolor>
<!-- Working example (row 115): menu item text color as a preset dropdown.
The KEY navbarfontcolor is kept (stored DB values stay attached); the
type changes colorpicker -> dropdown with modes default|color1|color2|
color3|other. A legacy stored hex value is migrated client-side to mode
"other" + hex into navbarfontcolorcustom (options.js navbarColorModeUI),
and custom_header.twig accepts a raw hex directly. The child
navbarfontcolorcustom is rendered VISIBLE but grayed out (disabled)
unless mode "other" (data-show-if-mode="disable" in options.twig) and
keeps its value across saves (data-keep-value in options.js). -->
<navbarfontcolor type="dropdown" category="Colors" width="12" title="Menu item text color in the top bar (should contrast with the header background color)" options="default|color1|color2|color3|other" optionlabels="Same as default font color|Color 1|Color 2|Color 3|Other…">default
<dropdownoptions>
<option value="default">Same as default font color</option>
<option value="color1">Color 1</option>
<option value="color2">Color 2</option>
<option value="color3">Color 3</option>
<option value="other">Other…</option>
</dropdownoptions></navbarfontcolor>
<navbarfontcolorcustom type="colorpicker" category="Colors" width="12" title="Custom menu item text color (used when 'Other…' is chosen)" parent="navbarfontcolor">#444444</navbarfontcolorcustom>
<sliderhandlecolor type="colorpicker" category="Colors" width="12" title="Slider handle color" options="on|off" optionlabels="Yes|No">#5e1c64</sliderhandlecolor>
<progressbarbackgroundcolor type="colorpicker" category="Colors" width="12" title="Progress bar background color" options="on|off" optionlabels="Yes|No">#eeeeee</progressbarbackgroundcolor>
<progressbarcolor type="colorpicker" category="Colors" width="12" title="Progress bar color" options="on|off" optionlabels="Yes|No">#5e1c64</progressbarcolor>

View file

@ -227,4 +227,47 @@ div.qvideo .question-valid-container {
margin-left: 0;
}
/* Row 115: "disable" mode for parented options (navbarfontcolor working example) —
the child stays visible but grayed out; swatch chips + effective-color swatch. */
.option-visibility-disable .mb-3 {
opacity: 0.55;
}
.color-mode-chips {
display: inline-flex;
gap: 0.25rem;
margin-left: 0.5rem;
vertical-align: middle;
}
.color-chip {
width: 1.1rem;
height: 1.1rem;
padding: 0;
border: 1px solid rgba(0, 0, 0, 0.35);
border-radius: 0.25rem;
cursor: pointer;
background: transparent;
}
.color-chip.active {
outline: 2px solid currentColor;
outline-offset: 1px;
}
.color-chip:focus-visible {
outline: 2px solid #0d6efd;
outline-offset: 1px;
}
.color-mode-effective {
display: inline-block;
width: 1.1rem;
height: 1.1rem;
border: 1px solid rgba(0, 0, 0, 0.35);
border-radius: 0.25rem;
vertical-align: middle;
background: transparent;
}
/*# sourceMappingURL=plain.css.map */

View file

@ -19,6 +19,12 @@ var ThemeOptions = function () {
"general_inherit": 1
}
// THEME ADDITION (row 115): legacy hex value of navbarfontcolor, captured right
// after parseOptionObject — later startup steps (prepareSelectField val() with a
// non-matching value, then updateFieldSettings) can clobber optionObject, so the
// migration in navbarColorModeUI must use this snapshot.
var legacyNavbarFontColor = null;
// THEME FIX: on the GLOBAL theme-options page the hidden #optionCssFiles can
// hold the literal string "inherit" (not JSON) — an unguarded JSON.parse then
// throws inside this constructor, so run() never executes: no change handlers
@ -85,10 +91,21 @@ var ThemeOptions = function () {
globalForm.find('.selector_option_value_field').each(function (i, item) {
//disabled items should be inherit or false
if ($(item).prop('disabled')) {
$(item).val((inheritPossible ? 'inherit' : false));
// THEME ADDITION (row 115, navbarfontcolor working example): a child of a
// "disable"-mode parent (data-keep-value) keeps its stored value instead of
// being reset — the grayed-out picker must remember the custom color even
// when another mode is selected and the form is saved.
if ($(item).data('keep-value')) {
if (optionObject[$(item).attr('name')] === undefined) {
optionObject[$(item).attr('name')] = ($(item).data('inheritvalue') !== undefined ? String($(item).data('inheritvalue')) : '');
}
} else {
$(item).val((inheritPossible ? 'inherit' : false));
optionObject[$(item).attr('name')] = getOptionFieldValue(item);
}
} else {
optionObject[$(item).attr('name')] = getOptionFieldValue(item);
}
});
globalForm.find('.selector_image_selector').each(function (i, item) {
@ -135,10 +152,19 @@ var ThemeOptions = function () {
globalForm.find('.selector_text_option_value_field').each(function (i, item) {
//disabled items should be inherit or false
if ($(item).prop('disabled')) {
$(item).val((inheritPossible ? 'inherit' : false));
// THEME ADDITION (row 115): see the selector_option_value_field loop above —
// data-keep-value children keep their stored value while disabled.
if ($(item).data('keep-value')) {
if (optionObject[$(item).attr('name')] === undefined) {
optionObject[$(item).attr('name')] = ($(item).data('inheritvalue') !== undefined ? String($(item).data('inheritvalue')) : '');
}
} else {
$(item).val((inheritPossible ? 'inherit' : false));
optionObject[$(item).attr('name')] = $(item).val();
}
} else {
optionObject[$(item).attr('name')] = $(item).val();
}
});
var newOptionObject = $.extend(true, {}, optionObject);
@ -340,6 +366,8 @@ var ThemeOptions = function () {
}
$(childEl).prop('disabled', !enabled);
// a11y: mirror the disabled state for assistive technology (row 115)
$(childEl).attr('aria-disabled', String(!enabled));
};
// grab the parent for a given child field
@ -367,6 +395,13 @@ var ThemeOptions = function () {
const updateVisibilityByParent = function() {
$('.option-visibility[data-show-if-parent]').each(function (i, wrapperEl) {
const parentName = $(wrapperEl).data('show-if-parent');
// THEME ADDITION (row 115, navbarfontcolor working example): parents with
// data-show-if-mode="disable" never hide their children — the wrapper stays
// visible and only the child control is disabled (updateChild/updateAllChildren).
if (String($(wrapperEl).data('show-if-mode') || 'hide') === 'disable') {
$(wrapperEl).removeClass('d-none');
return;
}
// THEME ADDITION (Prompt R): multi-value — data-show-if-value may be a
// pipe-separated list (e.g. "box|top" for questionborder); a single
// value keeps working unchanged.
@ -700,6 +735,106 @@ var ThemeOptions = function () {
});
};
// THEME ADDITION (row 115, working example on navbarfontcolor only): preset-dropdown
// UI for the "Menu item text color" option.
// - option labels of the navbarfontcolor dropdown get the LIVE hex of the preset
// they point at ("Color 1 [#5e1c64]" — values read from the stored options JSON /
// the fields' data-inheritvalue, so they also work at survey level with inherit)
// - clickable swatch chips next to the dropdown (one per preset; click = choose it)
// - an "effective color" swatch appended to the custom picker's input group, showing
// the color that is actually applied for the current mode (overwritable by picking
// another color when mode is "other")
// - legacy migration: a stored HEX value of navbarfontcolor (from before the option
// became a dropdown) selects mode "other" and moves the hex into navbarfontcolorcustom
var navbarColorModeUI = function () {
var sel = globalForm.find('select[name="navbarfontcolor"]');
if (!sel.length) { return; }
var presets = { 'default': 'fontcolor', 'color1': 'primarycolor', 'color2': 'secondarycolor', 'color3': 'tertiarycolor' };
var customInput = globalForm.find('input[name="navbarfontcolorcustom"]');
var currentColor = function (key) {
var f = globalForm.find('#simple_edit_options_' + key);
var v = f.val();
if (!v) { v = f.data('inheritvalue'); }
return v ? String(v) : '';
};
var effectiveColor = function () {
var mode = String(sel.val());
if (mode === 'other') { return customInput.length && customInput.val() ? String(customInput.val()) : ''; }
var pk = presets[mode];
return pk ? currentColor(pk) : '';
};
var refreshLabels = function () {
sel.find('option').each(function () {
var op = $(this);
var mode = String(op.attr('value'));
if (!op.data('base-label')) { op.data('base-label', op.text()); }
var base = String(op.data('base-label'));
var pk = presets[mode];
if (pk) {
var c = currentColor(pk);
op.text(c ? base + ' [' + c + ']' : base);
}
});
};
var refreshChips = function () {
var chips = sel.data('color-chips');
if (!chips) {
chips = $('<span class="color-mode-chips"></span>');
sel.after(chips);
sel.data('color-chips', chips);
$.each(presets, function (mode, key) {
var chip = $('<button type="button" class="color-chip" data-mode="' + mode + '" aria-label="' + mode + '"></button>');
chip.on('click', function () { sel.val(mode).trigger('change'); });
chips.append(chip);
});
}
chips.find('.color-chip').each(function () {
var chip = $(this);
var mode = String(chip.data('mode'));
var c = currentColor(presets[mode]);
chip.css('background', c || 'transparent');
chip.attr('title', mode + (c ? ' [' + c + ']' : ''));
chip.attr('aria-label', chip.attr('title'));
chip.toggleClass('active', String(sel.val()) === mode);
});
};
var refreshEffective = function () {
var group = customInput.closest('.input-group');
if (!group.length) { return; }
var sw = group.find('.color-mode-effective');
if (!sw.length) {
sw = $('<span class="color-mode-effective"></span>');
group.append($('<div class="input-group-text"></div>').append(sw));
}
var c = effectiveColor();
sw.css('background', c || 'transparent');
sw.attr('title', c ? 'Effective menu item color: ' + c : 'Effective menu item color: (none)');
};
var refreshAll = function () { refreshLabels(); refreshChips(); refreshEffective(); };
// legacy migration: stored hex (pre-dropdown value) -> mode "other" + hex into the custom field
var stored = legacyNavbarFontColor;
if (typeof stored === 'string' && /^#[0-9a-fA-F]{3,8}$/.test(stored)) {
sel.val('other');
if (customInput.length && !/^#[0-9a-fA-F]{3,8}$/.test(String(customInput.val() || ''))) {
customInput.val(stored);
}
// re-evaluate the child's disabled state for the migrated mode
updateAllChildren();
updateVisibilityByParent();
} else if (!sel.val()) {
// no (matching) stored value: fall back to the first option
sel.val('default');
updateAllChildren();
updateVisibilityByParent();
}
refreshAll();
sel.on('change', refreshAll);
if (customInput.length) { customInput.on('input change', refreshAll); }
$.each(['fontcolor', 'primarycolor', 'secondarycolor', 'tertiarycolor'], function (i, key) {
globalForm.find('#simple_edit_options_' + key).on('input change', refreshAll);
});
};
// THEME HARDENING: run every startup step isolated — one throwing step must
// NEVER prevent bind() (without the save/change handlers, Save silently
// posts the stale options JSON; that is exactly the 2026-11-25 regression
@ -720,6 +855,15 @@ var ThemeOptions = function () {
var run = function () {
safeStep('parseOptionObject', parseOptionObject);
// THEME ADDITION (row 115): snapshot a legacy hex navbarfontcolor before other
// startup steps can clobber optionObject (prepareSelectField + updateFieldSettings)
safeStep('captureNavbarLegacy', function () {
var v = optionObject['navbarfontcolor'];
if (typeof v === 'string' && /^#[0-9a-fA-F]{3,8}$/.test(v)) {
legacyNavbarFontColor = v;
}
});
safeStep('startupGeneralInherit', startupGeneralInherit);
safeStep('prepareSelectField', prepareSelectField);
@ -741,6 +885,12 @@ var ThemeOptions = function () {
// THEME ADDITION: set initial visibility of conditional fields
safeStep('updateVisibilityByParent', updateVisibilityByParent);
// THEME ADDITION (row 115): preset-dropdown UI for navbarfontcolor (labels,
// swatch chips, effective-color swatch, legacy hex migration) — AFTER
// parseOptionObject (needs the stored optionObject) and AFTER
// updateAllChildren/updateVisibilityByParent (mode "other" enables the child)
safeStep('navbarColorModeUI', navbarColorModeUI);
};
return run;

View file

@ -43,7 +43,7 @@
heuristically cached copy (the file has only Last-Modified/ETag, no Cache-Control).
Re-register it with a version token: bump OPTIONS_JS_TOKEN below whenever
options/options.js changes, so every browser fetches the new file once. #}
{% set OPTIONS_JS_TOKEN = '20261125.5' %}
{% set OPTIONS_JS_TOKEN = '20261126.1' %}
{{ unregisterScriptFile(optionsPath ~ '/options.js') }}
{{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}
@ -142,7 +142,7 @@
Values are stored per option key, so moving them here does not change any stored
value. The order of this list is the order shown in the tab. #}
{% set aTopOfPageKeys = [
'headerbackgroundcolor', 'headerfont', 'navbarfontcolor',
'headerbackgroundcolor', 'headerfont', 'navbarfontcolor', 'navbarfontcolorcustom',
'headersticky', 'headerstickycomputer', 'headerstickytablet', 'headerstickymobile',
'brandlogofile', 'brandlogotopmargin', 'brandshowoncomputer', 'brandshowontablet', 'brandshowonmobile',
'centerlogofile', 'centerlogotopmargin', 'centershowoncomputer', 'centershowontablet', 'centershowonmobile',
@ -162,9 +162,16 @@
{% set aFontElements = ['questiontitle', 'answers', 'grouptitle', 'groupdescription', 'buttons'] %}
{% set aShowIfValues = { 'questionborder': 'box|top' } %}
{% set aShowIfValues = { 'questionborder': 'box|top', 'navbarfontcolor': 'other' } %}
{% for el in aFontElements %}{% set aShowIfValues = aShowIfValues|merge({ (el ~ 'textcolor'): 'other' }) %}{% endfor %}
{# How a parented option behaves when the parent's value is NOT in the show-values:
default 'hide' = wrapper gets d-none; 'disable' = wrapper STAYS VISIBLE but the
child control is rendered disabled (grayed out) and carries data-keep-value so
options.js keeps its stored value across saves. Working example: navbarfontcolor
(row 115) — the custom color picker stays visible next to the mode dropdown. #}
{% set aShowIfMode = { 'navbarfontcolor': 'disable' } %}
{% set aFontsRow1 = ['font', 'fontcolor', 'fontsize'] %}
{% set aFontsRow2 = ['primarycolor', 'secondarycolor', 'tertiarycolor'] %}
@ -406,8 +413,14 @@
{% if parentValue not in showIfValues|split('|') %}{% 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="{{ showIfValues }}"{% endif %}>
{# 'disable' mode (aShowIfMode): the child stays visible but is rendered
disabled server-side; options.js keeps toggling only disabled (never
d-none) for these wrappers, and data-keep-value makes the serializer
keep the stored child value instead of resetting it to inherit/false #}
{% set bDisableMode = attr.parent != '' and (aShowIfMode[attr.parent] ?? 'hide') == 'disable' %}
{% set bChildDisabled = bParentHidden and bDisableMode %}
<div class="{{ wrapClass }} {% if attr.parent != '' %}option-visibility{% if bParentHidden and not bDisableMode %} d-none{% endif %}{% endif %}"
{% if attr.parent != '' %}data-show-if-parent="{{ attr.parent }}" data-show-if-value="{{ showIfValues }}"{% if bDisableMode %} data-show-if-mode="disable"{% endif %}{% endif %}>
<div class="mb-3">
{# label ALWAYS above the control, for every option type EXCEPT checkbox
(checkboxes carry their label to the RIGHT of the box, rendered in
@ -509,12 +522,15 @@
<div class="input-group-text style__colorpicker">
<input type="color" name="{{ key }}_picker" data-value="{{ oParentOptions[key] }}"
{% if currentValue matches '/^#[0-9a-fA-F]{3,8}$/' %}value="{{ currentValue }}"{% endif %}
{% if bChildDisabled %}disabled aria-disabled="true"{% endif %}
class="selector__colorpicker-inherit-value"/>
</div>
<input type="text" name="{{ key }}" data-inheritvalue="{{ oParentOptions[key] }}"
value="{% if currentValue != '' and currentValue != 'inherit' %}{{ currentValue }}{% endif %}"
{% if bInherit %}placeholder="{{ gT("Inherit") }} [{{ gT("Inherited value:") }} {{ oParentOptions[key] }}]"{% endif %}
{% if attr.parent != '' %}data-parent="{{ attr.parent }}"{% endif %}
{% if bChildDisabled %}disabled aria-disabled="true"{% endif %}
{% if bDisableMode %}data-keep-value="1"{% endif %}
id="simple_edit_options_{{ key }}"
class="selector_option_value_field selector__color-picker form-control simple_edit_options_{{ key }}{% if attr.parent != '' %} selector_radio_childfield{% endif %}"/>
{% if bInherit %}

View file

@ -268,6 +268,17 @@ foreach ($logoPositions as $pos) {
}
}
// --- Row 115 migration: navbarfontcolor became a mode dropdown (default|color1|
// color2|color3|other) with a navbarfontcolorcustom colorpicker child. A legacy HEX
// value in the json means "custom color": map it to mode "other" and move the hex
// into navbarfontcolorcustom, so the variant default stays valid for the dropdown.
if (isset($definition['options']['navbarfontcolor'])
&& is_string($definition['options']['navbarfontcolor'])
&& preg_match('/^#[0-9a-fA-F]{3,8}$/', $definition['options']['navbarfontcolor'])) {
$definition['options']['navbarfontcolorcustom'] = $definition['options']['navbarfontcolor'];
$definition['options']['navbarfontcolor'] = 'other';
}
$optionsNode = $xpath->query('//options')->item(0);
if ($optionsNode === null) {
fwrite(STDERR, "No <options> section found in mother config\n");

View file

@ -179,16 +179,23 @@
padding-top: {{ aSurveyInfo.options.rightlogotopmargin|default('15')|replace({'px': ''}) }}px;
}
{# Row 115 working example: navbarfontcolor is now a MODE dropdown
(default|color1|color2|color3|other). Resolve the effective color:
default -> fontcolor, color1/2/3 -> primarycolor/secondarycolor/tertiarycolor,
other -> navbarfontcolorcustom. A raw hex value (legacy stored value from
before the dropdown existed, or a hand-set one) is used directly. #}
{% set sNavbarFontColorMode = aSurveyInfo.options.navbarfontcolor|default('default') %}
{% set sNavbarFontColor = sNavbarFontColorMode matches '/^#[0-9a-fA-F]{3,8}$/' ? sNavbarFontColorMode : (sNavbarFontColorMode == 'color1' ? aSurveyInfo.options.primarycolor|default('') : (sNavbarFontColorMode == 'color2' ? aSurveyInfo.options.secondarycolor|default('') : (sNavbarFontColorMode == 'color3' ? aSurveyInfo.options.tertiarycolor|default('') : (sNavbarFontColorMode == 'other' ? aSurveyInfo.options.navbarfontcolorcustom|default('') : aSurveyInfo.options.fontcolor|default(''))))) %}
#survey-nav .navbar-nav > li > a,
#survey-nav .navbar-nav .nav-link {
color: {{ aSurveyInfo.options.navbarfontcolor }};
color: {{ sNavbarFontColor }};
}
#survey-nav .navbar-nav > li > a:hover,
#survey-nav .navbar-nav > li > a:focus,
#survey-nav .navbar-nav .nav-link:hover,
#survey-nav .navbar-nav .nav-link:focus {
color: {{ aSurveyInfo.options.navbarfontcolor }};
color: {{ sNavbarFontColor }};
opacity: 0.75;
}