diff --git a/lib/common/static/instance_stats.js b/lib/common/static/instance_stats.js index d4e0f19..7b7045a 100644 --- a/lib/common/static/instance_stats.js +++ b/lib/common/static/instance_stats.js @@ -7,7 +7,17 @@ return document.getElementById("stats-segment-select"); } - function activeSegmentPanel() { + function panelFromTrigger(triggerEl) { + if (triggerEl && triggerEl.closest) { + var fromBtn = triggerEl.closest(".stats-segment-panel"); + if (fromBtn) return fromBtn; + } + return null; + } + + function activeSegmentPanel(triggerEl) { + var panel = panelFromTrigger(triggerEl); + if (panel) return panel; var sel = statsSegmentSelect(); if (!sel) return null; var key = sel.value; @@ -30,8 +40,8 @@ ); } - function switchStatsPeriod(periodKey) { - var panel = activeSegmentPanel(); + function switchStatsPeriod(periodKey, triggerEl) { + var panel = activeSegmentPanel(triggerEl); if (!panel) return; var key = PERIODS.indexOf(periodKey) >= 0 ? periodKey : "day"; panel.querySelectorAll(".stats-period-pane").forEach(function (pane) { @@ -64,16 +74,20 @@ function ensurePeriodTabDelegation() { if (global.__instanceStatsTabsDelegated) return; global.__instanceStatsTabsDelegated = true; - document.addEventListener("click", function (e) { - var btn = - e.target && e.target.closest - ? e.target.closest(".stats-period-tab") - : null; - if (!btn) return; - var card = document.getElementById("stats-card"); - if (!card || !card.contains(btn)) return; - switchStatsPeriod(btn.getAttribute("data-stats-period") || "day"); - }); + document.addEventListener( + "click", + function (e) { + var btn = + e.target && e.target.closest + ? e.target.closest(".stats-period-tab") + : null; + if (!btn) return; + var card = document.getElementById("stats-card"); + if (!card || !card.contains(btn)) return; + switchStatsPeriod(btn.getAttribute("data-stats-period") || "day", btn); + }, + true + ); } function initStatsFromUrl() { diff --git a/lib/hub/hub_bridge.py b/lib/hub/hub_bridge.py index 9d22ede..ed4e817 100644 --- a/lib/hub/hub_bridge.py +++ b/lib/hub/hub_bridge.py @@ -68,6 +68,7 @@ def install_instance_theme_static(app) -> None: "strategy_roll.js": "application/javascript; charset=utf-8", "instance_page.css": "text/css; charset=utf-8", "instance_embed.js": "application/javascript; charset=utf-8", + "instance_stats.js": "application/javascript; charset=utf-8", "instance_live.js": "application/javascript; charset=utf-8", "instance_settings_prefs.js": "application/javascript; charset=utf-8", "options_panel.js": "application/javascript; charset=utf-8", diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 5a93e96..33daa3d 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -100,7 +100,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj - + {% include 'embed_boot_scripts.html' %} - +