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:
parent
57c7009ec2
commit
cfbb4c983b
2 changed files with 184 additions and 63 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 = '20261126.13' %}
|
||||
{% set OPTIONS_JS_TOKEN = '20261126.14' %}
|
||||
{{ unregisterScriptFile(optionsPath ~ '/options.js') }}
|
||||
{{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}
|
||||
|
||||
|
|
@ -224,12 +224,13 @@
|
|||
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', 'navbarfontcolorcustom',
|
||||
'headerbackgroundcolor', 'headerbackgroundcolorcustom', 'headerfont', 'navbarfontcolor', 'navbarfontcolorcustom',
|
||||
'headersticky', 'headerstickycomputer', 'headerstickytablet', 'headerstickymobile',
|
||||
'brandlogofile', 'brandlogotopmargin', 'brandshowoncomputer', 'brandshowontablet', 'brandshowonmobile',
|
||||
'centerlogofile', 'centerlogotopmargin', 'centershowoncomputer', 'centershowontablet', 'centershowonmobile',
|
||||
'rightlogofile', 'rightlogotopmargin', 'rightshowoncomputer', 'rightshowontablet', 'rightshowonmobile',
|
||||
'progressbarposition', 'progressbarfont', 'progressbarbackgroundcolor', 'progressbarcolor', 'progressbarfontcolor'
|
||||
'progressbarposition', 'progressbarfont', 'progressbarcolor', 'progressbarcolorcustom',
|
||||
'progressbarbackgroundcolor', 'progressbarbackgroundcolorcustom', 'progressbarfontcolor', 'progressbarfontcolorcustom'
|
||||
] %}
|
||||
{% set aLogoKeys = [
|
||||
'brandlogofile', 'brandlogotopmargin', 'brandshowoncomputer', 'brandshowontablet', 'brandshowonmobile',
|
||||
|
|
@ -244,8 +245,11 @@
|
|||
|
||||
{% set aFontElements = ['questiontitle', 'answers', 'grouptitle', 'groupdescription', 'buttons'] %}
|
||||
|
||||
{% set aColorChooserKeys = ['navbarfontcolor', 'headerbackgroundcolor', 'progressbarcolor', 'progressbarbackgroundcolor', 'progressbarfontcolor'] %}
|
||||
|
||||
{% set aShowIfValues = { 'questionborder': 'box|top', 'navbarfontcolor': 'other' } %}
|
||||
{% for el in aFontElements %}{% set aShowIfValues = aShowIfValues|merge({ (el ~ 'textcolor'): 'other' }) %}{% endfor %}
|
||||
{% for ck in aColorChooserKeys %}{% set aShowIfValues = aShowIfValues|merge({ (ck): '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
|
||||
|
|
@ -253,6 +257,7 @@
|
|||
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' } %}
|
||||
{% for ck in aColorChooserKeys %}{% set aShowIfMode = aShowIfMode|merge({ (ck): 'disable' }) %}{% endfor %}
|
||||
|
||||
{% set aFontsRow1 = ['font', 'fontcolor', 'fontsize'] %}
|
||||
{% set aFontsRow2 = ['primarycolor', 'secondarycolor', 'tertiarycolor'] %}
|
||||
|
|
@ -366,15 +371,22 @@
|
|||
{% elseif bTopPane %}
|
||||
{% if key in aLogoKeys %}{% set fSlot = 'logo' %}
|
||||
{% elseif key == 'headerbackgroundcolor' %}{% set fSlot = 'h1' %}
|
||||
{% elseif key == 'headerbackgroundcolorcustom' %}{% set fSlot = 'h1' %}
|
||||
{% elseif key == 'headerfont' %}{% set fSlot = 'hf' %}
|
||||
{% elseif key == 'navbarfontcolor' %}{% set fSlot = 'h2' %}
|
||||
{% elseif key == 'navbarfontcolorcustom' %}{% set fSlot = 'h2' %}
|
||||
{% elseif key in aTopStickyKeys %}{% set fSlot = 'h3' %}
|
||||
{% elseif key == 'progressbarposition' %}{% set fSlot = 'ppos' %}
|
||||
{% elseif key == 'progressbarfont' %}{% set fSlot = 'pfont' %}
|
||||
{% elseif key == 'progressbarbackgroundcolor' %}{% set fSlot = 'pcol1' %}
|
||||
{% elseif key == 'progressbarcolor' %}{% set fSlot = 'pcol2' %}
|
||||
{# row 135: progress bar colors row — col 1 = progress bar color,
|
||||
col 2 = progress background, col 3 = progress font color
|
||||
(custom children share their parent's column) #}
|
||||
{% elseif key == 'progressbarcolor' %}{% set fSlot = 'pcol1' %}
|
||||
{% elseif key == 'progressbarcolorcustom' %}{% set fSlot = 'pcol1' %}
|
||||
{% elseif key == 'progressbarbackgroundcolor' %}{% set fSlot = 'pcol2' %}
|
||||
{% elseif key == 'progressbarbackgroundcolorcustom' %}{% set fSlot = 'pcol2' %}
|
||||
{% elseif key == 'progressbarfontcolor' %}{% set fSlot = 'pcol3' %}
|
||||
{% elseif key == 'progressbarfontcolorcustom' %}{% set fSlot = 'pcol3' %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if fSlot != fLastSlot and (bFontsPane or bTopPane) %}
|
||||
|
|
@ -559,6 +571,7 @@
|
|||
{% if attr.parent != '' %}{% set ddClasses = ddClasses ~ ' selector_radio_childfield' %}{% endif %}
|
||||
{% if tab.category == 'Images' %}{% set ddClasses = ddClasses ~ ' selector_image_selector' %}{% endif %}
|
||||
{% if key == 'font' %}{% set ddClasses = ddClasses ~ ' selector_fontselect' %}{% endif %}
|
||||
{% if key in aColorChooserKeys %}{% set ddClasses = ddClasses ~ ' selector_color_mode' %}{% endif %}
|
||||
<select class="{{ ddClasses }}"
|
||||
{% if attr.parent != '' %}data-parent="{{ attr.parent }}"{% endif %}
|
||||
data-inheritvalue="{{ oParentOptions[key] }}"
|
||||
|
|
@ -642,6 +655,12 @@
|
|||
id="simple_edit_options_{{ key }}" name="{{ key }}"
|
||||
title="{{ gT("Inherited value:") }} {{ oParentOptions[key] }}"/>
|
||||
{% endif %}
|
||||
{# row 135: extra tip underneath the whole "Progress bar font color"
|
||||
option (attached to its custom child, which renders last in the
|
||||
same column, so the tip sits at the bottom of the option) #}
|
||||
{% if key == 'progressbarfontcolorcustom' %}
|
||||
<div class="form-text mt-1">{{ gT("Make this font color the same color as the color of the progress bar when you do not want to see the progress in %.") }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue