:where(.hwd-formulaire .screen-reader-response){position:absolute;overflow:hidden;clip:rect(1px,1px,1px,1px);clip-path:inset(50%);height:1px;width:1px;margin:-1px;padding:0;border:0;word-wrap:normal}:where(.hwd-formulaire form .wpcf7-response-output){margin:2em .5em 1em;padding:.2em 1em;border:2px solid #00a0d2}:where(.hwd-formulaire form.init .wpcf7-response-output,.hwd-formulaire form.submitting .wpcf7-response-output){display:none}:where(.hwd-formulaire form.sent .wpcf7-response-output){border-color:#46b450}:where(.hwd-formulaire form.failed .wpcf7-response-output,.hwd-formulaire form.aborted .wpcf7-response-output){border-color:#dc3232}:where(.hwd-formulaire form.spam .wpcf7-response-output){border-color:#f56e28}:where(.hwd-formulaire form.invalid .wpcf7-response-output){border-color:#ffb900}:where(.hwd-formulaire .wpcf7-form-control-wrap){position:relative}:where(.hwd-formulaire .wpcf7-not-valid-tip){color:#dc3232;font-size:1em;font-weight:400;display:block}:where(.hwd-formulaire .wpcf7-list-item){display:inline-block;margin:0 0 0 1em}:where(.hwd-formulaire form.submitting [type=submit]){opacity:.6;cursor:wait}
window.hwdFormulairesReglages={"u":"https:\/\/www.villa-morelia.com\/wp-admin\/admin-ajax.php","r":""};
/* HWD - formulaires. Le fonctionnement est decrit dans inc/hwd-formulaires.php. */
(function (w, d, c) {
'use strict';
if (!c || !c.u || !w.fetch || !w.FormData || !w.Promise || !d.addEventListener || w.hwdFormulairesArmes) {
return;
}
w.hwdFormulairesArmes = 1;
var ETATS = {
mail_sent: 'sent',
validation_failed: 'invalid',
spam: 'spam',
mail_failed: 'failed',
aborted: 'aborted'
};
var EVENEMENTS = {
mail_sent: 'wpcf7mailsent',
validation_failed: 'wpcf7invalid',
spam: 'wpcf7spam',
mail_failed: 'wpcf7mailfailed',
aborted: 'wpcf7mailfailed'
};
/* Classes de Contact Form 7 avant la 5.2, encore colorees par des themes. */
var ANCIENNES = {
mail_sent: 'wpcf7-mail-sent-ok',
validation_failed: 'wpcf7-validation-errors',
spam: 'wpcf7-spam-blocked',
mail_failed: 'wpcf7-mail-sent-ng',
aborted: 'wpcf7-aborted'
};
var recaptchaDemande = false;
/* reCAPTCHA v3 : charge au premier contact avec un formulaire, pas avant. */
function chargerRecaptcha() {
if (!c.r || recaptchaDemande) {
return;
}
recaptchaDemande = true;
var s = d.createElement('script');
s.src = 'https://www.google.com/recaptcha/api.js?render=' + encodeURIComponent(c.r);
s.async = true;
d.head.appendChild(s);
}
function jeton() {
return new Promise(function (ok) {
if (!c.r) {
ok('');
return;
}
chargerRecaptcha();
var essais = 0;
(function attendre() {
var g = w.grecaptcha;
if (g && g.ready && g.execute) {
g.ready(function () {
g.execute(c.r, {action: 'contactform'}).then(ok, function () {
ok('');
});
});
} else if (essais++ < 100) {
setTimeout(attendre, 100);
} else {
ok('');
}
})();
});
}
function formulaire(el) {
while (el && el.nodeName !== 'FORM') {
el = el.parentNode;
}
return el && el.classList && el.classList.contains('hwd-formulaire-form') ? el : null;
}
function etat(f, nom) {
var k;
for (k in ETATS) {
if (Object.prototype.hasOwnProperty.call(ETATS, k)) {
f.classList.remove(ETATS[k]);
}
}
f.classList.remove('init', 'submitting', 'resetting');
f.classList.add(nom);
f.setAttribute('data-status', nom);
}
function nettoyer(f) {
var i, liste = f.querySelectorAll('.wpcf7-not-valid-tip');
for (i = 0; i < liste.length; i++) {
liste[i].parentNode.removeChild(liste[i]);
}
liste = f.querySelectorAll('.wpcf7-not-valid');
for (i = 0; i < liste.length; i++) {
liste[i].classList.remove('wpcf7-not-valid');
liste[i].setAttribute('aria-invalid', 'false');
}
}
function prevenir(f, r) {
var boite = f.closest ? f.closest('.hwd-formulaire') : null;
var cible = boite || f;
var detail = {
contactFormId: r.contact_form_id,
unitTag: boite ? boite.id : '',
status: r.status,
apiResponse: r,
inputs: []
};
var noms = ['wpcf7submit', EVENEMENTS[r.status] || 'wpcf7mailfailed'];
var i;
try {
new FormData(f).forEach(function (valeur, nom) {
if (nom.charAt(0) !== '_' && typeof valeur === 'string') {
detail.inputs.push({name: nom, value: valeur});
}
});
} catch (e) {}
for (i = 0; i < noms.length; i++) {
try {
cible.dispatchEvent(new CustomEvent(noms[i], {bubbles: true, detail: detail}));
} catch (e) {}
}
}
function afficher(f, r) {
var message = r && typeof r.message === 'string' && r.message !== '' ? r.message : f.getAttribute('data-echec');
var statut = r && ETATS[r.status] ? r.status : 'mail_failed';
var sortie = f.querySelector('.wpcf7-response-output');
var boite = f.closest ? f.closest('.hwd-formulaire') : null;
var lecteur = boite ? boite.querySelector('.screen-reader-response p') : null;
var i, k, champ, enveloppe, controle, astuce;
nettoyer(f);
etat(f, ETATS[statut]);
if (sortie) {
for (k in ANCIENNES) {
if (Object.prototype.hasOwnProperty.call(ANCIENNES, k)) {
sortie.classList.remove(ANCIENNES[k]);
}
}
sortie.classList.add(ANCIENNES[statut]);
sortie.textContent = message || '';
sortie.setAttribute('aria-hidden', 'false');
sortie.setAttribute('role', 'alert');
}
if (lecteur) {
lecteur.textContent = message || '';
}
if (r && r.invalid_fields && r.invalid_fields.length) {
for (i = 0; i < r.invalid_fields.length; i++) {
champ = r.invalid_fields[i];
enveloppe = null;
try {
enveloppe = f.querySelector('.wpcf7-form-control-wrap[data-name="' + String(champ.field).replace(/["\\]/g, '\\$&') + '"]');
} catch (e) {}
if (!enveloppe) {
continue;
}
controle = enveloppe.querySelector('.wpcf7-form-control');
if (controle) {
controle.classList.add('wpcf7-not-valid');
controle.setAttribute('aria-invalid', 'true');
}
astuce = d.createElement('span');
astuce.className = 'wpcf7-not-valid-tip';
astuce.setAttribute('aria-hidden', 'true');
astuce.textContent = champ.message;
enveloppe.appendChild(astuce);
}
}
if (statut === 'mail_sent') {
f.reset();
}
prevenir(f, r || {status: statut, message: message, invalid_fields: []});
}
function envoyer(f) {
if (f.getAttribute('data-status') === 'submitting') {
return;
}
etat(f, 'submitting');
jeton().then(function (t) {
var donnees = new FormData(f);
donnees.set('action', 'hwd_formulaire');
donnees.set('_hwd_url', w.location.href);
if (t) {
donnees.set('_hwd_recaptcha', t);
}
return w.fetch(c.u, {method: 'POST', body: donnees, credentials: 'same-origin'});
}).then(function (reponse) {
return reponse.json();
}).then(function (r) {
afficher(f, r);
}, function () {
afficher(f, null);
});
}
d.addEventListener('submit', function (ev) {
var f = formulaire(ev.target);
if (!f) {
return;
}
ev.preventDefault();
envoyer(f);
}, false);
['focusin', 'pointerdown', 'touchstart'].forEach(function (type) {
d.addEventListener(type, function (ev) {
if (formulaire(ev.target)) {
chargerRecaptcha();
}
}, {passive: true, capture: true});
});
})(window, document, window.hwdFormulairesReglages);