style: convert var to const in sparkline toggle block (#16)
This commit is contained in:
@@ -529,23 +529,23 @@ function closeAddPlayerModal(event) {
|
|||||||
|
|
||||||
// ── Sparkline toggle ───────────────────────────────
|
// ── Sparkline toggle ───────────────────────────────
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var SPARKLINE_KEY = 'ratingtracker.sparklines';
|
const SPARKLINE_KEY = 'ratingtracker.sparklines';
|
||||||
|
|
||||||
function syncSparklineButtons(state) {
|
function syncSparklineButtons(state) {
|
||||||
var btns = document.querySelectorAll('#trendchart-toggle, #trendchart-toggle-mobile');
|
const btns = document.querySelectorAll('#trendchart-toggle, #trendchart-toggle-mobile');
|
||||||
btns.forEach(function(b) {
|
btns.forEach(function(b) {
|
||||||
b.setAttribute('aria-pressed', state === 'on' ? 'true' : 'false');
|
b.setAttribute('aria-pressed', state === 'on' ? 'true' : 'false');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = localStorage.getItem(SPARKLINE_KEY) || 'on';
|
const state = localStorage.getItem(SPARKLINE_KEY) || 'on';
|
||||||
document.body.dataset.sparklines = state;
|
document.body.dataset.sparklines = state;
|
||||||
syncSparklineButtons(state);
|
syncSparklineButtons(state);
|
||||||
|
|
||||||
document.body.addEventListener('click', function(e) {
|
document.body.addEventListener('click', function(e) {
|
||||||
var target = e.target.closest('#trendchart-toggle, #trendchart-toggle-mobile');
|
const target = e.target.closest('#trendchart-toggle, #trendchart-toggle-mobile');
|
||||||
if (!target) return;
|
if (!target) return;
|
||||||
var next = document.body.dataset.sparklines === 'on' ? 'off' : 'on';
|
const next = document.body.dataset.sparklines === 'on' ? 'off' : 'on';
|
||||||
document.body.dataset.sparklines = next;
|
document.body.dataset.sparklines = next;
|
||||||
localStorage.setItem(SPARKLINE_KEY, next);
|
localStorage.setItem(SPARKLINE_KEY, next);
|
||||||
syncSparklineButtons(next);
|
syncSparklineButtons(next);
|
||||||
@@ -553,7 +553,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// Re-sync after HTMX table swap (mobile button is inside the swapped partial)
|
// Re-sync after HTMX table swap (mobile button is inside the swapped partial)
|
||||||
document.body.addEventListener('htmx:afterSwap', function(event) {
|
document.body.addEventListener('htmx:afterSwap', function(event) {
|
||||||
var target = event.detail.target;
|
const target = event.detail.target;
|
||||||
if (target.id === 'ratings-table') {
|
if (target.id === 'ratings-table') {
|
||||||
syncSparklineButtons(document.body.dataset.sparklines || 'on');
|
syncSparklineButtons(document.body.dataset.sparklines || 'on');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user