class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Add scroll effect
const navbar = this.shadowRoot.querySelector('.navbar');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});
// Mobile menu toggle
const mobileMenuButton = this.shadowRoot.getElementById('mobile-menu-button');
const mobileMenu = this.shadowRoot.getElementById('mobile-menu');
mobileMenuButton.addEventListener('click', () => {
mobileMenu.classList.toggle('open');
const icon = mobileMenuButton.querySelector('i');
if (mobileMenu.classList.contains('open')) {
icon.setAttribute('data-feather', 'x');
} else {
icon.setAttribute('data-feather', 'menu');
}
feather.replace();
});
// Highlight active link
const currentPath = window.location.pathname.split('/').pop() || 'index.html';
const links = this.shadowRoot.querySelectorAll('.nav-link');
links.forEach(link => {
const linkPath = link.getAttribute('href');
if (currentPath === linkPath) {
link.classList.add('active-link');
}
});
}
}
customElements.define('custom-navbar', CustomNavbar);