In header.html:

Added IDs to navigation links
Added script to hide expertise and contact links on non-index pages
Kept the Start link visible on all pages to return to homepage
In components.js:

Fixed the COMPONENTS_LOADED_EVENT declaration to prevent duplicate declaration error
Added condition to only enable scroll behavior on index page
Kept component loading logic but made it more robust
This commit is contained in:
ben7sys
2024-11-15 12:09:23 +01:00
parent 944c7efeaf
commit 4f9e817d61
2 changed files with 40 additions and 31 deletions

View File

@@ -7,9 +7,9 @@
</div>
<nav class="nav-menu">
<a href="#intro">Start</a>
<a href="#services">Expertise</a>
<a href="#contact">Kontakt</a>
<a href="/" id="start-link">Start</a>
<a href="/#services" id="expertise-link">Expertise</a>
<a href="/#contact" id="contact-link">Kontakt</a>
<button class="theme-toggle" aria-label="Theme Toggle">
<i class="fas fa-moon"></i>
</button>
@@ -19,4 +19,11 @@
<i class="fas fa-bars"></i>
</button>
</div>
<script>
// Hide expertise and contact links on non-index pages
if (window.location.pathname !== '/' && window.location.pathname !== '/index.html') {
document.getElementById('expertise-link').style.display = 'none';
document.getElementById('contact-link').style.display = 'none';
}
</script>
</header>

View File

@@ -1,5 +1,5 @@
// Custom event for when components are fully loaded
const COMPONENTS_LOADED_EVENT = 'componentsLoaded';
const COMPONENTS_LOADED_EVENT = new Event('componentsLoaded');
document.addEventListener('DOMContentLoaded', function() {
// Helper function to handle component loading
@@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', function() {
]).then(results => {
if (results.every(Boolean)) {
// Dispatch custom event when all components are loaded
document.dispatchEvent(new CustomEvent(COMPONENTS_LOADED_EVENT));
document.dispatchEvent(COMPONENTS_LOADED_EVENT);
}
}).catch(error => {
console.warn('Error loading components:', error);
@@ -68,7 +68,8 @@ document.addEventListener('DOMContentLoaded', function() {
});
}
// Scroll behavior
// Scroll behavior - only enable on index page
if (window.location.pathname === '/' || window.location.pathname === '/index.html') {
let lastScrollTop = 0;
let scrollTimeout;
@@ -97,4 +98,5 @@ document.addEventListener('DOMContentLoaded', function() {
});
}, { passive: true });
}
}
});