diff --git a/lib/common/static/instance_embed.js b/lib/common/static/instance_embed.js index c3efd8d..f5c3d2c 100644 --- a/lib/common/static/instance_embed.js +++ b/lib/common/static/instance_embed.js @@ -109,7 +109,7 @@ global.toggleReviewMode(); } } - if (!revisit && tab === "stats") { + if (tab === "stats") { if (typeof global.initStatsSegmentFromUrl === "function") global.initStatsSegmentFromUrl(); } if (tab === "settings" || tab === "env_config") { diff --git a/lib/common/static/instance_stats.js b/lib/common/static/instance_stats.js index 67dabcb..d4e0f19 100644 --- a/lib/common/static/instance_stats.js +++ b/lib/common/static/instance_stats.js @@ -61,20 +61,25 @@ switchStatsPeriod(period); } - function bindPeriodTabs() { - document.querySelectorAll(".stats-period-tab").forEach(function (btn) { - if (btn.getAttribute("data-stats-bound") === "1") return; - btn.setAttribute("data-stats-bound", "1"); - btn.addEventListener("click", function () { - switchStatsPeriod(btn.getAttribute("data-stats-period") || "day"); - }); + 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"); }); } function initStatsFromUrl() { var sel = statsSegmentSelect(); if (!sel) return; - bindPeriodTabs(); + ensurePeriodTabDelegation(); var url = new URLSearchParams(global.location.search); var segKey = url.get("stats_segment"); if ( @@ -89,6 +94,8 @@ switchStatsPeriod(period); } + ensurePeriodTabDelegation(); + global.switchStatsSegment = switchStatsSegment; global.switchStatsPeriod = switchStatsPeriod; global.initStatsFromUrl = initStatsFromUrl; diff --git a/lib/instance/templates/embed_shell.html b/lib/instance/templates/embed_shell.html index 21ff920..8e3b4cf 100644 --- a/lib/instance/templates/embed_shell.html +++ b/lib/instance/templates/embed_shell.html @@ -100,13 +100,13 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj - + {% include 'embed_boot_scripts.html' %} - + diff --git a/lib/instance/templates/index.html b/lib/instance/templates/index.html index 0854cb3..2c45e40 100644 --- a/lib/instance/templates/index.html +++ b/lib/instance/templates/index.html @@ -629,7 +629,7 @@ const ORDER_ENTRY_MODEL_CODE_TO_CATEGORY = {{ entry_model_code_to_category | toj - +