Skip to content

Commit 8a5b548

Browse files
committed
slot: preserve active tab when navigating between slots
Carry the URL hash forward on the prev/next chevrons so e.g. /slot/35#ptcVotes -> next chevron -> /slot/36#ptcVotes lands on the same tab. The chevron href is rewritten on page load, hashchange, and tab switches, so regular, middle, and cmd+click all preserve the tab.
1 parent 5280da3 commit 8a5b548

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

templates/slot/slot.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<div class="d-md-flex py-2 justify-content-md-between">
44
<h1 class="h4 my-2 mb-md-0 h1-pager">
55
{{- if not (eq .Slot 0) -}}
6-
<a href="/slot/{{ .PreviousSlot }}"><i class="fa fa-chevron-left"></i></a>
6+
<a href="/slot/{{ .PreviousSlot }}" class="slot-nav-link" data-slot-nav-base="/slot/{{ .PreviousSlot }}"><i class="fa fa-chevron-left"></i></a>
77
{{- else -}}
88
<a></a>
99
{{- end -}}
1010
<span><i class="fas fa-cube mx-2"></i>Slot <span id="slot">{{ .Slot }}</span></span>
1111
{{- if gt .NextSlot 0 -}}
12-
<a href="/slot/{{ .NextSlot }}"><i class="fa fa-chevron-right"></i></a>
12+
<a href="/slot/{{ .NextSlot }}" class="slot-nav-link" data-slot-nav-base="/slot/{{ .NextSlot }}"><i class="fa fa-chevron-right"></i></a>
1313
{{- else -}}
1414
<a></a>
1515
{{- end -}}
@@ -455,15 +455,28 @@ <h5 class="mb-3"><i class="fas fa-project-diagram me-2"></i>Tracoor Traces</h5>
455455
if (target.length) target.tab('show');
456456
}
457457

458+
function syncSlotNavHashes() {
459+
var hash = window.location.hash || '';
460+
$('.slot-nav-link').each(function() {
461+
var base = this.getAttribute('data-slot-nav-base') || this.getAttribute('href');
462+
this.setAttribute('href', base + hash);
463+
});
464+
}
465+
458466
activateTabByHash();
459-
window.addEventListener('hashchange', activateTabByHash);
467+
syncSlotNavHashes();
468+
window.addEventListener('hashchange', function() {
469+
activateTabByHash();
470+
syncSlotNavHashes();
471+
});
460472

461473
$('.nav-tabs a[data-bs-toggle="tab"]').on('shown.bs.tab', function(e) {
462474
var href = e.target.getAttribute('href') || '';
463475
if (!href.startsWith('#')) return;
464476
var newHash = href === '#overview' ? '' : href;
465477
if (window.location.hash !== newHash) {
466478
window.history.replaceState(null, document.title, window.location.pathname + window.location.search + newHash);
479+
syncSlotNavHashes();
467480
}
468481
});
469482

0 commit comments

Comments
 (0)