File size: 2,228 Bytes
73e2719 4af909c 89b908c 4af909c 89b908c 4af909c 89b908c 4dab223 89b908c 4dab223 89b908c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
// Handle navigation for all links
document.querySelectorAll('a').forEach(anchor => {
// Skip if it's an external link or has a different protocol
if (anchor.href && anchor.href.startsWith(window.location.origin)) {
anchor.addEventListener('click', function(e) {
// Only prevent default for anchor links
if (this.getAttribute('href').startsWith('#')) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
}
// Allow normal navigation for other internal links
});
}
});
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Intersection Observer for animations
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('animate-fadeIn');
observer.unobserve(entry.target);
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -100px 0px'
});
document.querySelectorAll('[class*="animate-"]').forEach(el => {
observer.observe(el);
});
// Better mobile menu toggle (for future implementation)
function setupMobileMenu() {
const menuButton = document.querySelector('[aria-controls="mobile-menu"]');
if (menuButton) {
const menu = document.getElementById('mobile-menu');
menuButton.addEventListener('click', () => {
const expanded = menuButton.getAttribute('aria-expanded') === 'true';
menuButton.setAttribute('aria-expanded', !expanded);
menu.classList.toggle('hidden');
});
}
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
setupMobileMenu();
// Replace icons in main document
feather.replace();
// Replace icons in any existing custom elements
document.querySelectorAll('custom-navbar, custom-footer').forEach(el => {
if (el.shadowRoot) {
const icons = el.shadowRoot.querySelectorAll('[data-feather]');
icons.forEach(icon => {
feather.replace(icon);
});
}
});
});
|