/
pashko
/
siec
Обзор
Документация
Войти
/
pashko
/
siec
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/widgets/views/plashka.php
344 строки
10 KB
Pavel Kokorin
privacy
11 ноя 2025, 06:56
11 ноя 2025, 06:56
bc3a066
Код
Авторство
О чём код?
<meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Cookie Banner</title> <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500&display=swap" rel="stylesheet"> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Roboto', sans-serif; /* min-height: 100vh;*/ } .cookie-content-wrapper { max-width: 1200px; margin: 0 auto; } /* Overlay для мобильной версии */ .cookie-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); z-index: 9998; } .cookie-overlay.active { display: block; } /* Cookie Banner */ .cookie-banner { display: none; position: fixed; background: #2d2d2d; color: #ffffff; z-index: 9999; padding: 20px; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; } .cookie-banner.active { display: block; opacity: 1; visibility: visible; } .cookie-text a { color: #ffffff; } /* Десктопная версия */ @media (min-width: 769px) { .cookie-banner { bottom: 0; left: 0; right: 0; width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 16px 40px; } .cookie-content { display: flex; align-items: flex-start; gap: 30px; flex: 1; justify-content: space-between; } .cookie-text { font-size: 14px; margin-right: 20px; } .cookie-checkboxes { display: flex; gap: 20px; } } /* Checkbox стили */ .checkbox-item { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; } .checkbox-item input[type="checkbox"] { display: none; } .checkbox-custom { width: 20px; height: 20px; background: #2d2d2d; border: 2px solid #ffffff; position: relative; flex-shrink: 0; } .checkbox-item input[type="checkbox"]:checked + .checkbox-custom { background: #e31e24; border-color: #e31e24; } .checkbox-item input[type="checkbox"]:checked + .checkbox-custom::after { content: ''; position: absolute; left: 5px; top: 2px; width: 6px; height: 10px; border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg); } .checkbox-label { font-size: 13px; color: #ffffff; } @media (max-width: 768px) { .checkbox-label { font-size: 14px; } } /* Кнопка */ .cookie-button { background: #e31e24; color: #ffffff; border: none; padding: 10px 33px; font-size: 14px; font-family: 'Roboto', sans-serif; cursor: pointer; transition: background 0.3s; flex-shrink: 0; } .cookie-button:hover { background: #c51a1f; } /* Demo контент */ .demo-content { max-width: 1200px; margin: 0 auto; } .demo-content h1 { margin-bottom: 20px; } .demo-content p { line-height: 1.6; margin-bottom: 15px; } /* Мобильная версия */ @media (max-width: 768px) { .cookie-banner { top: 50%; left: 50%; transform: translate(-50%, -50%); width: calc(100% - 40px); max-width: 279px; border-radius: 4px; padding: 20px 16px; } .cookie-content-wrapper { display: flex; flex-direction: column-reverse; gap: 18px; } .cookie-content { display: flex; flex-direction: column; gap: 15px; } .cookie-text { font-size: 12px; text-align: left; line-height: 14px; margin-bottom: 10px; } .cookie-checkboxes { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .cookie-button { padding: 12px 2px; font-size: 12px; width: 100px; margin: 0 auto; } } </style> <!-- Overlay для мобильной версии --> <div class="cookie-overlay" id="cookieOverlay"></div> <!-- Cookie Banner --> <div class="cookie-banner" id="cookieBanner"> <div class="cookie-content-wrapper"> <div class="cookie-content"> <div class="cookie-text"> Подробнее <a href="/privacy" target="_blank">в политике ООО «Лигал-Импорт» в отношении cookie-файлов</a> </div> <button class="cookie-button" id="acceptButton">Хорошо</button> </div> <div class="cookie-checkboxes"> <label class="checkbox-item"> <input type="checkbox" id="analyticsCheckbox" checked> <span class="checkbox-custom"></span> <span class="checkbox-label">Аналитические cookie-файлы</span> </label> <label class="checkbox-item"> <input type="checkbox" id="technicalCheckbox" checked> <span class="checkbox-custom"></span> <span class="checkbox-label">Технические cookie-файлы</span> </label> </div> </div> </div> <script> // Проверка наличия cookie function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); return null; } // Установка cookie function setCookie(name, value, days) { const date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); const expires = `expires=${date.toUTCString()}`; document.cookie = `${name}=${value};${expires};path=/`; } // Показ баннера function showBanner() { const banner = document.getElementById('cookieBanner'); const overlay = document.getElementById('cookieOverlay'); const isMobile = window.innerWidth <= 768; banner.classList.add('active'); if (isMobile) { overlay.classList.add('active'); } } // Скрытие баннера function hideBanner() { const banner = document.getElementById('cookieBanner'); const overlay = document.getElementById('cookieOverlay'); banner.classList.remove('active'); overlay.classList.remove('active'); } // Инициализация window.addEventListener('DOMContentLoaded', () => { // Проверяем, есть ли уже согласие const cookieAccepted = getCookie('cookieAccepted'); if (!cookieAccepted) { // Показываем баннер через 3 секунды setTimeout(() => { showBanner(); }, 3000); } // Обработчик кнопки "Хорошо" document.getElementById('acceptButton').addEventListener('click', () => { const analyticsChecked = document.getElementById('analyticsCheckbox').checked; const technicalChecked = document.getElementById('technicalCheckbox').checked; // Сохраняем выбор пользователя setCookie('cookieAccepted', 'true', 10); setCookie('analyticsEnabled', analyticsChecked, 10); setCookie('technicalEnabled', technicalChecked, 10); hideBanner(); }); // Обработчик клика по overlay (только для мобильной версии) document.getElementById('cookieOverlay').addEventListener('click', () => { const analyticsChecked = document.getElementById('analyticsCheckbox').checked; const technicalChecked = document.getElementById('technicalCheckbox').checked; setCookie('cookieAccepted', 'true', 10); setCookie('analyticsEnabled', analyticsChecked, 10); setCookie('technicalEnabled', technicalChecked, 10); hideBanner(); }); // Обработчик изменения размера окна для управления overlay window.addEventListener('resize', () => { const banner = document.getElementById('cookieBanner'); const overlay = document.getElementById('cookieOverlay'); const isMobile = window.innerWidth <= 768; if (banner.classList.contains('active')) { if (isMobile) { overlay.classList.add('active'); } else { overlay.classList.remove('active'); } } }); }); </script>