-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
109 lines (95 loc) · 3.16 KB
/
main.js
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
const openMenu = () => {
const nav = document.getElementById('nav');
const openButton = document.getElementById('open-button');
const closeButton = document.getElementById('close-button');
if (nav) {
nav.classList.remove('visible');
nav.classList.remove('hidden');
nav.classList.add('visible');
}
if (closeButton) {
closeButton.classList.remove('visible');
closeButton.classList.remove('hidden');
closeButton.classList.add('visible');
}
}
const closeMenu = () => {
const nav = document.getElementById('nav');
const openButton = document.getElementById('open-button');
const closeButton = document.getElementById('close-button');
if (nav) {
nav.classList.remove('visible');
nav.classList.remove('hidden');
nav.classList.add('hidden');
}
if (closeButton) {
closeButton.classList.remove('visible');
closeButton.classList.remove('hidden');
closeButton.classList.add('hidden');
}
}
const goToTop = () => {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}
const scrollFunction = () => {
const top = document.getElementById('top');
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
top.style.display = 'grid';
} else {
top.style.display = 'none';
}
}
const form = document.getElementById('contact-form');
if (form) {
form.addEventListener('submit', (e) => {
e.preventDefault();
const nom = document.getElementsByName('nom')[0];
const prenom = document.getElementsByName('prenom')[0];
const email = document.getElementsByName('email')[0];
const phone = document.getElementsByName('phone')[0];
const message = document.getElementsByName('message')[0];
if (!nom.value) {
nom.parentElement.classList.add('invalid');
return;
}
nom.parentElement.classList.remove('invalid');
if (!prenom.value) {
prenom.parentElement.classList.add('invalid');
return;
}
prenom.parentElement.classList.remove('invalid');
if (!email.value) {
email.parentElement.classList.add('invalid');
return;
}
email.parentElement.classList.remove('invalid');
const anchor = document.createElement('a');
anchor.href = `mailto:info@ipfconsulting.ch?subject=Prise de contact via ipfconsulting.ch&body=${encodeURIComponent(message.value)}%0A%0AInformations de contact:%0ANom: ${encodeURIComponent(prenom.value)} ${encodeURIComponent(nom.value)}%0AEmail: ${encodeURIComponent(email.value)}%0ATéléphone: ${encodeURIComponent(phone.value)}`;
anchor.target="_blank";
anchor.click();
});
}
window.onscroll = () => {
scrollFunction();
};
if (document.getElementById('contact-map')) {
mapboxgl.accessToken = '';
const map = new mapboxgl.Map({
container: 'contact-map',
style: 'mapbox://styles/mapbox/outdoors-v11',
center: [6.374857, 46.404928],
zoom: 9,
projection: 'globe'
});
map.on('style.load', () => {
map.setFog({});
});
const marker = new mapboxgl.Marker({
color: '#DC001C'
}).setLngLat([6.6087252, 46.59848])
.addTo(map);
const markerCarouge = new mapboxgl.Marker({
color: '#DC001C'
}).setLngLat([6.1369664, 46.1860605]).addTo(map);
}