Fix instance stats week/month tabs not responding after embed preload.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user