-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
426 lines (357 loc) · 14.5 KB
/
scripts.js
File metadata and controls
426 lines (357 loc) · 14.5 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/**
* ========================================
* PORTFÓLIO PESSOAL - JAVASCRIPT
* ========================================
* Script principal para gerenciar a navegação e interações
* Autor: Célio Marcos Moreira Santiago - UNINTER
* Versão: 1.0
*/
// Aguarda o carregamento completo do DOM antes de executar
document.addEventListener('DOMContentLoaded', function() {
// ========================================
// SELEÇÃO DE ELEMENTOS DO DOM
// ========================================
const navLinks = document.querySelectorAll('.nav-link');
const contentSections = document.querySelectorAll('.content-section');
const header = document.querySelector('.main-header');
const submitButton = document.querySelector('.submit-button');
const contactForm = document.querySelector('.contact-form');
// ========================================
// NAVEGAÇÃO ENTRE SEÇÕES
// ========================================
/**
* Esconde todas as seções e remove a classe 'active' dos links
*/
function hideAllSections() {
contentSections.forEach(section => {
section.classList.remove('active');
});
navLinks.forEach(link => {
link.classList.remove('active');
});
}
/**
* Mostra a seção especificada e marca o link como ativo
* @param {string} sectionId - ID da seção a ser exibida
*/
function showSection(sectionId) {
hideAllSections();
// Encontra e ativa a seção
const targetSection = document.querySelector(sectionId);
if (targetSection) {
targetSection.classList.add('active');
// Marca o link correspondente como ativo
const targetLink = document.querySelector(`a[href="${sectionId}"]`);
if (targetLink) {
targetLink.classList.add('active');
}
// Rola suavemente até o topo da seção
window.scrollTo({
top: 0,
behavior: 'smooth'
});
}
}
// Adiciona evento de clique em cada link de navegação
navLinks.forEach(link => {
link.addEventListener('click', function(event) {
event.preventDefault();
const targetId = this.getAttribute('href');
showSection(targetId);
// Salva a seção atual no localStorage
localStorage.setItem('currentSection', targetId);
});
});
// ========================================
// PERSISTÊNCIA DE NAVEGAÇÃO
// ========================================
/**
* Restaura a última seção visitada ao recarregar a página
*/
function restoreLastSection() {
const lastSection = localStorage.getItem('currentSection');
if (lastSection) {
showSection(lastSection);
} else {
// Se não houver seção salva, mostra "Sobre Mim"
showSection('#sobre');
}
}
// Restaura a última seção visitada
restoreLastSection();
// ========================================
// EFEITO DE SCROLL NO HEADER
// ========================================
/**
* Adiciona sombra ao header quando a página é rolada
*/
let lastScrollTop = 0;
window.addEventListener('scroll', function() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// Adiciona ou remove classe baseado no scroll
if (scrollTop > 50) {
header.style.boxShadow = '0 4px 20px rgba(0, 0, 0, 0.3)';
} else {
header.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
}
lastScrollTop = scrollTop;
});
// ========================================
// VALIDAÇÃO E ENVIO DO FORMULÁRIO
// ========================================
/**
* Manipula o envio do formulário com Formspree
*/
const form = document.getElementById('contact-form');
const formStatus = document.getElementById('form-status');
const submitBtn = document.getElementById('submit-button');
if (form) {
async function handleSubmit(event) {
event.preventDefault();
// Obtém os valores dos campos para validação
const nome = document.getElementById('nome').value.trim();
const email = document.getElementById('email').value.trim();
const mensagem = document.getElementById('mensagem').value.trim();
// Validação básica
if (nome.length < 3) {
showFormMessage('Por favor, insira um nome válido (mínimo 3 caracteres).', 'error');
return;
}
if (!isValidEmail(email)) {
showFormMessage('Por favor, insira um email válido.', 'error');
return;
}
if (mensagem.length < 10) {
showFormMessage('Por favor, escreva uma mensagem mais detalhada (mínimo 10 caracteres).', 'error');
return;
}
// Mostra estado de envio
submitBtn.disabled = true;
submitBtn.textContent = 'Enviando...';
submitBtn.classList.add('sending');
// Envia o formulário
const data = new FormData(event.target);
try {
const response = await fetch(event.target.action, {
method: form.method,
body: data,
headers: {
'Accept': 'application/json'
}
});
if (response.ok) {
// Sucesso
showFormMessage('✅ Mensagem enviada com sucesso! Entrarei em contato em breve.', 'success');
form.reset();
// Efeito de sucesso
form.classList.add('form-success');
setTimeout(() => {
form.classList.remove('form-success');
}, 1000);
} else {
// Erro no servidor
const errorData = await response.json();
if (errorData.errors) {
const errorMessages = errorData.errors.map(error => error.message).join(', ');
showFormMessage(`❌ Erro: ${errorMessages}`, 'error');
} else {
showFormMessage('❌ Oops! Houve um problema ao enviar sua mensagem. Tente novamente.', 'error');
}
}
} catch (error) {
// Erro de rede
showFormMessage('❌ Erro de conexão. Verifique sua internet e tente novamente.', 'error');
console.error('Erro ao enviar formulário:', error);
} finally {
// Restaura o botão
submitBtn.disabled = false;
submitBtn.textContent = 'Enviar Mensagem';
submitBtn.classList.remove('sending');
}
}
// Adiciona o listener do formulário
form.addEventListener('submit', handleSubmit);
}
/**
* Exibe mensagem de status do formulário
* @param {string} message - Mensagem a ser exibida
* @param {string} type - Tipo da mensagem (success, error)
*/
function showFormMessage(message, type) {
formStatus.textContent = message;
formStatus.className = `form-status ${type}`;
formStatus.style.display = 'block';
// Remove a mensagem após 5 segundos se for sucesso
if (type === 'success') {
setTimeout(() => {
formStatus.style.display = 'none';
}, 5000);
}
}
/**
* Valida formato de email
* @param {string} email - Email a ser validado
* @returns {boolean} - True se o email for válido
*/
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// ========================================
// ANIMAÇÕES E INTERAÇÕES
// ========================================
/**
* Anima as barras de nível de idiomas quando visíveis
*/
function animateLanguageBars() {
const languageBars = document.querySelectorAll('.level-fill');
languageBars.forEach(bar => {
// Salva a largura original
const width = bar.style.width;
// Reset a largura para 0
bar.style.width = '0';
// Anima após um pequeno delay
setTimeout(() => {
bar.style.width = width;
}, 300);
});
}
// Anima as barras quando a seção de formação é exibida
document.querySelector('a[href="#formacao"]').addEventListener('click', function() {
setTimeout(animateLanguageBars, 100);
});
// ========================================
// EFEITOS VISUAIS NOS PROJETOS
// ========================================
/**
* Adiciona efeito de parallax aos ícones dos projetos
*/
const projectIcons = document.querySelectorAll('.project-icon');
projectIcons.forEach(icon => {
icon.addEventListener('mousemove', function(e) {
const rect = this.getBoundingClientRect();
const x = e.clientX - rect.left;
const y = e.clientY - rect.top;
const centerX = rect.width / 2;
const centerY = rect.height / 2;
const deltaX = (x - centerX) / centerX;
const deltaY = (y - centerY) / centerY;
this.style.transform = `
perspective(1000px)
rotateY(${deltaX * 10}deg)
rotateX(${-deltaY * 10}deg)
scale(1.1)
`;
});
icon.addEventListener('mouseleave', function() {
this.style.transform = 'perspective(1000px) rotateY(0) rotateX(0) scale(1)';
});
});
// ========================================
// LAZY LOADING DE IMAGENS
// ========================================
/**
* Implementa lazy loading para otimizar carregamento
*/
const lazyImages = document.querySelectorAll('img[data-src]');
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.removeAttribute('data-src');
imageObserver.unobserve(img);
}
});
});
lazyImages.forEach(img => imageObserver.observe(img));
}
// ========================================
// MODO ESCURO (PREPARAÇÃO FUTURA)
// ========================================
/**
* Preparação para implementação de modo escuro
* Atualmente o site já usa tema escuro por padrão
*/
function toggleDarkMode() {
document.body.classList.toggle('light-mode');
const isDarkMode = !document.body.classList.contains('light-mode');
localStorage.setItem('darkMode', isDarkMode);
}
// ========================================
// ACESSIBILIDADE
// ========================================
/**
* Melhora a navegação por teclado
*/
document.addEventListener('keydown', function(e) {
// Navegação por setas entre seções
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
const activeLink = document.querySelector('.nav-link.active');
const allLinks = Array.from(navLinks);
const currentIndex = allLinks.indexOf(activeLink);
let newIndex;
if (e.key === 'ArrowRight') {
newIndex = (currentIndex + 1) % allLinks.length;
} else {
newIndex = (currentIndex - 1 + allLinks.length) % allLinks.length;
}
allLinks[newIndex].click();
}
// Tecla ESC fecha formulários ou modais
if (e.key === 'Escape') {
// Implementar fechamento de modais futuros
}
});
// ========================================
// MENSAGENS DE FEEDBACK
// ========================================
/**
* Exibe mensagens de feedback ao usuário
* @param {string} message - Mensagem a ser exibida
* @param {string} type - Tipo da mensagem (success, error, info)
*/
function showMessage(message, type = 'info') {
const messageDiv = document.createElement('div');
messageDiv.className = `feedback-message ${type}`;
messageDiv.textContent = message;
document.body.appendChild(messageDiv);
// Remove a mensagem após 3 segundos
setTimeout(() => {
messageDiv.remove();
}, 3000);
}
// ========================================
// PERFORMANCE
// ========================================
/**
* Debounce para otimizar eventos de scroll e resize
*/
function debounce(func, wait) {
let timeout;
return function executedFunction(...args) {
const later = () => {
clearTimeout(timeout);
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
}
// Otimiza eventos de redimensionamento
const optimizedResize = debounce(() => {
// Código para lidar com redimensionamento
console.log('Janela redimensionada');
}, 250);
window.addEventListener('resize', optimizedResize);
// ========================================
// CONSOLE EASTER EGG
// ========================================
console.log('%c🚀 Bem-vindo ao meu portfólio!',
'font-size: 20px; color: #2563eb; font-weight: bold;');
console.log('%c💻 Desenvolvido com HTML, CSS e JavaScript puro',
'font-size: 14px; color: #10b981;');
console.log('%c📧 Entre em contato: celiomarcos@gmail.com',
'font-size: 14px; color: #94a3b8;');
});