-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
233 lines (201 loc) · 9.57 KB
/
Copy pathscript.js
File metadata and controls
233 lines (201 loc) · 9.57 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
document.addEventListener('DOMContentLoaded', () => {
// ==================================================
// LÓGICA GLOBAL (Executa em todas as páginas)
// ==================================================
// --- 1. Loader de Transição de Página ---
const allLinks = document.querySelectorAll('a:not([href^="#"]):not([target="_blank"])');
// Remove o loader quando a página termina de carregar
window.addEventListener('load', () => {
document.body.classList.remove('loading');
});
// CORREÇÃO: Lida com a navegação de "Voltar" e "Avançar" do navegador
window.addEventListener('pageshow', (event) => {
// Se a página foi carregada do bfcache, remove o loader
if (event.persisted) {
document.body.classList.remove('loading');
}
});
// Adiciona o loader ao clicar em um link interno para navegar para outra página
allLinks.forEach(link => {
link.addEventListener('click', (e) => {
if (link.hostname === window.location.hostname && link.pathname === window.location.pathname) {
return;
}
e.preventDefault();
const destination = link.href;
document.body.classList.add('loading');
setTimeout(() => {
window.location = destination;
}, 500);
});
});
// --- 2. Lógica para o Menu Móvel ---
const menuToggle = document.querySelector('.mobile-menu-toggle');
const mainNav = document.querySelector('.main-nav');
if (menuToggle && mainNav) {
menuToggle.addEventListener('click', () => {
mainNav.classList.toggle('is-active');
document.body.style.overflow = mainNav.classList.contains('is-active') ? 'hidden' : 'auto';
});
}
// --- 3. Lógica Otimizada para as Partículas de Flores ---
if (typeof tsParticles !== 'undefined') {
tsParticles.load("particles-js", {
fpsLimit: 40,
particles: {
number: { value: 15, density: { enable: true, value_area: 800 } },
color: { value: ["#d8a79d", "#a3b18a", "#b08968"] },
shape: {
type: "char",
character: { value: ["•", "✻", "·"], font: "Verdana", style: "", weight: "400", fill: true }
},
opacity: { value: { min: 0.3, max: 0.7 }, anim: { enable: true, speed: 0.5, sync: false } },
size: { value: { min: 8, max: 16 } },
move: { enable: true, speed: 1, direction: "bottom", random: true, straight: false, out_mode: "out", bounce: false }
},
interactivity: {
events: { onhover: { enable: false }, onclick: { enable: false }, resize: true }
},
detectRetina: true
});
}
// ==================================================
// LÓGICA ESPECÍFICA DE CADA PÁGINA
// ==================================================
// --- Lógica para a Homepage (index.html) ---
const slider = document.querySelector('.testimonial-slider');
const slides = document.querySelectorAll('.testimonial-slide');
const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');
if (slider && slides.length > 0 && prevBtn && nextBtn) {
let currentIndex = 0;
const totalSlides = slides.length;
const updateSliderPosition = () => { slider.style.transform = `translateX(-${currentIndex * 100}%)`; };
nextBtn.addEventListener('click', () => { currentIndex = (currentIndex + 1) % totalSlides; updateSliderPosition(); });
prevBtn.addEventListener('click', () => { currentIndex = (currentIndex - 1 + totalSlides) % totalSlides; updateSliderPosition(); });
updateSliderPosition();
}
// --- Lógica para a Página de Coleção (produtos.html) ---
const filterButtons = document.querySelectorAll('.filter-btn');
if (filterButtons.length > 0) {
filterButtons.forEach(button => {
button.addEventListener('click', (event) => {
filterButtons.forEach(btn => btn.classList.remove('active'));
event.currentTarget.classList.add('active');
});
});
}
// --- Lógica para a Página de Detalhes (detalhe-produto.html) ---
// 1. Skeleton Loading
const skeletonUI = document.querySelector('.skeleton-ui');
const realContent = document.querySelector('.real-content');
if (skeletonUI && realContent) {
setTimeout(() => {
skeletonUI.style.display = 'none';
realContent.style.display = 'grid';
}, 1500);
}
// 2. Accordion
const accordionItems = document.querySelectorAll('.accordion-item');
if (accordionItems.length > 0) {
accordionItems.forEach(item => {
const header = item.querySelector('.accordion-header');
header.addEventListener('click', () => {
const content = item.querySelector('.accordion-content');
header.classList.toggle('active');
if (content.style.maxHeight) {
content.style.maxHeight = null;
content.style.padding = "0 1rem";
} else {
content.style.padding = "0 1rem 1.5rem";
content.style.maxHeight = content.scrollHeight + "px";
}
});
});
}
// --- Lógica para a Página do Carrinho (carrinho.html) ---
const cartSkeleton = document.querySelector('.cart-section .skeleton-ui');
const cartRealContent = document.querySelector('.cart-section .real-content');
if (cartSkeleton && cartRealContent) {
// Simula 1 segundo de carregamento para o carrinho
setTimeout(() => {
cartSkeleton.style.display = 'none';
cartRealContent.style.display = 'grid'; // Usa 'grid' para ativar o layout
}, 1000);
}
// --- Lógica para a Página de Perfil (perfil.html) ---
const profileNavLinks = document.querySelectorAll('.profile-nav-link');
const profileTabContents = document.querySelectorAll('.profile-tab-content');
if (profileNavLinks.length > 0) {
profileNavLinks.forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
// Desativa todos os links e abas
profileNavLinks.forEach(item => item.classList.remove('active'));
profileTabContents.forEach(content => content.classList.remove('active'));
// Ativa o link clicado
link.classList.add('active');
// Ativa a aba de conteúdo correspondente
const targetId = link.dataset.tab;
const targetContent = document.getElementById(targetId);
if (targetContent) {
targetContent.classList.add('active');
}
});
});
}
// --- Lógica para a Página de Detalhe do Pedido ---
const orderDetailSkeleton = document.querySelector('.order-detail-section .skeleton-ui');
const orderDetailRealContent = document.querySelector('.order-detail-section .real-content');
if (orderDetailSkeleton && orderDetailRealContent) {
// Simula 1.2 segundos de carregamento
setTimeout(() => {
orderDetailSkeleton.style.display = 'none';
orderDetailRealContent.style.display = 'block';
}, 1200);
}
// --- Lógica para a Página de Login/Registro ---
const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form');
const showLoginBtn = document.getElementById('show-login');
const showRegisterBtn = document.getElementById('show-register');
if (showLoginBtn && showRegisterBtn) {
showLoginBtn.addEventListener('click', () => {
loginForm.classList.add('active');
registerForm.classList.remove('active');
showLoginBtn.classList.add('active');
showRegisterBtn.classList.remove('active');
});
showRegisterBtn.addEventListener('click', () => {
loginForm.classList.remove('active');
registerForm.classList.add('active');
showLoginBtn.classList.remove('active');
showRegisterBtn.classList.add('active');
});
}
// --- Lógica para o Botão Flutuante do WhatsApp ---
const whatsappBubble = document.querySelector('.whatsapp-message-bubble');
const whatsappText = document.getElementById('whatsapp-text');
if (whatsappBubble && whatsappText) {
const messages = [
"Olá! Posso ajudar?",
"Ficou com alguma dúvida?",
"Fale conosco por aqui!",
"Podemos ajudar na escolha?"
];
let messageIndex = 0;
const showMessage = () => {
whatsappText.textContent = messages[messageIndex];
whatsappBubble.classList.add('visible');
setTimeout(() => {
whatsappBubble.classList.remove('visible');
messageIndex = (messageIndex + 1) % messages.length; // Avança para a próxima msg
}, 5000); // Mensagem fica visível por 5 segundos
};
// Inicia o ciclo de mensagens após um delay inicial
setTimeout(() => {
showMessage(); // Mostra a primeira mensagem
setInterval(showMessage, 8000); // Alterna a mensagem a cada 8 segundos (5 visível + 3 invisível)
}, 3000); // Espera 3 segundos após carregar a página para começar
}
});