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:
parent
7939f3de3f
commit
f2ebf24270
2 changed files with 263 additions and 16 deletions
|
|
@ -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 = $('<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;
|
||||
|
|
|
|||
|
|
@ -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 %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue