fix(options): active-swatch outline follows the choice immediately

The outline around the chosen swatch (.color-chip.active) only updated on page
load/save, not when the dropdown choice changed: the refresh was bound as a
direct change handler on the select, and on the real page an earlier direct
handler in the chain can throw, which aborts jQuery's dispatch so the refresh
never ran (native user events still bubble, synthetic triggers do not). Fixes:
the chip click handler now calls refreshAll() directly after triggering change,
and a delegated document-level change handler on select[name=navbarfontcolor]
acts as a backup that still fires for real user changes. OPTIONS_JS_TOKEN ->
20261126.4. jsdom test pins: outline moves on chip click and on dropdown
change, and no preset is outlined in mode 'other'. Suite 6/6, export 0.
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 14:29:50 +01:00
commit 1c89032339
2 changed files with 9 additions and 2 deletions

View file

@ -788,7 +788,10 @@ var ThemeOptions = function () {
var item = $('<span class="color-chip-item"></span>'); var item = $('<span class="color-chip-item"></span>');
var chip = $('<button type="button" class="color-chip" data-mode="' + mode + '"></button>'); var chip = $('<button type="button" class="color-chip" data-mode="' + mode + '"></button>');
var lbl = $('<span class="color-chip-label"></span>'); var lbl = $('<span class="color-chip-label"></span>');
chip.on('click', function () { sel.val(mode).trigger('change'); }); // refreshAll() is called directly too: a throwing EARLIER direct
// change handler (e.g. updateFieldSettings on the real page) aborts
// jQuery's synthetic dispatch, and then the outline would not move
chip.on('click', function () { sel.val(mode).trigger('change'); refreshAll(); });
item.append(chip).append(lbl); item.append(chip).append(lbl);
chips.append(item); chips.append(item);
}); });
@ -835,6 +838,10 @@ var ThemeOptions = function () {
} }
refreshAll(); refreshAll();
sel.on('change', 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); } if (customInput.length) { customInput.on('input change', refreshAll); }
$.each(['fontcolor', 'primarycolor', 'secondarycolor', 'tertiarycolor'], function (i, key) { $.each(['fontcolor', 'primarycolor', 'secondarycolor', 'tertiarycolor'], function (i, key) {
globalForm.find('#simple_edit_options_' + key).on('input change', refreshAll); globalForm.find('#simple_edit_options_' + key).on('input change', refreshAll);

View file

@ -43,7 +43,7 @@
heuristically cached copy (the file has only Last-Modified/ETag, no Cache-Control). 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 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. #} options/options.js changes, so every browser fetches the new file once. #}
{% set OPTIONS_JS_TOKEN = '20261126.3' %} {% set OPTIONS_JS_TOKEN = '20261126.4' %}
{{ unregisterScriptFile(optionsPath ~ '/options.js') }} {{ unregisterScriptFile(optionsPath ~ '/options.js') }}
{{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }} {{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}