feat(options): return to the options tab you were on after Save

Row 133: after changing an option on a non-first tab and saving, the page
reloaded on the first tab. The active tab button id is now stored in
sessionStorage on every tab click (keyed per options-page URL: pathname +
sid/gsid scope, so global and per-survey pages don't clash and volatile
redirect params cannot change the key), and on page load the stored tab is
re-activated by class toggling (nav-link active/aria-selected + pane
active/show) — no Bootstrap API needed. OPTIONS_JS_TOKEN -> 20261126.12.
Verified: render tc=618 (served options.js?v=20261126.12), jsdom 6/6 incl.
new pins (tab click stores the id; a fresh load with the id pre-seeded
activates the stored tab and pane, first tab inactive), export exit 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 18:45:16 +01:00
commit 1b6ae85f83
2 changed files with 56 additions and 1 deletions

View file

@ -948,6 +948,61 @@ var ThemeOptions = function () {
// parseOptionObject (needs the stored optionObject) and AFTER // parseOptionObject (needs the stored optionObject) and AFTER
// updateAllChildren/updateVisibilityByParent (mode "other" enables the child) // updateAllChildren/updateVisibilityByParent (mode "other" enables the child)
safeStep('navbarColorModeUI', navbarColorModeUI); safeStep('navbarColorModeUI', navbarColorModeUI);
// THEME ADDITION (row 133): restore the options tab the user was on before
// Save (after a save the page reloads on the first tab)
safeStep('restoreActiveTab', restoreActiveTab);
safeStep('bindTabPersistence', bindTabPersistence);
};
// THEME ADDITION (row 133): remember the active options tab across Save. The
// active tab button id is stored in sessionStorage, keyed per options-page URL
// (pathname + sid/gsid scope, so global and per-survey pages don't clash and a
// volatile flash param in the redirect URL cannot change the key); on load the
// stored tab is re-activated by class toggling (no Bootstrap API needed).
var tabStorageKey = function () {
var scope = '';
try {
var p = new URLSearchParams(location.search);
scope = p.get('sid') || p.get('gsid') || '';
} catch (e) { /* older browser — scope stays empty */ }
return 'respondage_options_tab:' + location.pathname + '|' + scope;
};
var activateTab = function (btnId) {
var btn = document.getElementById(btnId);
if (!btn || !btn.classList.contains('nav-link')) { return false; }
var nav = btn.closest('.nav-tabs');
var paneSel = btn.getAttribute('data-bs-target') || ('#' + btn.getAttribute('aria-controls'));
var pane = nav && paneSel ? document.querySelector(paneSel) : null;
if (!pane) { return false; }
Array.prototype.forEach.call(nav.querySelectorAll('.nav-link'), function (b) {
var on = b === btn;
b.classList.toggle('active', on);
b.setAttribute('aria-selected', on ? 'true' : 'false');
});
var content = pane.parentElement;
Array.prototype.forEach.call(content.children, function (p) {
if (!p.classList.contains('tab-pane')) { return; }
var on = p === pane;
p.classList.toggle('active', on);
p.classList.toggle('show', on);
});
return true;
};
var restoreActiveTab = function () {
try {
var id = sessionStorage.getItem(tabStorageKey());
if (id) { activateTab(id); }
} catch (e) { /* storage unavailable — keep the first tab */ }
};
var bindTabPersistence = function () {
// plain delegated click listener: works whether or not Bootstrap's tab
// plugin fires its events (shown.bs.tab)
document.addEventListener('click', function (e) {
var t = e.target && e.target.closest ? e.target.closest('.nav-tabs .nav-link') : null;
if (!t || !t.id) { return; }
try { sessionStorage.setItem(tabStorageKey(), t.id); } catch (err) { /* ignore */ }
}, false);
}; };
return run; return run;

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.11' %} {% set OPTIONS_JS_TOKEN = '20261126.12' %}
{{ 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') }}