mbmal's picture
мне нужен портал проекта Технозаметки Малышева (канал в телеграме @tsingular)
29e58e3 verified
raw
history blame
6.77 kB
class CustomNavbar extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.render();
this.setupEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
width: 100%;
}
.navbar {
background: rgba(10, 10, 15, 0.95);
backdrop-filter: blur(10px);
border-bottom: 1px solid #00ff88;
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
}
.nav-container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.nav-brand {
display: flex;
align-items: center;
gap: 0.5rem;
text-decoration: none;
font-family: Orbitron, monospace;
font-weight: 700;
font-size: 1.25rem;
background: linear-gradient(45deg, #00ff88, #00a2ff);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.nav-menu {
display: flex;
gap: 2rem;
align-items: center;
}
.nav-link {
color: #e2e8f0;
text-decoration: none;
font-weight: 500;
transition: all 0.3s ease;
position: relative;
}
.nav-link:hover {
color: #00ff88;
}
.nav-link.active {
color: #00ff88;
}
.nav-link.active::after {
content: '';
position: absolute;
bottom: -8px;
left: 0;
width: 100%;
height: 2px;
background: #00ff88;
box-shadow: 0 0 8px #00ff88;
}
.mobile-menu-button {
display: none;
background: none;
border: none;
color: #00ff88;
cursor: pointer;
}
@media (max-width: 768px) {
.nav-menu {
position: absolute;
top: 100%;
left: 0;
right: 0;
background: rgba(10, 10, 15, 0.95);
flex-direction: column;
padding: 1rem;
gap: 1rem;
display: none;
}
.nav-menu.active {
display: flex;
}
.mobile-menu-button {
display: block;
}
}
</style>
<nav class="navbar">
<div class="nav-container">
<a href="/" class="nav-brand">
<i data-feather="cpu"></i>
SINGULARITY
</a>
<button class="mobile-menu-button">
<i data-feather="menu"></i>
</button>
<div class="nav-menu">
<a href="/news" class="nav-link">
<i data-feather="zap" class="inline mr-1"></i>
Новости
</a>
<a href="/learning" class="nav-link">
<i data-feather="book-open" class="inline mr-1"></i>
Обучение
</a>
<a href="/resources" class="nav-link">
<i data-feather="link" class="inline mr-1"></i>
Ресурсы
</a>
<a href="/talks" class="nav-link">
<i data-feather="video" class="inline mr-1"></i>
Доклады
</a>
<a href="/demos" class="nav-link">
<i data-feather="code" class="inline mr-1"></i>
Демо
</a>
<a href="/admin" class="nav-link" data-auth="admin">
<i data-feather="settings" class="inline mr-1"></i>
Управление
</a>
</div>
</div>
</nav>
`;
// Replace feather icons after rendering
setTimeout(() => {
if (typeof feather !== 'undefined') {
feather.replace();
}
}, 100);
}
setupEventListeners() {
const mobileButton = this.shadowRoot.querySelector('.mobile-menu-button');
const navMenu = this.shadowRoot.querySelector('.nav-menu');
if (mobileButton) {
mobileButton.addEventListener('click', () => {
navMenu.classList.toggle('active');
mobileButton.innerHTML = navMenu.classList.contains('active') ?
'<i data-feather="x"></i>' :
'<i data-feather="menu"></i>';
feather.replace();
});
}
// Close mobile menu when clicking outside
document.addEventListener('click', (event) => {
if (!this.contains(event.target) && navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
mobileButton.innerHTML = '<i data-feather="menu"></i>';
feather.replace();
}
});
}
}
}
customElements.define('custom-navbar', CustomNavbar);