feat(options): roll the color-chooser scheme out to 4 more options (row 135)

The experimental color-chooser (mode dropdown + swatch chips + custom picker,
previously only navbarfontcolor) now also covers, with the owner-specified
defaults:
- headerbackgroundcolor — default "Default background color" (slot h1)
- progressbarcolor — COLUMN 1 of the progress colors row (was col 2), default Color 1
- progressbarbackgroundcolor — COLUMN 2 (was col 1), default Default background color
- progressbarfontcolor — column 3, default Default font color, with an extra tip
  underneath: "Make this font color the same color as the color of the progress
  bar when you do not want to see the progress in %."

Each option is a dropdown (default|defaultbackgroundcolor|color1|color2|color3|
other) whose own default carries data-default="1" + [ ] in config.xml, plus a
<key>custom colorpicker child (parent, disable-mode, data-keep-value). options.js
generalized navbarColorModeUI to colorModeUI(key) over aColorChooserKeys with
shared presets, one delegated change handler for select.selector_color_mode, and
per-key legacy hex migration (stored hex -> mode "other" + hex into the custom
child). custom_header.twig resolves the modes via a local cm() macro (import
_self, same pattern as nav_bar.twig); raw hex passes through. build.php migrates
legacy hex values in variant jsons for all 5 chooser keys. OPTIONS_JS_TOKEN ->
20261126.14. Verified: render tc=618 (all 5 selects with per-option [ ] default,
progress row col order, tip present, divs balanced, options.js?v=20261126.14),
jsdom 7/7 incl. new options_color_choosers.test.js (5 choosers, legacy migration,
chips, layout, tip) and the navbar test re-scoped to its own chips; live survey
282267 with legacy hex AND with modes (color2 -> #888888, defaultbackgroundcolor
-> #ffffff; DB row restored); export exit 0; build.php lints. Variants not
rebuilt (deferred).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Tammo ter Hark 2026-11-26 19:14:47 +01:00
commit cfbb4c983b

View file

@ -19,11 +19,21 @@ 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 ADDITION (row 115, generalized row 135): legacy hex values of the
// color-chooser options, captured right after parseOptionObject — later startup
// steps (prepareSelectField val() with a non-matching value, then
// updateFieldSettings) can clobber optionObject, so the migration in colorModeUI
// must use this snapshot.
var legacyColorValues = {};
// row 135: all options that use the color-chooser scheme (mode dropdown with
// class selector_color_mode + swatch chips + a <key>custom colorpicker child)
var aColorChooserKeys = ['navbarfontcolor', 'headerbackgroundcolor', 'progressbarcolor', 'progressbarbackgroundcolor', 'progressbarfontcolor'];
// the 5 presets, in the SAME order as the dropdown options in config.xml
// (object key order = swatch chip order) — row 125: "Default background color"
// is the SECOND choice, right after "Default font color".
var colorPresets = { 'default': 'fontcolor', 'defaultbackgroundcolor': 'defaultbackgroundcolor', 'color1': 'primarycolor', 'color2': 'secondarycolor', 'color3': 'tertiarycolor' };
// one refreshAll per chooser, called by the shared delegated handlers
var colorModeRefreshers = [];
// THEME FIX: on the GLOBAL theme-options page the hidden #optionCssFiles can
// hold the literal string "inherit" (not JSON) — an unguarded JSON.parse then
@ -735,25 +745,21 @@ var ThemeOptions = function () {
});
};
// THEME ADDITION (row 115, working example on navbarfontcolor only): preset-dropdown
// UI for the "Menu item color in header" 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 /
// THEME ADDITION (row 115 on navbarfontcolor, generalized row 135 to every key in
// aColorChooserKeys): preset-dropdown UI for a color-chooser option.
// - option labels of the 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"]');
// - legacy migration: a stored HEX value (from before the option became a
// dropdown) selects mode "other" and moves the hex into the <key>custom child
var colorModeUI = function (key) {
var sel = globalForm.find('select[name="' + key + '"]');
if (!sel.length) { return; }
// row 124/125: 5 presets, in the SAME order as the dropdown options in
// config.xml (object key order = swatch chip order) — row 125: the
// "Default background color" is the SECOND choice, right after "Same as
// default font color".
var presets = { 'default': 'fontcolor', 'defaultbackgroundcolor': 'defaultbackgroundcolor', 'color1': 'primarycolor', 'color2': 'secondarycolor', 'color3': 'tertiarycolor' };
var presets = colorPresets;
// row 126/134: the option's DEFAULT choice — the config.xml <option data-default="1">
// (same value as the <default> element text). In the dropdown LIST it is
// enclosed in [ ] (bolding <option> is not rendered by every browser — row 134);
@ -764,9 +770,10 @@ var ThemeOptions = function () {
|| sel.data('inheritvalue')
|| sel.find('option').not('[value="inherit"]').first().attr('value')
|| '');
var customInput = globalForm.find('input[name="navbarfontcolorcustom"]');
var currentColor = function (key) {
var f = globalForm.find('#simple_edit_options_' + key);
var customInput = globalForm.find('input[name="' + key + 'custom"]');
var rowLabel = String(sel.closest('.mb-3').find('.form-label').first().text() || key);
var currentColor = function (ckey) {
var f = globalForm.find('#simple_edit_options_' + ckey);
var v = f.val();
if (!v) { v = f.data('inheritvalue'); }
return v ? String(v) : '';
@ -850,11 +857,12 @@ var ThemeOptions = function () {
}
var c = effectiveColor();
sw.css('background', c || 'transparent');
sw.attr('title', c ? 'Effective menu item color: ' + c : 'Effective menu item color: (none)');
sw.attr('title', c ? 'Effective color (' + rowLabel + '): ' + c : 'Effective color (' + rowLabel + '): (none)');
};
var refreshAll = function () { refreshLabels(); refreshChips(); refreshEffective(); };
colorModeRefreshers.push(refreshAll);
// legacy migration: stored hex (pre-dropdown value) -> mode "other" + hex into the custom field
var stored = legacyNavbarFontColor;
var stored = legacyColorValues[key];
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() || ''))) {
@ -876,13 +884,22 @@ var ThemeOptions = function () {
}
refreshAll();
sel.on('change', refreshAll);
// Delegated backup: a REAL user change event bubbles natively to document even
// when an earlier direct handler threw (jQuery only aborts synthetic triggers),
// so the active outline still moves on the chosen swatch (row 122).
$(document).on('change', 'select[name="navbarfontcolor"]', refreshAll);
if (customInput.length) { customInput.on('input change', refreshAll); }
$.each(['fontcolor', 'primarycolor', 'secondarycolor', 'tertiarycolor', 'defaultbackgroundcolor'], function (i, key) {
globalForm.find('#simple_edit_options_' + key).on('input change', refreshAll);
};
// Shared delegated handlers for ALL chooser dropdowns (row 122/135): a REAL user
// change event bubbles natively to document even when an earlier direct handler
// threw (jQuery only aborts synthetic triggers), so the active outline still moves
// on the chosen swatch. Bound once, calling every chooser's refreshAll.
var bindColorModeDelegates = function () {
$(document).on('change', 'select.selector_color_mode', function () {
$.each(colorModeRefreshers, function (i, fn) { try { fn(); } catch (e) { /* keep the others running */ } });
});
// live hex labels/chips update when one of the shared color fields changes
$.each(['fontcolor', 'primarycolor', 'secondarycolor', 'tertiarycolor', 'defaultbackgroundcolor'], function (i, ckey) {
globalForm.find('#simple_edit_options_' + ckey).on('input change', function () {
$.each(colorModeRefreshers, function (j, fn) { try { fn(); } catch (e) { /* ignore */ } });
});
});
};
@ -906,13 +923,16 @@ 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;
}
// THEME ADDITION (row 115, generalized row 135): snapshot a legacy hex value of
// every color-chooser option before other startup steps can clobber
// optionObject (prepareSelectField + updateFieldSettings)
safeStep('captureLegacyColorValues', function () {
$.each(aColorChooserKeys, function (i, k) {
var v = optionObject[k];
if (typeof v === 'string' && /^#[0-9a-fA-F]{3,8}$/.test(v)) {
legacyColorValues[k] = v;
}
});
});
safeStep('startupGeneralInherit', startupGeneralInherit);
@ -937,11 +957,15 @@ 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);
// THEME ADDITION (row 115, generalized row 135): preset-dropdown UI for every
// color-chooser option (labels with live hex, swatch chips, effective-color
// swatch, legacy hex migration) — AFTER parseOptionObject (needs the stored
// optionObject) and AFTER updateAllChildren/updateVisibilityByParent
// (mode "other" enables the child)
$.each(aColorChooserKeys, function (i, k) {
safeStep('colorModeUI:' + k, function () { colorModeUI(k); });
});
safeStep('bindColorModeDelegates', bindColorModeDelegates);
// THEME ADDITION (row 133): restore the options tab the user was on before
// Save (after a save the page reloads on the first tab)