|
76 | 76 | } |
77 | 77 |
|
78 | 78 | function openModal() { |
| 79 | + // Always show the selection modal first |
| 80 | + openNoSelectionModal(); |
| 81 | + } |
| 82 | + |
| 83 | + function openCompareModal() { |
79 | 84 | const selected = getSelectedModels(); |
80 | | - if (!selected.length) { |
81 | | - openNoSelectionModal(); |
82 | | - return; |
83 | | - } |
| 85 | + if (!selected.length) return; |
| 86 | + |
| 87 | + closeNoSelectionModal(); |
| 88 | + |
84 | 89 | const modal = document.getElementById('compare-modal'); |
85 | 90 | if (!modal) return; |
86 | 91 |
|
|
99 | 104 | if (!modal) return; |
100 | 105 | modal.classList.add('show'); |
101 | 106 | modal.setAttribute('aria-hidden', 'false'); |
| 107 | + updateCompareSelectedButton(); |
| 108 | + |
| 109 | + // Focus the compare button for Enter key support |
| 110 | + const compareBtn = document.getElementById('compare-selected-btn'); |
| 111 | + if (compareBtn) { |
| 112 | + setTimeout(() => compareBtn.focus(), 50); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + function updateCompareSelectedButton() { |
| 117 | + const selected = getSelectedModels(); |
| 118 | + const btn = document.getElementById('compare-selected-btn'); |
| 119 | + const msg = document.getElementById('no-selection-message'); |
| 120 | + |
| 121 | + if (!btn) return; |
| 122 | + |
| 123 | + if (selected.length > 0) { |
| 124 | + btn.disabled = false; |
| 125 | + btn.classList.remove('button-disabled'); |
| 126 | + if (msg) msg.style.display = 'none'; |
| 127 | + } else { |
| 128 | + btn.disabled = true; |
| 129 | + btn.classList.add('button-disabled'); |
| 130 | + if (msg) msg.style.display = ''; |
| 131 | + } |
102 | 132 | } |
103 | 133 |
|
104 | 134 | function closeNoSelectionModal() { |
|
130 | 160 | }); |
131 | 161 |
|
132 | 162 | closeNoSelectionModal(); |
133 | | - openModal(); |
| 163 | + openCompareModal(); |
134 | 164 | } |
135 | 165 |
|
136 | 166 | function selectTopN(n, openWeightsOnly = false) { |
|
161 | 191 | }); |
162 | 192 |
|
163 | 193 | closeNoSelectionModal(); |
164 | | - openModal(); |
| 194 | + openCompareModal(); |
165 | 195 | } |
166 | 196 |
|
167 | | - function closeModal() { |
| 197 | + function closeCompareModal() { |
168 | 198 | const modal = document.getElementById('compare-modal'); |
169 | 199 | if (!modal) return; |
170 | 200 | modal.classList.remove('show'); |
|
508 | 538 | } |
509 | 539 | }); |
510 | 540 |
|
511 | | - // Open the compare modal |
512 | | - openModal(); |
513 | | - |
514 | | - // Set the chart type |
| 541 | + // Set the chart type before opening modal |
515 | 542 | const chartTypeSelect = document.getElementById('compare-chart-type'); |
516 | 543 | if (chartTypeSelect) { |
517 | 544 | chartTypeSelect.value = chartType; |
518 | 545 | } |
519 | 546 |
|
520 | | - // Render the chart |
521 | | - renderChart(); |
| 547 | + // Open the compare modal directly (bypass selection modal since models are from URL) |
| 548 | + openCompareModal(); |
522 | 549 | }, 300); |
523 | 550 | } |
524 | 551 |
|
|
558 | 585 | const closeEl = e.target && typeof e.target.closest === 'function' ? e.target.closest('[data-close="true"]') : null; |
559 | 586 | if (closeEl) { |
560 | 587 | e.preventDefault(); |
561 | | - closeModal(); |
| 588 | + closeCompareModal(); |
562 | 589 | } |
563 | 590 | }); |
564 | 591 | } |
|
594 | 621 | }); |
595 | 622 | } |
596 | 623 |
|
597 | | - // Quickselect button handler |
| 624 | + // Quickselect button handler (in compare modal, opens selection modal) |
598 | 625 | const quickselectBtn = document.getElementById('quickselect-btn'); |
599 | 626 | if (quickselectBtn) { |
600 | 627 | quickselectBtn.addEventListener('click', (e) => { |
601 | 628 | e.preventDefault(); |
602 | | - closeModal(); |
| 629 | + closeCompareModal(); |
603 | 630 | openNoSelectionModal(); |
604 | 631 | }); |
605 | 632 | } |
|
641 | 668 | closeNoSelectionModal(); |
642 | 669 | } |
643 | 670 | }); |
| 671 | + |
| 672 | + // Handle Enter key to trigger compare button |
| 673 | + noSelectionModal.addEventListener('keydown', (e) => { |
| 674 | + if (e.key === 'Enter') { |
| 675 | + const btn = document.getElementById('compare-selected-btn'); |
| 676 | + if (btn && !btn.disabled) { |
| 677 | + e.preventDefault(); |
| 678 | + openCompareModal(); |
| 679 | + } |
| 680 | + } |
| 681 | + }); |
| 682 | + } |
| 683 | + |
| 684 | + // Compare selected models button |
| 685 | + const compareSelectedBtn = document.getElementById('compare-selected-btn'); |
| 686 | + if (compareSelectedBtn) { |
| 687 | + compareSelectedBtn.addEventListener('click', (e) => { |
| 688 | + e.preventDefault(); |
| 689 | + openCompareModal(); |
| 690 | + }); |
644 | 691 | } |
645 | 692 |
|
646 | 693 | // Quick select buttons |
|
666 | 713 |
|
667 | 714 | document.addEventListener('change', (e) => { |
668 | 715 | if (e.target && e.target.classList.contains('row-select')) { |
| 716 | + // Update chart if compare modal is open |
669 | 717 | if (document.getElementById('compare-modal')?.classList.contains('show')) { |
670 | 718 | renderChart(); |
671 | 719 | } |
| 720 | + // Update button state if selection modal is open |
| 721 | + if (document.getElementById('no-selection-modal')?.classList.contains('show')) { |
| 722 | + updateCompareSelectedButton(); |
| 723 | + } |
672 | 724 | } |
673 | 725 | }); |
674 | 726 |
|
|
0 commit comments