-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
396 lines (324 loc) · 13 KB
/
app.js
File metadata and controls
396 lines (324 loc) · 13 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
// Max&Max Srls Landing Page JavaScript - Fixed Navigation
(function() {
'use strict';
// Wait for DOM to be fully loaded
document.addEventListener('DOMContentLoaded', function() {
// Initialize all functionality
initNavigation();
initMobileMenu();
initContactForm();
initScrollEffects();
initAnimations();
console.log('Max&Max Srls Landing Page initialized successfully');
});
// Navigation functionality
function initNavigation() {
// Get all links that start with #
const navLinks = document.querySelectorAll('a[href^="#"]');
navLinks.forEach(function(link) {
link.addEventListener('click', function(event) {
event.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
// Close mobile menu if open
closeMobileMenu();
// Smooth scroll to target
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// Handle hash navigation on page load
if (window.location.hash) {
setTimeout(function() {
const targetElement = document.querySelector(window.location.hash);
if (targetElement) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
}, 100);
}
}
// Mobile menu functionality
function initMobileMenu() {
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
const nav = document.querySelector('.nav');
if (mobileMenuToggle && nav) {
mobileMenuToggle.addEventListener('click', function() {
nav.classList.toggle('nav--open');
mobileMenuToggle.classList.toggle('mobile-menu-toggle--open');
});
}
// Close menu on escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
closeMobileMenu();
}
});
// Close menu when clicking outside
document.addEventListener('click', function(e) {
const nav = document.querySelector('.nav');
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
if (nav && nav.classList.contains('nav--open')) {
if (!nav.contains(e.target) && !mobileMenuToggle.contains(e.target)) {
closeMobileMenu();
}
}
});
}
function closeMobileMenu() {
const nav = document.querySelector('.nav');
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
if (nav) nav.classList.remove('nav--open');
if (mobileMenuToggle) mobileMenuToggle.classList.remove('mobile-menu-toggle--open');
}
// Contact form functionality
function initContactForm() {
const contactForm = document.getElementById('contactForm');
if (!contactForm) return;
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const nome = formData.get('nome').trim();
const email = formData.get('email').trim();
const telefono = formData.get('telefono').trim();
const messaggio = formData.get('messaggio').trim();
// Validation
if (!nome || !email || !messaggio) {
showStatusMessage('Per favore compila tutti i campi obbligatori.', 'error');
return;
}
if (!isValidEmail(email)) {
showStatusMessage('Per favore inserisci un indirizzo email valido.', 'error');
return;
}
// Show loading state
const submitButton = this.querySelector('button[type="submit"]');
submitButton.classList.add('btn--loading');
submitButton.disabled = true;
// Simulate form submission
setTimeout(function() {
// Reset button state
submitButton.classList.remove('btn--loading');
submitButton.disabled = false;
// Show success message
showStatusMessage(
'Grazie per il tuo messaggio! Ti contatteremo al più presto per fornirti tutte le informazioni richieste.',
'success'
);
// Reset form
contactForm.reset();
// Open email client
const subject = encodeURIComponent('Richiesta informazioni - Scatole per Pizza');
const body = encodeURIComponent(`Nome: ${nome}\nTelefono: ${telefono}\n\nMessaggio:\n${messaggio}`);
const mailtoLink = `mailto:info@scatoleperpizza.it?subject=${subject}&body=${body}`;
window.open(mailtoLink);
}, 1500);
});
// Phone number formatting
const phoneField = document.getElementById('telefono');
if (phoneField) {
phoneField.addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length > 0) {
if (value.startsWith('39')) {
value = value.replace(/(\d{2})(\d{3})(\d{3})(\d{4})/, '+$1 $2 $3 $4');
} else if (value.length === 10) {
value = value.replace(/(\d{3})(\d{3})(\d{4})/, '$1 $2 $3');
} else if (value.length > 6) {
value = value.replace(/(\d{3})(\d{3})(\d+)/, '$1 $2 $3');
} else if (value.length > 3) {
value = value.replace(/(\d{3})(\d+)/, '$1 $2');
}
}
e.target.value = value;
});
}
// Real-time validation
const formFields = contactForm.querySelectorAll('.form-control');
formFields.forEach(function(field) {
field.addEventListener('blur', function() {
validateField(this);
});
field.addEventListener('input', function() {
if (this.classList.contains('form-control--error')) {
this.classList.remove('form-control--error');
}
});
});
}
// Scroll effects
function initScrollEffects() {
const header = document.querySelector('.header');
window.addEventListener('scroll', function() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
if (header) {
if (scrollTop > 50) {
header.classList.add('header--scrolled');
} else {
header.classList.remove('header--scrolled');
}
}
});
}
// Animation on scroll
function initAnimations() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.classList.add('animate-in');
}
});
}, observerOptions);
const animateElements = document.querySelectorAll('.product-card, .advantage-item, .sustainability-feature');
animateElements.forEach(function(el) {
observer.observe(el);
});
}
// Helper functions
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function validateField(field) {
const value = field.value.trim();
let isValid = true;
if (field.required && !value) {
isValid = false;
}
if (field.type === 'email' && value && !isValidEmail(value)) {
isValid = false;
}
if (!isValid) {
field.classList.add('form-control--error');
} else {
field.classList.remove('form-control--error');
}
return isValid;
}
function showStatusMessage(message, type) {
// Remove existing message
const existingMessage = document.querySelector('.status-message');
if (existingMessage) {
existingMessage.remove();
}
// Create new message
const statusMessage = document.createElement('div');
statusMessage.className = `status-message status-message--${type}`;
statusMessage.textContent = message;
// Insert after form
const form = document.getElementById('contactForm');
if (form && form.parentNode) {
form.parentNode.insertBefore(statusMessage, form.nextSibling);
// Scroll to message
statusMessage.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
// Auto remove
const timeout = type === 'success' ? 8000 : 10000;
setTimeout(function() {
if (statusMessage.parentNode) {
statusMessage.remove();
}
}, timeout);
}
// Add additional styles
const additionalStyles = `
html {
scroll-behavior: smooth;
}
.header--scrolled {
background-color: rgba(255, 255, 253, 0.95);
backdrop-filter: blur(10px);
border-bottom: 1px solid var(--color-border);
}
.nav--open {
display: flex !important;
flex-direction: column;
position: absolute;
top: 100%;
left: 0;
right: 0;
background-color: var(--color-surface);
border: 1px solid var(--color-border);
border-top: none;
padding: var(--space-16);
box-shadow: var(--shadow-lg);
z-index: 999;
}
.mobile-menu-toggle--open span:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
.mobile-menu-toggle--open span:nth-child(2) {
opacity: 0;
}
.mobile-menu-toggle--open span:nth-child(3) {
transform: rotate(-45deg) translate(7px, -6px);
}
.animate-in {
animation: fadeInUp 0.6s ease-out forwards;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.form-control--error {
border-color: var(--color-error) !important;
box-shadow: 0 0 0 3px rgba(var(--color-error-rgb), 0.1) !important;
}
.btn {
transition: all var(--duration-normal) var(--ease-standard);
}
.btn:hover {
transform: translateY(-2px);
box-shadow: var(--shadow-md);
}
.btn:active {
transform: translateY(0);
}
.product-card,
.advantage-item {
transition: all var(--duration-normal) var(--ease-standard);
}
@media (max-width: 768px) {
.nav--open {
gap: var(--space-16);
}
.nav--open .nav-link {
padding: var(--space-12);
border-bottom: 1px solid var(--color-border);
text-align: center;
}
.nav--open .nav-link:last-child {
border-bottom: none;
}
.hero {
margin-top: 60px;
}
}
`;
// Inject styles
const styleSheet = document.createElement('style');
styleSheet.textContent = additionalStyles;
document.head.appendChild(styleSheet);
})();