-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
49 lines (40 loc) · 1.65 KB
/
main.js
File metadata and controls
49 lines (40 loc) · 1.65 KB
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
function initMenuMobile() {
const btnMenu = document.getElementById('btn-menu');
const menu = document.getElementById('menu-mobile');
const overlay = document.getElementById('overlay-menu');
if (btnMenu && menu && overlay) {
btnMenu.addEventListener('click', () => menu.classList.add('abrir-menu'));
menu.addEventListener('click', () => menu.classList.remove('abrir-menu'));
overlay.addEventListener('click', () => menu.classList.remove('abrir-menu'));
}
}
function initThemeToggle() {
const themeToggle = document.getElementById('theme-toggle');
if (!themeToggle) return;
const themeIcon = themeToggle.querySelector('i');
function updateTheme(isLight) {
document.documentElement.classList.toggle('light-mode', isLight);
themeIcon.className = isLight ? 'fa-solid fa-sun' : 'fa-solid fa-moon';
}
themeToggle.addEventListener('click', () => {
const isLight = document.documentElement.classList.toggle('light-mode');
localStorage.setItem('theme', isLight ? 'light' : 'dark');
updateTheme(isLight);
});
const currentTheme = localStorage.getItem('theme') || 'dark';
updateTheme(currentTheme === 'light');
}
function initActiveNavLinks() {
const links = document.querySelectorAll('.menu-desktop ul li a');
const currentPath = window.location.pathname.split('/').pop() || 'index.html';
links.forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
}
document.addEventListener('DOMContentLoaded', () => {
initMenuMobile();
initThemeToggle();
initActiveNavLinks();
});