/** * SiteForge Privacy Manager * Gestisce il consenso ai cookie e la privacy (GDPR/CCPA compliant basics). * * Utilizzo: * 1. Includi questo script: * 2. Inizializza: * PrivacyManager.init({ * policyUrl: '/privacy-policy', * cookiePolicyUrl: '/cookie-policy' * }); */ $( document ).ready(function() {PrivacyManager.init({policyUrl: '/privacy-policy.htm', cookiePolicyUrl: '/cookie-policy.html'});}); const PrivacyManager = (function () { const STORAGE_KEY = 'siteforge_privacy_consent'; // Default config let config = { policyUrl: '#', cookiePolicyUrl: '#', autoBlock: true // Blocca script src se non autorizzati (richiede gestione specifica) }; let consent = { necessary: true, // Sempre true analytics: false, marketing: false, timestamp: null }; // --- UI TEMPLATES --- const css = ` #sf-privacy-banner { position: fixed; bottom: 0; left: 0; width: 100%; background: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,0.1); padding: 20px; font-family: sans-serif; font-size: 14px; z-index: 99999; display: none; flex-direction: column; gap: 15px; border-top: 1px solid #eee; } @media (min-width: 768px) { #sf-privacy-banner { flex-direction: row; align-items: center; justify-content: space-between; padding: 20px 40px; } } .sf-privacy-buttons { display: flex; gap: 10px; flex-wrap: wrap; } .sf-btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; font-weight: 600; font-size: 13px; } .sf-btn-primary { background: #1a73e8; color: white; } .sf-btn-secondary { background: #f1f3f4; color: #333; } .sf-btn-link { background: none; text-decoration: underline; color: #555; } #sf-privacy-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 100000; display: none; align-items: center; justify-content: center; } .sf-privacy-modal-content { background: white; padding: 30px; border-radius: 8px; width: 90%; max-width: 500px; max-height: 90vh; overflow-y: auto; font-family: sans-serif; } .sf-switch-group { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid #eee; } .sf-switch-label { font-weight: bold; display: block; } .sf-switch-desc { font-size: 12px; color: #666; display: block; margin-top: 5px; } `; function init(userConfig) { config = { ...config, ...userConfig }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', runStartLogic); } else { runStartLogic(); } } function runStartLogic() { // Load saved consent const saved = localStorage.getItem(STORAGE_KEY); if (saved) { consent = JSON.parse(saved); // Apply saved consent (e.g. enable scripts) applyConsent(); } else { // Show Banner injectStyles(); injectBanner(); } } function injectStyles() { const style = document.createElement('style'); style.textContent = css; document.head.appendChild(style); } function injectBanner() { $('#sf-privacy-banner').remove(); if (document.getElementById('sf-privacy-banner')) return; const banner = document.createElement('div'); banner.id = 'sf-privacy-banner'; banner.innerHTML = `
Questo sito utilizza i cookie.

Utilizziamo cookie tecnici e, previo consenso, cookie di profilazione e analitici per migliorare la tua esperienza. Puoi gestire le tue preferenze o accettare tutti i cookie. Leggi la Privacy Policy.

`; document.body.appendChild(banner); // Animations setTimeout(() => banner.style.display = 'flex', 100); // Events document.getElementById('sf-privacy-accept').onclick = acceptAll; document.getElementById('sf-privacy-reject').onclick = rejectAll; document.getElementById('sf-privacy-settings').onclick = openSettings; } function injectSettingsModal() { if (document.getElementById('sf-privacy-modal')) { document.getElementById('sf-privacy-modal').style.display = 'flex'; return; } const modal = document.createElement('div'); modal.id = 'sf-privacy-modal'; modal.innerHTML = `

Preferenze Privacy

Gestisci il consenso per le diverse categorie di cookie.

Necessari Indispensabili per il funzionamento del sito. Non possono essere disattivati.
Analitici Ci aiutano a capire come visiti il sito (es. Google Analytics).
Marketing Usati per inviare pubblicità mirata (es. Facebook Pixel).
`; document.body.appendChild(modal); modal.style.display = 'flex'; // Events document.getElementById('sf-modal-cancel').onclick = () => { modal.style.display = 'none'; }; document.getElementById('sf-modal-save').onclick = () => { consent.analytics = document.getElementById('sf-consent-analytics').checked; consent.marketing = document.getElementById('sf-consent-marketing').checked; saveConsent(); modal.style.display = 'none'; }; } function acceptAll() { consent.analytics = true; consent.marketing = true; saveConsent(); } function rejectAll() { consent.analytics = false; consent.marketing = false; saveConsent(); } function openSettings() { injectSettingsModal(); } function saveConsent() { consent.timestamp = new Date().toISOString(); localStorage.setItem(STORAGE_KEY, JSON.stringify(consent)); const banner = document.getElementById('sf-privacy-banner'); if (banner) banner.style.display = 'none'; applyConsent(); } function applyConsent() { console.log("SiteForge Privacy: Consent Applied", consent); // Event for other scripts const event = new CustomEvent('siteforge-consent-update', { detail: consent }); window.dispatchEvent(event); // Example: Enable Google Analytics if accepted if (consent.analytics) { enableAnalytics(); } } function enableAnalytics() { // Here you would typically inject the GA script tag dynamically // or change types from text/plain to text/javascript // Example logic needed here based on user specific scripts } // Public API return { init: init, openSettings: openSettings, getConsent: () => consent }; })(); $(document).ready(function () { // Riassunto automatico: testo pulito dall'HTML del contenuto (esclude