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
1 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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue