var cmsCore = { mobile: 767, /* surchargeable localement */ tablet: 1024, /* surchargeable localement */ init: function () { 'use strict'; // gestion title lien externe/document $(' a.external, a.document').each(function () { var title = $(this).attr('title'); if (title === undefined) { title = $(this).clone(); $('[aria-hidden="true"]', title).remove(); title = title.text().trim(); if (title === '') { var $img = $('img', $(this)); if ($img.length) { title = $img.attr('alt').trim(); } } } if (title !== '') { if ($(this).hasClass('external')) { title += ' (nouvelle fenêtre)'; } else if ($(this).data('file_ext') !== undefined) { title += ' (' + $(this).data('file_ext'); if ($(this).data('file_weight') !== undefined) { title += ' - ' + $(this).data('file_weight'); } title += ')'; } $(this).attr('title', title.replace(/\s+/g, ' ')); } }); // Toggle ARIA $('.aria-toggle').on('click', function (e) { var $button = $(this); var $target = $('#' + $button.attr('aria-controls')); if ($button.attr('aria-expanded') === 'true') { // on ferme $target.attr('aria-hidden', 'true').slideUp().off('keydown.aria.' + $button.attr('id')); $button.attr('aria-expanded', 'false'); $('body').off('click.aria.' + $button.attr('id')); } else { // on ouvre $target.removeAttr('aria-hidden').slideDown(); $button.attr('aria-expanded', 'true'); // on focus $target.focus(); if (!$target.is(':focus')) { $target.attr('tabindex', '-1'); $target.focus(); } // echappe $target.on('keydown.aria.' + $button.attr('id'), function (ev) { if (ev.which === 27) { $button.trigger('click', [true]); $button.focus(); } }); // clic en dehors $('body').on('click.aria.' + $button.attr('id'), function (ev, triggered) { if (!triggered && !$(ev.target).closest($button).length && !$(ev.target).closest($target).length) { $button.trigger('click', [true]); } }); } e.preventDefault(); }); $('.aria-close').on('click', function (e) { $('#' + $(this).attr('aria-controls')).trigger('click', [true]); e.preventDefault(); }); // Défilement progessif au clic sur une ancre $(document).on('click', "a[href^='#']", function () { if (!$(this).hasClass('noScroll')) { cmsCore.scroll($($(this).attr('href'))); return false; } return true; }); //colorbox $('a.lightbox').colorbox({ title: function () { return $(this).data('title') !== '' ? $(this).data('title') : ' '; }, onComplete: function () { var alt = ''; if ($('img', this).attr('alt') !== $(this).data('title') && $('img', this).attr('alt') !== '') { alt = $('img', this).attr('alt'); } $('.cboxPhoto').attr('alt', alt); }, maxWidth: '95%', maxHeight: '95%' }); // credit image $('.spanCredit').hide(); $('.spanImgOuter').attr('tabindex', 0) .hover( function () { $('.spanCredit', this).fadeIn(); }, function () { $('.spanCredit', this).fadeOut(); } ) .on('focus', function () { $('.spanCredit', this).fadeIn(); }) .on('blur', function () { $('.spanCredit', this).fadeOut(); }); // Traitement rédactionnel $(".txt table:not('.tableNotResponsive'), .partage table:not('.tableNotResponsive'), .tpl table:not('.tableNotResponsive')").wrap('
'); // Lien d'évitement $('#lienEvitement').find('a') .on('focus', function () { $(this).closest('#lienEvitement').addClass('focus'); }) .on('blur', function () { $(this).closest('#lienEvitement').removeClass('focus'); }) .on('click', function () { if ($(this).hasClass('triggerClick')) { if ($(this).data('controls')) { var $e = $('#' + $(this).data('controls')); if ($e.is(':visible')) { $e.trigger('click', [true]); return false; } } else { $($(this).attr('href')).trigger('click', [true]); return false; } } return true; }); // Haut de page sticky var $hautDePage = $('#hautDePage'); $hautDePage.hide(); $(document).scroll(function () { if ($(window).scrollTop() > 1) { $hautDePage.show(400); } else { $hautDePage.hide(400); } }); // Google tracker pour les liens document + externe $(document).on('click', 'a.document', function () { window.open(this.href); return false; }); $(document).on('click', 'a.external', function () { window.open(this.href); return false; }); //gestion nb caractère max $('textarea[data-maxchar], input[data-maxchar]') .each(function () { $(this).attr('aria-describedby', $(this).attr('id') + '_max'); $(this).after(''); }) .on('keyup', function () { var $span = $(this).nextAll('span.counter'); $span.html('' + $(this).val().length + ' / ' + $(this).data('maxchar')); if ($(this).val().length > $(this).data('maxchar')) { $span.css('color', 'red'); } else { $span.css('color', ''); } }) .keyup(); //confirm $(document).on('click', '.confirm', function () { var str = 'Êtes-vous sûr'; if ($(this).attr('title') !== undefined && $(this).attr('title') !== '') { str += ' de vouloir\n"' + $(this).attr('title') + '"'; } str += ' ?'; return confirm(str); }); // gestion CB required $('div[data-required-cb], span[data-required-cb]').each(function () { var $cCB = $('input[type="checkbox"]', $(this)); var nb = $(this).data('required-cb'); $cCB.on('change', function () { if ($cCB.filter(':checked').length >= nb) { $cCB.each(function () { this.setCustomValidity(''); $(this).prop('required', false); }); } else { $cCB.filter(':not(:checked)').each(function () { this.setCustomValidity('Veuillez cocher au moins ' + nb + ' option(s)'); }); } }); if ($cCB.filter(':checked').length < $(this).data('required-cb')) { $cCB.filter(':not(:checked)').prop('required', true); } }); //type d'input $.datepicker.setDefaults($.datepicker.regional["fr"]); $('input[data-type="date"]') .attr('placeholder', 'jj/mm/aaaa') .attr('title', 'Format attendu : jj/mm/aaaa') .attr('pattern', '^(((0[1-9]|[12]\\d|3[01])/(0[13578]|1[02])/((19|[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)/(0[13456789]|1[012])/((19|[2-9]\\d)\\d{2}))|((0[1-9]|1\\d|2[0-8])/02/((19|[2-9]\\d)\\d{2}))|(29/02/((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$') .attr('maxlength', '10') .not('.noCalendar') .datepicker({ changeMonth: true, changeYear: true }); $('input[data-type="telephone"]') .attr('pattern', '^0[1-9][0-9]{8}$') .attr('title', 'Format attendu : numéro sur 10 chiffres sans espace'); $('input[data-type="integer"]') .attr('pattern', '^[0-9]*$') .attr('title', 'Format attendu : nombre entier') .addClass('alignright'); $('input[data-type="float"]') .attr('pattern', '^[0-9]*\.?[0-9]*$') .attr('title', 'Format attendu : nombre décimal') .addClass('alignright'); //gestion de l'étoile $('input[required], select[required], textarea[required]').not('input:checkbox, input:radio') .each(function () { $('label[for="' + $(this).attr('id') + '"]', $(this).closest('form')).append(' *'); }); $('input[required][type="checkbox"], input[required][type="radio"], div[data-required-cb], span[data-required-cb]').closest('p').find('label:first').append(' *'); //formatage virgule flottante $(document).on('keyup', 'input[data-type="float"]', function () { $(this).val($(this).val().replace(/,/, '.')); }); //formatage espace sur nombre $(document).on('keyup', 'input[data-type="float"], input[data-type="integer"]', function () { $(this).val($(this).val().replace(/\s/, '')); }); //formatage caractère sur téléphone $(document).on('keyup', 'input[data-type="telephone"]', function () { $(this).val($(this).val().replace(/\D/, '')); }); // Lecteur audio multi HTML5 (function () { var current = 0; var autoplay = true; // Pour chaque lecteur $('.audioPlayerMulti').each(function (i, player) { player = $(player); var audio = player.find('audio'); var playlist = player.find('.playlist'); var tracks = playlist.find('li a'); // Première piste active tracks.eq(0).parent().addClass('active'); // Choix des pistes tracks.click(function (e) { var $track = $(this); var li = $track.parent(); e.preventDefault(); // Remplacement des sources audio.find('source').remove(); var audioProperties = $track.data('audioProperties'); audio.append('