« Demander une démo » devient « Nous écrire », délai de réponse renseigné, raccourcis « Prêt à commencer ? » (formules) et « Déjà client ? » (espace), bouton « Envoyer le message » ; e-mail reçu intitulé « Message du site ». Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
179 lines
7.4 KiB
JavaScript
179 lines
7.4 KiB
JavaScript
// Comportements du site vitrine : menu mobile, simulateur, formulaire, FAQ, bandeau cookies.
|
||
(function () {
|
||
var root = document.querySelector('.mep');
|
||
|
||
// ── Menu mobile ──
|
||
var menu = document.querySelector('[data-menu]');
|
||
if (menu) {
|
||
menu.addEventListener('click', function () {
|
||
var open = root.classList.toggle('nav-open');
|
||
menu.setAttribute('aria-expanded', String(open));
|
||
menu.setAttribute('aria-label', open ? 'Fermer le menu' : 'Ouvrir le menu');
|
||
});
|
||
document.addEventListener('keydown', function (e) {
|
||
if (e.key === 'Escape' && root.classList.contains('nav-open')) menu.click();
|
||
});
|
||
}
|
||
|
||
// Lien actif dans la navigation
|
||
var here = location.pathname;
|
||
document.querySelectorAll('.nav .nl').forEach(function (a) {
|
||
if (a.getAttribute('href') === here) {
|
||
a.classList.add('on');
|
||
a.setAttribute('aria-current', 'page');
|
||
}
|
||
});
|
||
|
||
// ── Formules : bascule mensuel / annuel ──
|
||
var interval = 'month';
|
||
var euros = function (cents) {
|
||
return (cents / 100).toLocaleString('fr-FR', { minimumFractionDigits: cents % 100 ? 2 : 0, maximumFractionDigits: 2 });
|
||
};
|
||
function pressOnly(group, btn) {
|
||
group.querySelectorAll('button').forEach(function (b) {
|
||
var on = b === btn;
|
||
b.classList.toggle('on', on);
|
||
b.setAttribute('aria-pressed', String(on));
|
||
});
|
||
}
|
||
document.querySelectorAll('[data-interval]').forEach(function (btn) {
|
||
btn.addEventListener('click', function () {
|
||
interval = btn.getAttribute('data-interval');
|
||
pressOnly(btn.parentElement, btn);
|
||
document.querySelectorAll('[data-price],[data-per],[data-note]').forEach(function (el) {
|
||
el.innerHTML = el.getAttribute('data-' + interval);
|
||
});
|
||
// Les boutons « Choisir » emportent la périodicité vers l'inscription.
|
||
document.querySelectorAll('[data-plan-link]').forEach(function (a) {
|
||
a.href = a.href.replace(/&periode=\w+/, '') + (interval === 'year' ? '&periode=annuel' : '');
|
||
});
|
||
renderSim();
|
||
});
|
||
});
|
||
|
||
// ── Simulateur : formule × nombre de magasins ──
|
||
var n = 1;
|
||
var nEl = document.querySelector('[data-n]');
|
||
var totalEl = document.querySelector('[data-total]');
|
||
var simPlan = document.querySelector('[data-sim-plan].on') || document.querySelector('[data-sim-plan]');
|
||
function renderSim() {
|
||
if (!nEl || !simPlan) return;
|
||
var min = Number(simPlan.getAttribute('data-min'));
|
||
if (n < min) n = min;
|
||
nEl.textContent = n;
|
||
totalEl.textContent = euros(n * Number(simPlan.getAttribute('data-' + interval)));
|
||
var label = document.querySelector('[data-sim-label]');
|
||
var hint = document.querySelector('[data-sim-hint]');
|
||
if (label) label.textContent = interval === 'year' ? 'Total annuel' : 'Total mensuel';
|
||
if (hint) {
|
||
hint.textContent =
|
||
(interval === 'year' ? 'par an, 2 mois offerts' : 'par mois, sans engagement') +
|
||
(min > 1 ? ' · formule Réseau à partir de ' + min + ' magasins' : '');
|
||
}
|
||
}
|
||
document.querySelectorAll('[data-sim-plan]').forEach(function (btn) {
|
||
btn.addEventListener('click', function () {
|
||
simPlan = btn;
|
||
pressOnly(btn.parentElement, btn);
|
||
renderSim();
|
||
});
|
||
});
|
||
var dec = document.querySelector('[data-dec]');
|
||
var inc = document.querySelector('[data-inc]');
|
||
if (dec) dec.addEventListener('click', function () { n = Math.max(1, n - 1); renderSim(); });
|
||
if (inc) inc.addEventListener('click', function () { n = Math.min(50, n + 1); renderSim(); });
|
||
renderSim();
|
||
|
||
// ── Formulaire de contact ──
|
||
var box = document.querySelector('[data-contact]');
|
||
if (box) {
|
||
var form = box.querySelector('form');
|
||
var success = box.querySelector('[data-state="succes"]');
|
||
var errBox = box.querySelector('[data-error]');
|
||
var errText = box.querySelector('[data-error-text]');
|
||
var submit = box.querySelector('[data-submit]');
|
||
var sending = box.querySelector('[data-sending]');
|
||
var defaultErr = errText.textContent;
|
||
|
||
function show(state) {
|
||
form.classList.toggle('on', state !== 'succes');
|
||
success.classList.toggle('on', state === 'succes');
|
||
var busy = state === 'envoi';
|
||
submit.style.display = busy ? 'none' : '';
|
||
sending.style.display = busy ? '' : 'none';
|
||
box.querySelector('[data-fields]').classList.toggle('dim', busy);
|
||
box.querySelector('[data-consent]').classList.toggle('dim', busy);
|
||
form.querySelectorAll('input,select,textarea').forEach(function (el) { el.disabled = busy; });
|
||
}
|
||
|
||
function fail(message) {
|
||
errText.textContent = message || defaultErr;
|
||
errBox.hidden = false;
|
||
submit.textContent = 'Réessayer';
|
||
show('form');
|
||
errBox.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
||
}
|
||
|
||
form.addEventListener('submit', function (e) {
|
||
e.preventDefault();
|
||
errBox.hidden = true;
|
||
if (!form.checkValidity()) {
|
||
var first = form.querySelector(':invalid');
|
||
fail(first && first.name === 'consent'
|
||
? 'Cochez la case pour que nous puissions vous répondre.'
|
||
: 'Vérifiez les champs : tous sont obligatoires, sauf le message.');
|
||
if (first) first.focus();
|
||
return;
|
||
}
|
||
var data = {};
|
||
new FormData(form).forEach(function (v, k) { data[k] = typeof v === 'string' ? v.trim() : v; });
|
||
data.consent = true;
|
||
show('envoi');
|
||
fetch('/api/public/contact', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify(data),
|
||
})
|
||
.then(function (r) {
|
||
if (r.ok) { form.reset(); submit.textContent = 'Envoyer le message'; show('succes'); success.querySelector('h2').focus({ preventScroll: true }); return; }
|
||
if (r.status === 429) return fail('Trop de messages envoyés. Réessayez dans quelques minutes, ou écrivez-nous à contact@monespacepro.eu.');
|
||
fail();
|
||
})
|
||
.catch(function () { fail(); });
|
||
});
|
||
success.querySelector('h2').tabIndex = -1;
|
||
box.querySelector('[data-again]').addEventListener('click', function () { show('form'); });
|
||
}
|
||
|
||
// ── Recherche dans la FAQ ──
|
||
var search = document.querySelector('[data-faq-search]');
|
||
if (search) {
|
||
var norm = function (s) { return s.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase(); };
|
||
search.addEventListener('input', function () {
|
||
var q = norm(search.value.trim());
|
||
document.querySelectorAll('.faq details').forEach(function (d) {
|
||
var hit = !q || norm(d.textContent).indexOf(q) !== -1;
|
||
d.hidden = !hit;
|
||
if (q && hit) d.open = true;
|
||
});
|
||
document.querySelectorAll('.faq').forEach(function (group) {
|
||
// Rubrique sans résultat (titre + liste) masquée entièrement.
|
||
var block = group.parentElement;
|
||
var visible = group.querySelector('details:not([hidden])');
|
||
if (block) block.style.display = visible ? '' : 'none';
|
||
});
|
||
});
|
||
}
|
||
|
||
// ── Bandeau cookies (information seulement : cookies techniques) ──
|
||
var cookie = document.querySelector('[data-cookie]');
|
||
if (cookie) {
|
||
var seen = false;
|
||
try { seen = localStorage.getItem('mep.cookie') === '1'; } catch (e) { /* stockage indisponible */ }
|
||
if (!seen) cookie.hidden = false;
|
||
cookie.querySelector('[data-cookie-close]').addEventListener('click', function () {
|
||
cookie.hidden = true;
|
||
try { localStorage.setItem('mep.cookie', '1'); } catch (e) { /* rien */ }
|
||
});
|
||
}
|
||
})();
|