fix: language selector now works on all pages
- Added 'navbarReady' event dispatch from navbar after rendering - Language selector now waits for navbar container to exist - Fixes race condition where language selector ran before navbar rendered - Language toggle now functional on researcher, implementer, leader, about pages
This commit is contained in:
parent
ef954d6e49
commit
34e70a1b44
2 changed files with 17 additions and 4 deletions
|
|
@ -67,11 +67,21 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize when DOM is ready
|
// Initialize when navbar is ready (not just DOM ready)
|
||||||
|
function initWhenReady() {
|
||||||
|
// Check if navbar container exists
|
||||||
|
if (document.getElementById('language-selector-container')) {
|
||||||
|
createLanguageSelector();
|
||||||
|
} else {
|
||||||
|
// Wait for navbar to signal it's ready
|
||||||
|
window.addEventListener('navbarReady', createLanguageSelector, { once: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', createLanguageSelector);
|
document.addEventListener('DOMContentLoaded', initWhenReady);
|
||||||
} else {
|
} else {
|
||||||
createLanguageSelector();
|
initWhenReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-initialize when language changes (to update active state)
|
// Re-initialize when language changes (to update active state)
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,14 @@ class TractatusNavbar {
|
||||||
this.render();
|
this.render();
|
||||||
this.attachEventListeners();
|
this.attachEventListeners();
|
||||||
this.setActivePageIndicator();
|
this.setActivePageIndicator();
|
||||||
|
|
||||||
|
// Dispatch event to signal navbar is ready
|
||||||
|
window.dispatchEvent(new CustomEvent('navbarReady'));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const navHTML = `
|
const navHTML = `
|
||||||
<nav class="bg-white border-b border-gray-200 sticky top-0 z-50 shadow-sm">
|
<nav class="bg-white border-b border-gray-200 sticky top-0 z-50 shadow-sm" id="tractatus-navbar">
|
||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
<div class="flex justify-between h-16">
|
<div class="flex justify-between h-16">
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue