1const cmsCore = { 2 mobile: 767, 3 tablet: 1024, 4 5 init: function (aConf) { 6 Object.assign(this, aConf); 7 8 // gestion title lien externe/document 9 cmsCore.anchorInit($(document)); 10 11 // custom message input 12 $('input[type="email"]').on('change', function () { 13 if (this.validity.typeMismatch) { 14 this.setCustomValidity('Saisie invalide, format attendu : [email protected]'); 15 this.reportValidity(); 16 } else { 17 this.setCustomValidity(''); 18 } 19 }); 20 21 $('input[type="url"]').on('change', function () { 22 if (this.validity.typeMismatch) { 23 this.setCustomValidity('Saisie invalide, format attendu : https://www.nomdedomaine.com'); 24 this.reportValidity(); 25 } else { 26 this.setCustomValidity(''); 27 } 28 }); 29 30 /** 31 * Vérifie la validité d'un numéro de téléphone français 32 * @param {string} phoneNumber - Le numéro de téléphone à vérifier 33 * @returns {boolean} - Retourne `true` si le numéro est valide, sinon `false` 34 */ 35 function isValidFrenchPhoneNumber(phoneNumber) { 36 const frenchPhoneRegex = /^(?:\+33|0)[67]\d{8}$/; // Formats valides : +33639987654 ou 0739987654 37 return frenchPhoneRegex.test(phoneNumber); 38 } 39 40 $('input[type="tel"]').on('input', function (e) { 41 if (this.validity.typeMismatch || !isValidFrenchPhoneNumber(e.target.value)) { 42 this.setCustomValidity('Saisie invalide, exemple : 0639987654 ou +33739987654'); 43 this.reportValidity(); 44 } else { 45 this.setCustomValidity(''); 46 } 47 }); 48 49 $('form').on('submit', function () { 50 const $tel = $('input[type="tel"]'); 51 // On valide le format du téléphone à l'envoi du formulaire. 52 if ($tel.length > 0) { 53 $tel.each(function () { 54 if($tel.length > 0){ 55 $tel.each(function () { 56 if (!isValidFrenchPhoneNumber($tel[0].value)) { 57 $tel[0].setCustomValidity('Saisie invalide, exemple : 0639987654 ou +33739987654'); 58 return false; 59 } 60 }) 61 } 62 }) 63 } 64 return true; 65 }); 66 67 // Traitement rédactionnel 68 $('.txt table:not(\'.tableNotResponsive\'), .partage table:not(\'.tableNotResponsive\'), .tpl table:not(\'.tableNotResponsive\')').wrap('<div class="u-overflow-auto"/>'); 69 70 // Lien d'évitement 71 $('.js-skiplinks').find('a') 72 .on('focus', function () { 73 $(this).closest('.js-skiplinks').addClass('c-skiplinks--focus'); 74 }) 75 .on('blur', function () { 76 $(this).closest('.js-skiplinks').removeClass('c-skiplinks--focus'); 77 }) 78 .on('click', function () { 79 if ($(this).hasClass('trigger-click')) { 80 if ($(this).data('controls')) { 81 const $e = $('#' + $(this).data('controls')); 82 if ($e.is(':visible')) { 83 $e.trigger('click', [true]); 84 } 85 } else { 86 $($(this).attr('href')).trigger('click', [true]); 87 return false; 88 } 89 } 90 91 $($(this).attr('href')).focus(); 92 return false; 93 }); 94 95 const $lightbox = $('.js-lightbox'); 96 if ($lightbox.length > 0) { 97 $lightbox.attr('data-fancybox', 'cms'); 98 $lightbox.each((i, current) => { 99 current.setAttribute('data-thumb', current.href) 100 }); 101 Fancybox.defaults.Hash = false; 102 Fancybox.bind('[data-fancybox="cms"]', { 103 Thumbs: {showOnStart: false}, 104 l10n: Fancybox.l10n.fr, 105 caption: function (fancybox, slide) { 106 return slide.triggerEl?.getAttribute('data-title') || ""; 107 } 108 }); 109 } 110 111 //gestion nb caractère max 112 $('textarea[data-maxchar], input[data-maxchar]') 113 .each(function () { 114 $(this).attr('aria-describedby', $(this).attr('id') + '_max'); 115 $(this).after('<span class="counter" id="' + $(this).attr('id') + '_max' + '" aria-live="polite"></span>'); 116 }) 117 .on('keyup', function () { 118 var $span = $(this).nextAll('span.counter'); 119 $span.html('Nombre de caractères : ' + $(this).val().length + ' / ' + $(this).data('maxchar')); 120 if ($(this).val().length > $(this).data('maxchar')) { 121 $span.css('color', 'red'); 122 } else { 123 $span.css('color', ''); 124 } 125 }) 126 .keyup(); 127 128 //confirm 129 $(document).on('click', '.confirm', function () { 130 let str = 'Ãtes-vous sûr'; 131 if ($(this).attr('title') !== undefined && $(this).attr('title') !== '') { 132 str += ' de vouloir\n"' + $(this).attr('title') + '"'; 133 } 134 str += ' ?'; 135 return confirm(str); 136 }); 137 138 // gestion CB required 139 $('div[data-required-cb], span[data-required-cb]').each(function () { 140 const $cCB = $('input[type="checkbox"]', $(this)); 141 const nb = $(this).data('required-cb'); 142 $cCB.on('change', function () { 143 if ($cCB.filter(':checked').length >= nb) { 144 $cCB.each(function () { 145 this.setCustomValidity(''); 146 $(this).prop('required', false); 147 }); 148 } else { 149 $cCB.filter(':not(:checked)').each(function () { 150 this.setCustomValidity('Veuillez cocher au moins ' + nb + ' option(s)'); 151 }); 152 153 } 154 }); 155 if ($cCB.filter(':checked').length < $(this).data('required-cb')) { 156 $cCB.filter(':not(:checked)').prop('required', true); 157 } 158 }); 159 160 //gestion de l'étoile 161 $('input[required], select[required], textarea[required]').not('input:checkbox, input:radio').each(function () { 162 $('label[for="' + $(this).attr('id') + '"]', $(this).closest('form')).append(' <span class="obligatoire">*</span>'); 163 }); 164 $('input[required][type="checkbox"], input[required][type="radio"], div[data-required-cb], span[data-required-cb]').closest('fieldset').find('legend').append(' <span class="obligatoire">*</span>'); 165 166 // Lecteur audio multi HTML5 167 $('.c-audio--multi').each(function () { 168 const $audio = $(this).find('audio'); 169 const $playlist = $(this).find('.c-audio__playlist'); 170 const $cTrack = $playlist.find('li a'); 171 let current = 0; 172 173 // Première piste active 174 $cTrack.eq(0).addClass('c-audio__track--active'); 175 176 // Choix des pistes 177 $cTrack.on('click', function (e) { 178 e.preventDefault(); 179 180 // Remplacement des sources 181 $audio.find('source').remove(); 182 $audio.append('<source type="audio/mp3" src="' + $(this).attr('href') + '">'); 183 if ($(this).data('srcogg')) { 184 $audio.append('<source type="audio/ogg" src="' + $(this).data('srcogg') + '">'); 185 } 186 187 // Changement de la piste active 188 $cTrack.removeClass('c-audio__track--active'); 189 $(this).addClass('c-audio__track--active'); 190 current = $(this).closest('li').index(); 191 192 // Reload, lecture de la piste, focus 193 $audio.get(0).load(); 194 $audio.get(0).play(); 195 $audio.focus(); 196 }); 197 198 // Piste suivante 199 $audio.on('ended', function () { 200 current = current >= $cTrack.length - 1 ? 0 : current + 1; 201 $cTrack.eq(current).trigger('click'); 202 }); 203 }); 204 }, 205 anchorInit: function ($root) { 206 $('a.external, a.document', $root) 207 .each(function () { 208 let title = $(this).attr('title'); 209 if (title === undefined) { 210 title = $(this).clone(); 211 $('[aria-hidden="true"]', title).remove(); 212 title = title.text().trim(); 213 if (title === '') { 214 const $img = $('img', $(this)); 215 if ($img.length) { 216 title = $img.attr('alt').trim(); 217 } 218 } 219 } 220 if (title !== '') { 221 if ($(this).hasClass('external')) { 222 title += ' ' + cmsCore.title_newwindow; 223 } else if ($(this).data('file_ext') !== undefined) { 224 title += ' (' + $(this).data('file_ext'); 225 if ($(this).data('file_weight') !== undefined) { 226 title += ' - ' + $(this).data('file_weight'); 227 } 228 title += ')'; 229 } 230 $(this).attr('title', title.replace(/\s+/g, ' ')); 231 } 232 }) 233 .on('click', function () { 234 window.open(this.href); 235 return false;
236 }); 237 }, 238};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.