feat: add URL hash routing for RADAR tabs (#newsfeed, #govtracker)
This commit is contained in:
parent
4485940c3c
commit
0f4ce1a5f7
1 changed files with 37 additions and 17 deletions
32
js/radar.js
32
js/radar.js
|
|
@ -359,14 +359,11 @@
|
|||
govtracker: '> .GOV domain intelligence — tracking U.S. government infrastructure registry'
|
||||
};
|
||||
|
||||
document.querySelectorAll('.radar-view-btn').forEach(function(btn) {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
var view = this.dataset.view;
|
||||
|
||||
function switchToView(view) {
|
||||
// Toggle button states
|
||||
document.querySelectorAll('.radar-view-btn').forEach(function(b) { b.classList.remove('active'); });
|
||||
this.classList.add('active');
|
||||
var activeBtn = document.querySelector('.radar-view-btn[data-view="' + view + '"]');
|
||||
if (activeBtn) activeBtn.classList.add('active');
|
||||
|
||||
// Toggle views
|
||||
document.getElementById('viewNewsfeed').classList.toggle('hidden', view !== 'newsfeed');
|
||||
|
|
@ -375,12 +372,35 @@
|
|||
// Update subtitle
|
||||
document.getElementById('radarSubtitle').innerHTML = subtitles[view] || '';
|
||||
|
||||
// Update URL hash without scrolling
|
||||
history.replaceState(null, '', '#' + view);
|
||||
|
||||
// Lazy-load gov tracker data on first switch
|
||||
if (view === 'govtracker' && !GovTracker.loaded) {
|
||||
GovTracker.loadAll();
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelectorAll('.radar-view-btn').forEach(function(btn) {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
switchToView(this.dataset.view);
|
||||
});
|
||||
});
|
||||
|
||||
// Check URL hash on load
|
||||
var hash = window.location.hash.replace('#', '');
|
||||
if (hash === 'govtracker' || hash === 'newsfeed') {
|
||||
switchToView(hash);
|
||||
}
|
||||
|
||||
// Handle browser back/forward
|
||||
window.addEventListener('hashchange', function() {
|
||||
var h = window.location.hash.replace('#', '');
|
||||
if (h === 'govtracker' || h === 'newsfeed') {
|
||||
switchToView(h);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue