|
3500 | 3500 | // else: no auto-route. Picker is visible, graph-area hidden by CSS until first click. |
3501 | 3501 |
|
3502 | 3502 | // ===== Mobile overlay toggles ===== |
3503 | | - // On mobile, overlays are collapsed by CSS. These JS hooks add toggle buttons. |
3504 | | - function isMobile() { return window.matchMedia('(max-width: 768px)').matches; } |
| 3503 | + // On mobile, overlays are collapsed by CSS (@media max-width:768px). |
| 3504 | + // These JS hooks add interactive toggles for the user to expand them. |
3505 | 3505 |
|
3506 | | - // Legend toggle button (top-left on mobile) |
| 3506 | + // Legend toggle button (top-left on mobile, shown/hidden by CSS media query) |
3507 | 3507 | const legendToggle = document.createElement('button'); |
3508 | 3508 | legendToggle.className = 'mobile-toggle-btn'; |
3509 | 3509 | legendToggle.textContent = '☰'; |
3510 | 3510 | legendToggle.title = 'Toggle legend'; |
3511 | | - legendToggle.style.display = 'none'; |
3512 | 3511 | legendToggle.addEventListener('click', () => { |
3513 | 3512 | const legend = document.getElementById('graph-legend'); |
3514 | 3513 | if (legend) legend.classList.toggle('mobile-visible'); |
3515 | 3514 | }); |
3516 | | - document.querySelector('.graph-area').appendChild(legendToggle); |
| 3515 | + const graphAreaEl = document.querySelector('.graph-area'); |
| 3516 | + if (graphAreaEl) graphAreaEl.appendChild(legendToggle); |
3517 | 3517 |
|
3518 | 3518 | // Meta panel: tap to expand stats on mobile |
3519 | 3519 | const meta = document.getElementById('graph-meta'); |
3520 | 3520 | if (meta) { |
3521 | 3521 | meta.addEventListener('click', () => { |
3522 | | - if (isMobile()) meta.classList.toggle('mobile-expanded'); |
3523 | | - }); |
3524 | | - } |
3525 | | - |
3526 | | - // Show/hide the toggle button when graph becomes visible |
3527 | | - const showMobileControls = () => { |
3528 | | - if (isMobile()) { |
3529 | | - legendToggle.style.display = 'flex'; |
3530 | | - } else { |
3531 | | - legendToggle.style.display = 'none'; |
3532 | | - // Reset desktop state |
3533 | | - const legend = document.getElementById('graph-legend'); |
3534 | | - if (legend) legend.classList.remove('mobile-visible'); |
3535 | | - if (meta) meta.classList.remove('mobile-expanded'); |
3536 | | - } |
3537 | | - }; |
3538 | | - |
3539 | | - // Watch for graph visibility changes |
3540 | | - const graphArea = document.querySelector('.graph-area'); |
3541 | | - if (graphArea) { |
3542 | | - const observer = new MutationObserver(() => { |
3543 | | - const legend = document.getElementById('graph-legend'); |
3544 | | - if (legend && legend.style.display !== 'none') showMobileControls(); |
| 3522 | + if (window.matchMedia('(max-width: 768px)').matches) { |
| 3523 | + meta.classList.toggle('mobile-expanded'); |
| 3524 | + } |
3545 | 3525 | }); |
3546 | | - observer.observe(graphArea, { attributes: true, subtree: true, attributeFilter: ['style'] }); |
3547 | 3526 | } |
3548 | | - |
3549 | | - // Also respond to viewport changes (orientation, resize) |
3550 | | - window.addEventListener('resize', showMobileControls); |
3551 | 3527 | })(); |
3552 | 3528 |
|
0 commit comments