-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (83 loc) · 2.73 KB
/
Copy pathscript.js
File metadata and controls
104 lines (83 loc) · 2.73 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
/* =========================
VALIDACIÓN DEL FORMULARIO
========================= */
const form = document.getElementById('contact-form');
const nombreInput = document.getElementById('nombre');
const emailInput = document.getElementById('email');
const mensajeInput = document.getElementById('mensaje');
const feedback = document.getElementById('form-feedback');
function validarFormulario() {
// Limpiar feedback anterior
feedback.textContent = '';
feedback.className = 'form-feedback';
// Obtener valores (trim elimina espacios al inicio/final)
const nombre = nombreInput.value.trim();
const email = emailInput.value.trim();
const mensaje = mensajeInput.value.trim();
// Validar campos vacíos
if (nombre === '') {
mostrarError('Por favor ingresa tu nombre');
nombreInput.focus();
return false;
}
if (email === '') {
mostrarError('Por favor ingresa tu email');
emailInput.focus();
return false;
}
// Validar formato de email
if (!validarEmail(email)) {
mostrarError('Por favor ingresa un email válido');
emailInput.focus();
return false;
}
if (mensaje === '') {
mostrarError('Por favor escribe un mensaje');
mensajeInput.focus();
return false;
}
// Todo válido
mostrarExito('¡Mensaje enviado correctamente! Gracias, ' + nombre);
form.reset();
return true;
}
function validarEmail(email) {
// Verifica que tenga @ y un punto después del @
const arroba = email.indexOf('@');
const punto = email.lastIndexOf('.');
return arroba > 0 && punto > arroba + 1 && punto < email.length - 1;
}
function mostrarError(mensaje) {
feedback.textContent = mensaje;
feedback.className = 'form-feedback error';
}
function mostrarExito(mensaje) {
feedback.textContent = mensaje;
feedback.className = 'form-feedback success';
}
form.addEventListener('submit', (evento) => {
evento.preventDefault();
validarFormulario();
});
const navToggle = document.querySelector('.nav-toggle');
const navLinks = document.querySelector('.nav-links');
function toggleMenu() {
navLinks.classList.toggle('active');
// Cambiar icono del botón
if (navLinks.classList.contains('active')) {
navToggle.textContent = '✕';
} else {
navToggle.textContent = '☰';
}
}
navToggle.addEventListener('click', toggleMenu);
// Cerrar menú al hacer clic en un enlace
const navItems = document.querySelectorAll('.nav-links a');
//
navItems = [About, Skills, Projects, Contacto]
navItems.forEach(function (enlace) {
enlace.addEventListener('click', function () {
navLinks.classList.remove('active');
navToggle.textContent = '☰';
});
});