Menu
/** * WATHI × Ambassade d'Irlande — Contact Form 7 * Champs conditionnels + compteur de mots * * → Ajouter via "Insert Headers and Footers" (section Footer) * OU dans functions.php via wp_enqueue_scripts */ (function () { 'use strict'; function initWathiForm() { /* ── 1. Champ conditionnel : Nom d'organisation ── */ var orgRadios = document.querySelectorAll('input[name="organisation"]'); var orgBlock = document.getElementById('wf-orgblock'); if (orgRadios.length && orgBlock) { // État initial orgRadios.forEach(function (radio) { if (radio.checked && radio.value === 'Oui') orgBlock.classList.add('active'); radio.addEventListener('change', function () { orgBlock.classList.toggle('active', this.value === 'Oui'); }); }); } /* ── 2. Champ conditionnel : Autre plateforme ── */ var platCheckboxes = document.querySelectorAll('input[name="plateformes[]"]'); var autrePlatBlock = document.getElementById('wf-autreblock'); if (platCheckboxes.length && autrePlatBlock) { function checkAutre() { var autreChecked = Array.from(platCheckboxes).some(function (c) { return c.value === 'Autre' && c.checked; }); autrePlatBlock.classList.toggle('active', autreChecked); } platCheckboxes.forEach(function (cb) { cb.addEventListener('change', checkAutre); }); checkAutre(); } /* ── 3. Compteurs de mots ── */ var counters = document.querySelectorAll('.wf-wcount'); counters.forEach(function (counter) { var fieldName = counter.getAttribute('data-field'); var max = parseInt(counter.getAttribute('data-max'), 10) || 0; var span = counter.querySelector('span'); var textarea = document.querySelector('textarea[name="' + fieldName + '"]'); if (!textarea || !span) return; function update() { var trimmed = textarea.value.trim(); var count = trimmed === '' ? 0 : trimmed.split(/\s+/).length; span.textContent = count; if (max > 0) { counter.classList.toggle('over', count > max); } } textarea.addEventListener('input', update); update(); }); /* ── 4. Upload CV : afficher le nom du fichier ── */ var fileInputs = document.querySelectorAll('input[name="cv"]'); fileInputs.forEach(function (fileInput) { var titleEl = fileInput.closest('.wf-upload') ? fileInput.closest('.wf-upload').querySelector('.wf-upload-title') : null; if (!titleEl) return; var original = titleEl.textContent; fileInput.addEventListener('change', function () { if (this.files && this.files[0]) { titleEl.textContent = '✓ ' + this.files[0].name; titleEl.style.color = '#009A44'; } else { titleEl.textContent = original; titleEl.style.color = ''; } }); }); } /* Lance après chargement DOM */ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initWathiForm); } else { initWathiForm(); } /* Relance après soumission AJAX CF7 */ ['wpcf7mailsent','wpcf7invalid','wpcf7spam','wpcf7mailfailed'].forEach(function(ev){ document.addEventListener(ev, initWathiForm); }); })(); /** * WATHI × Ambassade d'Irlande — Contact Form 7 * Champs conditionnels + compteur de mots * * → Ajouter via "Insert Headers and Footers" (section Footer) * OU dans functions.php via wp_enqueue_scripts */ (function () { 'use strict'; function initWathiForm() { /* ── 1. Champ conditionnel : Nom d'organisation ── */ var orgRadios = document.querySelectorAll('input[name="organisation"]'); var orgBlock = document.getElementById('wf-orgblock'); if (orgRadios.length && orgBlock) { // État initial orgRadios.forEach(function (radio) { if (radio.checked && radio.value === 'Oui') orgBlock.classList.add('active'); radio.addEventListener('change', function () { orgBlock.classList.toggle('active', this.value === 'Oui'); }); }); } /* ── 2. Champ conditionnel : Autre plateforme ── */ var platCheckboxes = document.querySelectorAll('input[name="plateformes[]"]'); var autrePlatBlock = document.getElementById('wf-autreblock'); if (platCheckboxes.length && autrePlatBlock) { function checkAutre() { var autreChecked = Array.from(platCheckboxes).some(function (c) { return c.value === 'Autre' && c.checked; }); autrePlatBlock.classList.toggle('active', autreChecked); } platCheckboxes.forEach(function (cb) { cb.addEventListener('change', checkAutre); }); checkAutre(); } /* ── 3. Compteurs de mots ── */ var counters = document.querySelectorAll('.wf-wcount'); counters.forEach(function (counter) { var fieldName = counter.getAttribute('data-field'); var max = parseInt(counter.getAttribute('data-max'), 10) || 0; var span = counter.querySelector('span'); var textarea = document.querySelector('textarea[name="' + fieldName + '"]'); if (!textarea || !span) return; function update() { var trimmed = textarea.value.trim(); var count = trimmed === '' ? 0 : trimmed.split(/\s+/).length; span.textContent = count; if (max > 0) { counter.classList.toggle('over', count > max); } } textarea.addEventListener('input', update); update(); }); /* ── 4. Upload CV : afficher le nom du fichier ── */ var fileInputs = document.querySelectorAll('input[name="cv"]'); fileInputs.forEach(function (fileInput) { var titleEl = fileInput.closest('.wf-upload') ? fileInput.closest('.wf-upload').querySelector('.wf-upload-title') : null; if (!titleEl) return; var original = titleEl.textContent; fileInput.addEventListener('change', function () { if (this.files && this.files[0]) { titleEl.textContent = '✓ ' + this.files[0].name; titleEl.style.color = '#009A44'; } else { titleEl.textContent = original; titleEl.style.color = ''; } }); }); } /* Lance après chargement DOM */ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', initWathiForm); } else { initWathiForm(); } /* Relance après soumission AJAX CF7 */ ['wpcf7mailsent','wpcf7invalid','wpcf7spam','wpcf7mailfailed'].forEach(function(ev){ document.addEventListener(ev, initWathiForm); }); })();