-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
162 lines (136 loc) · 4.93 KB
/
Copy pathscript.js
File metadata and controls
162 lines (136 loc) · 4.93 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
/* KOVELEO — Vanilla JS interactions */
(function () {
'use strict';
const header = document.getElementById('site-header');
const hamburger = document.getElementById('hamburger');
const mobileNav = document.getElementById('mobile-nav');
const mobileNavClose = document.getElementById('mobile-nav-close');
const mobileNavLinks = document.querySelectorAll('.mobile-nav-link, .mobile-nav-cta');
/* ---- Mobile nav ---- */
function getFocusable() {
return Array.from(mobileNav.querySelectorAll('button, a, [tabindex="0"]'));
}
function trapFocus(e) {
if (e.key !== 'Tab') return;
var focusable = getFocusable();
var first = focusable[0];
var last = focusable[focusable.length - 1];
if (e.shiftKey) {
if (document.activeElement === first) {
e.preventDefault();
last.focus();
}
} else {
if (document.activeElement === last) {
e.preventDefault();
first.focus();
}
}
}
function openNav() {
mobileNav.classList.add('is-open');
mobileNav.removeAttribute('inert');
hamburger.classList.add('is-open');
hamburger.setAttribute('aria-expanded', 'true');
document.body.style.overflow = 'hidden';
mobileNavClose.focus();
document.addEventListener('keydown', trapFocus);
}
function closeNav() {
mobileNav.classList.remove('is-open');
mobileNav.setAttribute('inert', '');
hamburger.classList.remove('is-open');
hamburger.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
hamburger.focus();
document.removeEventListener('keydown', trapFocus);
}
if (hamburger) hamburger.addEventListener('click', openNav);
if (mobileNavClose) mobileNavClose.addEventListener('click', closeNav);
mobileNavLinks.forEach(function (link) {
link.addEventListener('click', closeNav);
});
/* Close nav on Escape */
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && mobileNav && mobileNav.classList.contains('is-open')) {
closeNav();
}
});
/* ---- Sticky nav scroll class ---- */
var heroSection = document.getElementById('hero');
function onScroll() {
if (!header) return;
var heroBottom = heroSection ? heroSection.getBoundingClientRect().bottom : 0;
if (heroBottom < 0) {
header.classList.add('nav--scrolled');
} else {
header.classList.remove('nav--scrolled');
}
}
window.addEventListener('scroll', onScroll, { passive: true });
/* ---- Active nav link on scroll ---- */
var navLinks = document.querySelectorAll('.nav-link');
var sectionIds = ['constat', 'approche', 'offres', 'preuves'];
var sectionObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
navLinks.forEach(function (link) {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + entry.target.id) {
link.classList.add('active');
}
});
}
});
}, { rootMargin: '-40% 0px -55% 0px' });
sectionIds.forEach(function (id) {
var el = document.getElementById(id);
if (el) sectionObserver.observe(el);
});
/* ---- Scroll reveal ---- */
var prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (!prefersReducedMotion) {
var revealTargets = document.querySelectorAll(
'.card, .offre-card, .metric, .verbatim, .pillar, .faq-item'
);
revealTargets.forEach(function (el) {
el.classList.add('reveal');
});
var revealObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
revealObserver.unobserve(entry.target);
}
});
}, { rootMargin: '0px 0px -60px 0px' });
revealTargets.forEach(function (el) {
revealObserver.observe(el);
});
}
/* ---- FAQ exclusive accordion (close others on open) ---- */
var faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(function (item) {
item.addEventListener('toggle', function () {
if (item.open) {
faqItems.forEach(function (other) {
if (other !== item && other.open) {
other.open = false;
}
});
}
});
});
/* ---- Ticker pause/play toggle ---- */
var tickerWrapper = document.querySelector('.ticker-wrapper');
var tickerPauseBtn = document.getElementById('ticker-pause');
if (tickerPauseBtn && tickerWrapper) {
var tickerLabel = tickerPauseBtn.querySelector('.ticker-pause-label');
tickerPauseBtn.addEventListener('click', function () {
var isPaused = tickerWrapper.classList.toggle('ticker-paused');
tickerPauseBtn.classList.toggle('is-paused', isPaused);
tickerPauseBtn.setAttribute('aria-pressed', String(isPaused));
if (tickerLabel) tickerLabel.textContent = isPaused ? 'Reprendre' : 'Pause';
});
}
})();