|
220 | 220 | } |
221 | 221 | buildBest(); |
222 | 222 |
|
223 | | -/* Profile tabs — clicking switches panels */ |
| 223 | +/* Profile tabs — clicking switches panels. Each panel carries its own |
| 224 | + * full set of tab buttons, and initial markup pre-renders an `active` |
| 225 | + * class on the tab that matches the panel's profile. We also sync tab |
| 226 | + * active state across every panel on click so the highlight tracks the |
| 227 | + * clicked profile regardless of which panel the user is currently in, |
| 228 | + * instead of relying on the pre-rendered class staying in lockstep. */ |
224 | 229 | w.querySelectorAll('.lb-tab-h2').forEach(function(tab) { |
225 | 230 | tab.addEventListener('click', function() { |
| 231 | + var targetId = tab.dataset.tab; |
226 | 232 | w.querySelectorAll('.lb-panel-h2').forEach(function(p) { p.classList.remove('active'); }); |
227 | | - w.querySelector('.lb-panel-h2[data-panel="' + tab.dataset.tab + '"]').classList.add('active'); |
| 233 | + w.querySelector('.lb-panel-h2[data-panel="' + targetId + '"]').classList.add('active'); |
| 234 | + w.querySelectorAll('.lb-tab-h2').forEach(function(t) { t.classList.remove('active'); }); |
| 235 | + w.querySelectorAll('.lb-tab-h2[data-tab="' + targetId + '"]').forEach(function(t) { |
| 236 | + t.classList.add('active'); |
| 237 | + }); |
228 | 238 | applyFilters_h2(); |
229 | 239 | if (window.dlScheduleUpdate) window.dlScheduleUpdate(); |
230 | 240 | }); |
|
431 | 441 | }); |
432 | 442 | }); |
433 | 443 |
|
| 444 | +/* Type filters — mutually mirrored across every panel's copy so switching |
| 445 | + * profile tabs preserves the current Production/Tuned/Infrastructure/Engine |
| 446 | + * selection. Each panel renders its own set of buttons, so toggling only |
| 447 | + * the clicked element would leave other panels at their pre-rendered |
| 448 | + * default and "reset" the filter on tab switch. */ |
434 | 449 | w.querySelectorAll('.lb-type-filter').forEach(function(btn) { |
435 | 450 | btn.addEventListener('click', function() { |
436 | 451 | var type = btn.dataset.type; |
437 | | - var allBtn = w.querySelector('.lb-type-filter[data-type="all"]'); |
438 | | - var typeButtons = w.querySelectorAll('.lb-type-filter:not([data-type="all"])'); |
| 452 | + var allBtns = w.querySelectorAll('.lb-type-filter[data-type="all"]'); |
439 | 453 | if (type === 'all') { |
440 | | - var allActive = allBtn.classList.contains('active'); |
441 | | - typeButtons.forEach(function(f) { f.classList.toggle('active', !allActive); }); |
442 | | - allBtn.classList.toggle('active', !allActive); |
| 454 | + var allActive = btn.classList.contains('active'); |
| 455 | + w.querySelectorAll('.lb-type-filter').forEach(function(f) { |
| 456 | + f.classList.toggle('active', !allActive); |
| 457 | + }); |
443 | 458 | } else { |
444 | | - btn.classList.toggle('active'); |
445 | | - var allOn = Array.from(typeButtons).every(function(f) { return f.classList.contains('active'); }); |
446 | | - allBtn.classList.toggle('active', allOn); |
447 | | - var anyOn = Array.from(typeButtons).some(function(f) { return f.classList.contains('active'); }); |
448 | | - if (!anyOn) { btn.classList.add('active'); } |
| 459 | + var isNowActive = !btn.classList.contains('active'); |
| 460 | + w.querySelectorAll('.lb-type-filter[data-type="' + type + '"]').forEach(function(f) { |
| 461 | + f.classList.toggle('active', isNowActive); |
| 462 | + }); |
| 463 | + // Recompute whether "All" should show as active by looking at any |
| 464 | + // one panel's buttons (they are all in sync after the toggle above). |
| 465 | + var firstPanel = w.querySelector('.lb-panel-h2') || w; |
| 466 | + var panelTypeBtns = firstPanel.querySelectorAll('.lb-type-filter:not([data-type="all"])'); |
| 467 | + var everyOn = Array.from(panelTypeBtns).every(function(f) { return f.classList.contains('active'); }); |
| 468 | + allBtns.forEach(function(f) { f.classList.toggle('active', everyOn); }); |
| 469 | + // Never allow zero type filters — re-enable the clicked one. |
| 470 | + var anyOn = Array.from(panelTypeBtns).some(function(f) { return f.classList.contains('active'); }); |
| 471 | + if (!anyOn) { |
| 472 | + w.querySelectorAll('.lb-type-filter[data-type="' + type + '"]').forEach(function(f) { |
| 473 | + f.classList.add('active'); |
| 474 | + }); |
| 475 | + } |
449 | 476 | } |
450 | 477 | applyFilters_h2(); |
451 | 478 | if (window.dlScheduleUpdate) window.dlScheduleUpdate(); |
|
0 commit comments