diff --git a/options/options.js b/options/options.js index cd8da07..479ee3d 100644 --- a/options/options.js +++ b/options/options.js @@ -948,6 +948,61 @@ var ThemeOptions = function () { // parseOptionObject (needs the stored optionObject) and AFTER // updateAllChildren/updateVisibilityByParent (mode "other" enables the child) 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; diff --git a/options/options.twig b/options/options.twig index 942577b..7805f60 100644 --- a/options/options.twig +++ b/options/options.twig @@ -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.11' %} +{% set OPTIONS_JS_TOKEN = '20261126.12' %} {{ unregisterScriptFile(optionsPath ~ '/options.js') }} {{ registerScriptFile(optionsPath ~ '/options.js?v=' ~ OPTIONS_JS_TOKEN, 'POS_END') }}