-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
174 lines (149 loc) · 6.81 KB
/
script.js
File metadata and controls
174 lines (149 loc) · 6.81 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
// FAQ Tab Functionality
document.addEventListener('DOMContentLoaded', function() {
// FAQ Tabs
const faqTabs = document.querySelectorAll('.faq-tab');
const faqCategories = document.querySelectorAll('.faq-category');
faqTabs.forEach(tab => {
tab.addEventListener('click', function() {
const category = this.getAttribute('data-category');
// Remove active class from all tabs and categories
faqTabs.forEach(t => t.classList.remove('active'));
faqCategories.forEach(c => c.classList.remove('active'));
// Add active class to clicked tab and corresponding category
this.classList.add('active');
document.querySelector(`.faq-category[data-category="${category}"]`).classList.add('active');
});
});
// Contact Form Handling (client-side validation + GDPR)
const contactForm = document.getElementById('contactForm');
// Check for success message in URL
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('success') === 'true') {
showFormMessage('✅ Thank you! Your message has been sent successfully. We\'ll get back to you soon.', 'success');
// Remove success parameter from URL
window.history.replaceState({}, document.title, window.location.pathname);
}
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
// Validation
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const message = document.getElementById('message').value.trim();
const privacyConsent = document.getElementById('privacy-consent').checked;
if (!name || !email || !message) {
e.preventDefault();
showFormMessage('⚠️ Please fill in all required fields.', 'error');
return false;
}
if (name.length < 2) {
e.preventDefault();
showFormMessage('⚠️ Name must be at least 2 characters long.', 'error');
return false;
}
if (message.length < 10) {
e.preventDefault();
showFormMessage('⚠️ Message must be at least 10 characters long.', 'error');
return false;
}
// Email validation
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(email)) {
e.preventDefault();
showFormMessage('⚠️ Please enter a valid email address.', 'error');
return false;
}
// GDPR consent check
if (!privacyConsent) {
e.preventDefault();
showFormMessage('⚠️ You must agree to the Privacy Policy to submit this form.', 'error');
return false;
}
// Show loading state
const submitBtn = document.getElementById('submitBtn');
submitBtn.disabled = true;
submitBtn.textContent = 'Sending...';
});
}
// Migliore gestione touch per mobile - FIX per Safari iOS
function enableTouchHover(selector) {
// Verifica se è un dispositivo touch
if (!('ontouchstart' in window) && !(navigator.maxTouchPoints > 0)) return;
const els = document.querySelectorAll(selector);
els.forEach(el => {
let touchMoved = false;
// Rileva se l'utente sta scrollando o toccando
el.addEventListener('touchstart', function(e) {
touchMoved = false;
}, { passive: true });
el.addEventListener('touchmove', function() {
touchMoved = true;
}, { passive: true });
// Applica l'effetto hover solo se NON ha scrollato
el.addEventListener('touchend', function(e) {
if (!touchMoved) {
// Rimuovi touch da tutti gli altri elementi
document.querySelectorAll(selector).forEach(other => {
if (other !== el) {
other.classList.remove('touch');
}
});
// Toggle sulla classe touch per questo elemento
el.classList.toggle('touch');
// Rimuovi automaticamente dopo 1.5 secondi
if (el.classList.contains('touch')) {
if (el._touchTimeout) clearTimeout(el._touchTimeout);
el._touchTimeout = setTimeout(() => {
el.classList.remove('touch');
}, 1500);
} else {
if (el._touchTimeout) {
clearTimeout(el._touchTimeout);
el._touchTimeout = null;
}
}
}
}, { passive: true });
});
// Nota: il listener global touchend è stato rimosso da qui per evitare duplicati
}
// Attiva touch hover su phone mockup e feature cards
enableTouchHover('.phone-mockup');
enableTouchHover('.feature-content');
// Aggiungo UNA sola volta il listener globale per rimuovere lo stato quando si tocca fuori
document.addEventListener('touchend', function(e) {
if (!e.target.closest('.phone-mockup') && !e.target.closest('.feature-content')) {
document.querySelectorAll('.phone-mockup.touch, .feature-content.touch').forEach(active => {
active.classList.remove('touch');
if (active._touchTimeout) {
clearTimeout(active._touchTimeout);
active._touchTimeout = null;
}
});
}
}, { passive: true });
});
function showFormMessage(message, type) {
const formMessage = document.getElementById('formMessage');
if (formMessage) {
formMessage.textContent = message;
formMessage.className = 'form-message ' + type;
formMessage.style.display = 'block';
// Hide message after 5 seconds
setTimeout(() => {
formMessage.style.display = 'none';
}, 5000);
}
}
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});