app/template/tanzo/Block/cookie.twig line 1

Open in your IDE?
  1. {% if cookie %}
  2.     <div class="cookie-consent">
  3.         <div class="cookie-text">
  4.             当サイトでは、サイトの利便性向上のため、クッキー(Cookie)を使用しています。<!--<br>
  5.             Cookieの使用に関する詳細は<span class="policy-link"><a href="{{ url('help_privacy') }}" target="_blank" >「プライバシーポリシー」</a></span>をご覧ください。-->
  6.         </div>
  7.         <div class="cookie-agree">同意する</div>
  8.         <div class="cookie-reject d-none">拒否する</div>
  9.     </div>
  10.     {% block stylesheet %}
  11.         <style>
  12.             .cookie-consent {
  13.                 display: flex;
  14.                 justify-content: center;
  15.                 align-items: center;
  16.                 position: fixed;
  17.                 bottom: 0;
  18.                 width: 100%;
  19.                 font-size: 12px;
  20.                 color: #fff;
  21.                 background: rgba(0, 0, 0, .8);
  22.                 padding: 1.2em;
  23.                 box-sizing: border-box;
  24.                 visibility: hidden;
  25.                 z-index: 2147483647;
  26.             }
  27.             .cookie-consent.is-show {
  28.                 visibility: visible;
  29.             }
  30.             .policy-link, .policy-link :link, .policy-link :visited, .policy-link :hover, .policy-link :active {
  31.                 color: #0092C4;
  32.                 font-size: 15px;
  33.                 text-decoration: none;
  34.             }
  35.             .cookie-agree, .cookie-reject {
  36.                 color: #fff;
  37.                 padding: .5em 1.5em;
  38.                 margin-left: 20px;
  39.                 min-width: 84px;
  40.             }
  41.             .cookie-agree {
  42.                 background-color: #c8a353;
  43.                 min-width: 90px;
  44.                 text-align: center;
  45.             }
  46.             .cookie-reject {
  47.                 background: #9da3a9;
  48.                 min-width: 90px;
  49.                 text-align: center;
  50.             }
  51.             .cookie-agree:hover, .cookie-reject:hover {
  52.                 cursor: pointer;
  53.             }
  54.             .cookie-text .policy-link a {
  55.                 color: #c8a353!important;
  56.             }
  57.             .cc-hide {
  58.                 animation: hide 0.2s linear 0s;
  59.                 animation-fill-mode: forwards;
  60.             }
  61.             @keyframes hide {
  62.                 from {
  63.                     opacity: 1;
  64.                 }
  65.                 to {
  66.                     opacity: 0;
  67.                     visibility: hidden;
  68.                 }
  69.             }
  70.             @media screen and (max-width: 425px) {
  71.                 .cookie-consent {
  72.                     flex-direction: column;
  73.                 }
  74.                 .cookie-text {
  75.                     margin-bottom: 1.4em;
  76.                 }
  77.                 .cookie-agree{
  78.                     margin: 0 0 1em;
  79.                 }
  80.                 .cookie-reject {
  81.                     margin: 0;
  82.                 }
  83.             }
  84.         </style>
  85.     {% endblock %}
  86.     {% block javascript %}
  87.         <script type='text/javascript'>
  88.             (function() {
  89.                 const cookieConsent = document.querySelector('.cookie-consent');
  90.                 const cookieAgree = document.querySelector('.cookie-agree');
  91.                 const cookieReject = document.querySelector('.cookie-reject');
  92.                 const rejectFlag = sessionStorage.getItem('rejectFlag');
  93.                 const cookieData = document.cookie;
  94.                 let cookieSetFlag = false;
  95.                 const cookieDataList = cookieData.split('; ');
  96.                 for (const cookie of cookieDataList) {
  97.                     const cookieSplit = cookie.split('=');
  98.                     if (cookieSplit[0] === 'robotama-cookie') cookieSetFlag = true;
  99.                 }
  100.                 // Cookie同意の有効期限(日)をSetする
  101.                 const expire = {{ cookie_expiration_date }};
  102.                 function SetCookie(expire){
  103.                     const current = new Date();
  104.                     expire = current.getTime() + expire * 24 * 3600 * 1000;
  105.                     document.cookie = `robotama-cookie=robotama-read; expire=${expire}`;
  106.                 }
  107.                 function DeleteAllCookie(){
  108.                     const maxAgeZero = 'max-age=0';
  109.                     for (const cookie of cookieDataList) {
  110.                         const cookieSplit = cookie.split('=');
  111.                         document.cookie = `${cookieSplit[0]}=; ${maxAgeZero}`;
  112.                     }
  113.                 }
  114.                 function PopupDisplay(){
  115.                     cookieConsent.classList.add('is-show');
  116.                 }
  117.                 if (!cookieSetFlag && !rejectFlag) {
  118.                     PopupDisplay();
  119.                 }
  120.                 cookieAgree.addEventListener('click', ()=> {
  121.                     cookieConsent.classList.add('cc-hide');
  122.                     SetCookie(expire);
  123.                 });
  124.                 cookieReject.addEventListener('click', ()=> {
  125.                     cookieConsent.classList.add('cc-hide');
  126.                     sessionStorage.setItem('rejectFlag', true);
  127.                     DeleteAllCookie();
  128.                 });
  129.             }());
  130.         </script>
  131.     {% endblock %}
  132. {% endif %}