From f2ebf24270382bee7aadcaa23612c0f973178373 Mon Sep 17 00:00:00 2001 From: Tammo ter Hark Date: Thu, 26 Nov 2026 13:51:55 +0100 Subject: [PATCH] feat(options): menu item color as preset dropdown with persistent custom color (working example) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- config.xml | 26 +++- css/plain.css | 43 ++++++ options/options.js | 162 ++++++++++++++++++++++- options/options.twig | 26 +++- variants/build.php | 11 ++ views/subviews/header/custom_header.twig | 11 +- 6 files changed, 263 insertions(+), 16 deletions(-) diff --git a/config.xml b/config.xml index 3eb39da..052cd1a 100644 --- a/config.xml +++ b/config.xml @@ -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). --> on - #dddddd + #ffffff scroll tile ./files/tiledtexture.png @@ -203,8 +203,28 @@ Colors pane: sliderhandlecolor + privacybackgroundcolor (final Colors layout = Prompt T, still open). --> - #eeeeee - #444444 + + #ffffff + + default + + + + + + + + #444444 #5e1c64 #eeeeee #5e1c64 diff --git a/css/plain.css b/css/plain.css index c3e006d..b2f0b92 100644 --- a/css/plain.css +++ b/css/plain.css @@ -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 */ diff --git a/options/options.js b/options/options.js index 6c1b7d3..d357fe2 100644 --- a/options/options.js +++ b/options/options.js @@ -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); } - - 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(); } - - 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 = $(''); + sel.after(chips); + sel.data('color-chips', chips); + $.each(presets, function (mode, key) { + var chip = $(''); + 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 = $(''); + group.append($('
').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; diff --git a/options/options.twig b/options/options.twig index dbaa6c7..345f2aa 100644 --- a/options/options.twig +++ b/options/options.twig @@ -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 %} -
+ {# '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 %} +
{# 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 @@
{% if bInherit %} diff --git a/variants/build.php b/variants/build.php index 0384ae6..4c5957c 100644 --- a/variants/build.php +++ b/variants/build.php @@ -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 section found in mother config\n"); diff --git a/views/subviews/header/custom_header.twig b/views/subviews/header/custom_header.twig index efca446..4c831eb 100644 --- a/views/subviews/header/custom_header.twig +++ b/views/subviews/header/custom_header.twig @@ -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; }