templates/_cookie_consent.html.twig line 1

Open in your IDE?
  1. {# Discreet cookie consent banner partial #}
  2. <div id="cookie-consent-banner" role="dialog" aria-label="Choix des cookies" aria-live="polite" style="display:none;position:fixed;bottom:1rem;right:1rem;z-index:10000;background:#1e1e1e;color:#fff;padding:.75rem 1rem;border-radius:999px;box-shadow:0 4px 14px rgba(0,0,0,.25);font-size:.75rem;line-height:1.2;font-family:Montserrat, Arial, sans-serif;">
  3.   <span style="margin-right:.5rem;">Acceptation des cookies ?</span>
  4.   <button id="cookie-accept" type="button" style="background:#0d6efd;border:none;color:#fff;padding:.35rem .7rem;border-radius:999px;font-size:.7rem;cursor:pointer;">OK</button>
  5.   <button id="cookie-decline" type="button" style="background:#444;border:none;color:#fff;padding:.35rem .7rem;border-radius:999px;font-size:.7rem;cursor:pointer;margin-left:.3rem;">Non</button>
  6.   <button id="cookie-close" type="button" style="background:transparent;border:none;color:#bbb;padding:.35rem .4rem;font-size:.8rem;cursor:pointer;margin-left:.2rem;" aria-label="Fermer">×</button>
  7.   <a href="/mentionlegales" style="color:#9ecfff;margin-left:.3rem;text-decoration:none;font-size:.65rem;">Infos</a>
  8. </div>
  9. <script>
  10. (function(){
  11.   const banner = document.getElementById('cookie-consent-banner');
  12.   function parseConsent(){
  13.     const m = document.cookie.match(/(^|;)\s*cookie_consent=([^;]+)/);
  14.     if(!m) return null;
  15.     try { return JSON.parse(decodeURIComponent(m[2])); } catch(e){ return null; }
  16.   }
  17.   function setConsent(obj){
  18.     const expires = new Date(Date.now()+365*24*3600*1000).toUTCString();
  19.     document.cookie = 'cookie_consent='+encodeURIComponent(JSON.stringify(obj))+';expires='+expires+';path=/;SameSite=Lax';
  20.   }
  21.   function ensureHubspot(){
  22.     if(document.getElementById('hs-script-loader')) return;
  23.     const s = document.createElement('script');
  24.     s.type='text/javascript';
  25.     s.id='hs-script-loader';
  26.     s.async=true; s.defer=true;
  27.     s.src='//js-eu1.hs-scripts.com/147164794.js';
  28.     document.head.appendChild(s);
  29.   }
  30.   function show(){ banner.style.display='flex'; banner.style.alignItems='center'; }
  31.   function hide(){ banner.style.display='none'; }
  32.   const consent = parseConsent();
  33.   if(!consent){ show(); }
  34.   else if(consent.analytics === true){ ensureHubspot(); }
  35.   document.getElementById('cookie-accept').addEventListener('click', function(){
  36.     setConsent({analytics:true});
  37.     ensureHubspot();
  38.     hide();
  39.   });
  40.   document.getElementById('cookie-decline').addEventListener('click', function(){
  41.     setConsent({analytics:false});
  42.     hide();
  43.   });
  44.   document.getElementById('cookie-close').addEventListener('click', hide);
  45.   // Expose reopen for footer link
  46.   window.showCookieBanner = function(){ show(); };
  47. })();
  48. </script>