Use HTMX fragements on the fitness dashboard
This commit is contained in:
@@ -1,27 +1,11 @@
|
||||
// Fitness dashboard range dropdowns and "absolute" checkboxes: changing one
|
||||
// reloads the page with that chart's query parameter updated. Plain GET
|
||||
// navigation — each view is distinct and bookmarkable, so no
|
||||
// postReplace/history handling is needed.
|
||||
// Fitness dashboard chart hover. The range dropdowns and "absolute"
|
||||
// checkboxes are htmx (assets/fitness/main.html): they swap in only their
|
||||
// chart.
|
||||
// Boosted navigation re-runs this script on every visit; the listeners
|
||||
// are delegated to document, so register them once.
|
||||
if (!window.fitnessWired) {
|
||||
window.fitnessWired = true;
|
||||
|
||||
document.addEventListener('change', function (e) {
|
||||
var url = new URL(window.location.href);
|
||||
var sel = e.target.closest('[data-fitness-range]');
|
||||
var abs = e.target.closest('[data-fitness-absolute]');
|
||||
if (sel) {
|
||||
url.searchParams.set(sel.dataset.fitnessRange, sel.value);
|
||||
} else if (abs) {
|
||||
if (abs.checked) url.searchParams.set(abs.dataset.fitnessAbsolute, '1');
|
||||
else url.searchParams.delete(abs.dataset.fitnessAbsolute);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
window.location.href = url.toString();
|
||||
});
|
||||
|
||||
// Hover tooltip: the pointer snaps to the data point nearest in time. Dots
|
||||
// are sorted by x, so a binary search finds it; the tooltip sits above the
|
||||
// point and is clamped to the chart panel.
|
||||
|
||||
Reference in New Issue
Block a user