-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
206 lines (167 loc) · 7.53 KB
/
Copy pathscript.js
File metadata and controls
206 lines (167 loc) · 7.53 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
window.addEventListener('scroll', onScroll)
onScroll()
function onScroll() {
showNavOnScroll()
showButtonWhatsappOnScroll()
}
function showNavOnScroll() {
if(scrollY > 0) {
document.querySelector("#navigation").classList.add("scroll")
} else {
document.querySelector("#navigation").classList.remove("scroll")
}
}
function showButtonWhatsappOnScroll() {
if(scrollY > 200) {
document.querySelector("#buttonWhatsapp").classList.add("show")
} else {
document.querySelector("#buttonWhatsapp").classList.remove("show")
}
}
function openMenu() {
document.body.classList.add('menu-expanded')
}
function closeMenu() {
document.body.classList.remove('menu-expanded')
}
// Función para verificar la visibilidad de las secciones
function checkServicesSectionsVisibility() {
const servicesSection = document.getElementById('services');
const servicesDeskSection = document.getElementById('servicesDesktop');
console.log('=== DIAGNÓSTICO DE SECCIONES DE SERVICIOS ===');
if (servicesSection) {
const servicesDisplay = window.getComputedStyle(servicesSection).display;
console.log('Sección móvil (#services):',
'Existe:', !!servicesSection,
'Estilo display:', servicesDisplay,
'Visible:', servicesDisplay !== 'none');
} else {
console.error('¡Sección #services no encontrada!');
}
if (servicesDeskSection) {
const deskDisplay = window.getComputedStyle(servicesDeskSection).display;
console.log('Sección escritorio (#servicesDesktop):',
'Existe:', !!servicesDeskSection,
'Estilo display:', deskDisplay,
'Visible:', deskDisplay !== 'none');
} else {
console.error('¡Sección #servicesDesktop no encontrada!');
}
console.log('Ancho de ventana actual:', window.innerWidth);
console.log('Debería mostrar:', window.innerWidth < 1080 ? '#services' : '#servicesDesktop');
console.log('=== FIN DE DIAGNÓSTICO ===');
}
// Función para asegurar la visibilidad de la imagen principal
function checkMainImageVisibility() {
const mainImage = document.getElementById('interactive-image');
if (mainImage) {
// Asegurar que la imagen tenga display block y sea visible
mainImage.style.display = 'block';
mainImage.style.opacity = '1';
// Asegurar que la imagen dentro del contenedor también sea visible
const imageElement = mainImage.querySelector('img');
if (imageElement) {
imageElement.style.display = 'block';
imageElement.style.width = '100%';
imageElement.style.height = '100%';
imageElement.style.objectFit = 'cover';
}
console.log('Visibilidad de imagen principal ajustada');
}
}
// Manejador unificado para todos los eventos DOM ready
document.addEventListener('DOMContentLoaded', function() {
console.log('DOM cargado - iniciando configuración de enlaces');
// Verificar y ajustar visibilidad de la imagen principal
checkMainImageVisibility();
// Ejecutar diagnóstico inicial
checkServicesSectionsVisibility();
// Verificar después de un tiempo para permitir que los estilos se apliquen
setTimeout(checkServicesSectionsVisibility, 500);
// Configuración específica para el botón principal de servicios
const mainServiceButton = document.getElementById('main-service-button');
if (mainServiceButton) {
console.log('Configurando botón principal de servicios');
// Eliminar atributos onclick existentes
mainServiceButton.removeAttribute('onclick');
// Añadir event listener directamente
mainServiceButton.addEventListener('click', function(e) {
e.preventDefault();
console.log('Clic en botón principal de servicios');
// Usar el mismo breakpoint que en CSS: 1080px
const targetId = window.innerWidth < 1080 ? 'services' : 'servicesDesktop';
console.log('Redirigiendo a:', targetId, 'Ancho de pantalla:', window.innerWidth);
// Verificar si la sección existe y es visible
const targetSection = document.getElementById(targetId);
if (targetSection) {
const isVisible = window.getComputedStyle(targetSection).display !== 'none';
console.log('Sección target:', targetId, 'Existe:', !!targetSection, 'Visible:', isVisible);
if (!isVisible) {
console.warn('¡La sección destino no es visible! Intentando hacer visible...');
targetSection.style.display = 'block';
}
}
// Cerrar el menú si está abierto
closeMenu();
// Navegar a la sección correcta
setTimeout(function() {
const element = document.getElementById(targetId);
if (element) {
console.log('Elemento encontrado, desplazando a la vista');
element.scrollIntoView({ behavior: 'smooth' });
window.location.hash = targetId;
} else {
console.error('Sección de servicios no encontrada:', targetId);
}
}, 300); // Incrementamos más el retraso
});
} else {
console.error('¡Botón principal de servicios no encontrado!');
}
// Eliminar todos los onclick existentes en los enlaces de servicios
document.querySelectorAll('.services-link').forEach(function(link) {
// Saltar el botón principal que ya configuramos
if (link.id === 'main-service-button') return;
console.log('Configurando enlace de servicio:', link);
// Eliminar atributos onclick existentes
link.removeAttribute('onclick');
// Eliminar cualquier evento click existente
const newLink = link.cloneNode(true);
link.parentNode.replaceChild(newLink, link);
// Añadir event listener directamente al enlace
newLink.addEventListener('click', function(e) {
e.preventDefault();
console.log('Clic en enlace de servicio');
// Usar el mismo breakpoint que en CSS: 1080px
const targetId = window.innerWidth < 1080 ? 'services' : 'servicesDesktop';
console.log('Redirigiendo a:', targetId, 'Ancho de pantalla:', window.innerWidth);
// Cerrar el menú si está abierto
closeMenu();
// Navegar a la sección correcta
setTimeout(function() {
const element = document.getElementById(targetId);
if (element) {
console.log('Elemento encontrado, desplazando a la vista');
element.scrollIntoView({ behavior: 'smooth' });
window.location.hash = targetId;
} else {
console.error('Sección de servicios no encontrada:', targetId);
}
}, 200); // Incrementamos el retraso para dar tiempo al DOM
});
});
// Actualizar enlaces al cambiar el tamaño de ventana
window.addEventListener('resize', function() {
const isMobile = window.innerWidth < 1080;
const targetId = isMobile ? 'services' : 'servicesDesktop';
console.log('Ventana redimensionada -', isMobile ? 'móvil' : 'escritorio', 'Ancho:', window.innerWidth);
// Solo actualizar los atributos href para la navegación por URL directa
document.querySelectorAll('.services-link').forEach(link => {
link.setAttribute('href', '#' + targetId);
});
// Verificar secciones después de redimensionar
setTimeout(checkServicesSectionsVisibility, 500);
// Verificar y ajustar visibilidad de la imagen principal
checkMainImageVisibility();
});
});