-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (45 loc) · 1.97 KB
/
script.js
File metadata and controls
51 lines (45 loc) · 1.97 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
50
51
// Interações leves
const yearEl = document.getElementById('year');
if (yearEl) yearEl.textContent = new Date().getFullYear();
// Menu mobile
const toggle = document.querySelector('.nav-toggle');
const nav = document.getElementById('site-nav');
toggle?.addEventListener('click', () => {
const open = nav.classList.toggle('open');
toggle.setAttribute('aria-expanded', String(open));
});
// Newsletter fake submit
document.getElementById('newsletter')?.addEventListener('submit', (e) => {
const status = document.getElementById('form-status');
status.textContent = 'Obrigado! Em breve enviaremos novidades.';
});
// Vídeo modal (lazy embed YouTube)
const modal = document.getElementById('video-modal');
const modalClose = modal?.querySelector('.modal__close');
const videoContainer = document.getElementById('video-container');
function openVideo(id){
if(!modal || !videoContainer) return;
modal.setAttribute('aria-hidden','false');
videoContainer.innerHTML = `<iframe width="100%" height="100%" src="https://www.youtube.com/embed/${id}?autoplay=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" referrerpolicy="no-referrer-when-downgrade" allowfullscreen></iframe>`;
}
function closeVideo(){
if(!modal || !videoContainer) return;
modal.setAttribute('aria-hidden','true');
videoContainer.innerHTML = '';
}
modalClose?.addEventListener('click', closeVideo);
modal?.addEventListener('click', (e) => { if(e.target === modal) closeVideo(); });
document.querySelectorAll('.video-card').forEach(btn => {
btn.addEventListener('click', () => openVideo(btn.dataset.video));
});
// Acessibilidade extra: smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(a => {
a.addEventListener('click', e => {
const id = a.getAttribute('href');
const target = document.querySelector(id);
if(target){
e.preventDefault();
target.scrollIntoView({behavior:'smooth'});
}
});
});