PageSourceSearch

https://cultura.gov.it/fe/mibact/js/cookies_consent.js

js cultura.gov.it collected 2026-09-24 07:35:54 UTC 4,193 bytes, 109 lines download raw bytes

1const iframes = document.getElementsByTagName("IFRAME");
2
3document.cookiesjsr = {
4    apiUrl: '',
5    configQuery: '/fe/mibact/js/cookiesjsr-config.json'
6}
7const getJson = async (url) => {
8    const response = await fetch(url);
9    return await response.json();
10};
11window.addEventListener('load', async (event) => {
12    const json = document.cookiesjsr.config;
13    let interfaceLang = json['interface'],
14        defaultLang = interfaceLang.defaultLang ?? 'it',
15        langApi = interfaceLang.translationQuery;
16    langApi = langApi.replace('%lang_id', defaultLang);
17    const langData = await getJson(langApi),
18        privacyUri = langData['privacyUri'];
19    document.cookiesjsr.config.privacyUri = privacyUri;
20    // Salvo consenso in database quando invio il form
21    let forms = document.getElementsByTagName('FORM');
22    Object.keys(forms).forEach(key => {
23        forms[key].addEventListener('submit', function (e) {
24            const that = this;
25            e.preventDefault();
26            let privacyField = $(this).find('input[name="'+json['privacy_field']+'"]');
27            if (privacyField.length) {
28                if($(privacyField).prop("checked") === false) {
29                    alert('L\'accettazione della privacy è obbligatoria');
30                    return false;
31                }
32                // Prendiamo i dati dal form
33                let formElement = e.target,
34                    formData = new FormData(formElement);
35                formData.append('privacyUri', privacyUri);
36                fetch('/saveConsent', {
37                    method: 'POST',
38                    body: formData
39                }).then(function (response) {
40                    return response.json();
41                }).then(function (data) {
42                    that.submit();
43                }).catch(function (error) {
44                    alert('Impossibile salvare il consenso nel database');
45                });
46            } else {
47                // Invio form
48                this.submit();
49            }
50        });
51    });
52
53});
54
55document.addEventListener('cookiesjsrCallbackResponse', function (e) {
56    console.log(e);
57});
58
59const dispatcher = {
60    matomo: {
61        activate: function () {
62            _paq.push(['rememberCookieConsentGiven']);
63        },
64        fallback: function () {
65            // Do stuff to fallback. E.g. display layer where the benefits are explained,
66            // when Matomo is enabled.
67        }
68    },
69    youtube: {
70        activate: function () {
71            // Cicliamo tutti gli iframes
72            Object.keys(iframes).forEach(key => {
73                if (iframes[key].hasAttribute('data-src')) {
74                    let src = iframes[key].getAttribute('data-src');
75                    iframes[key].removeAttribute('data-src');
76                    iframes[key].setAttribute('src', src);
77                    iframes[key].classList.remove('fallback');
78                }
79            });
80        },
81        fallback: function () {
82            Object.keys(iframes).forEach(key => {
83                if (iframes[key].hasAttribute('data-src') && !iframes[key].classList.contains('fallback')) {
84                    iframes[key].classList.add('fallback');
85                }
86            });
87        }
88    }
89}
90
91/**
92 * Entry to your custom code:
93 * Catch the Event 'cookiesjsrUserConsent' that comes with an object services inside the
94 * event object called with event.detail.services. It contains the current user decisions.
95 *
96 * This event is fired when DOM is loaded or user updates his settings.
97 */
98document.addEventListener('cookiesjsrUserConsent', function (event) {
99    var services = (typeof event.detail.services === 'object') ? event.detail.services : {};
100    for (var sid in services) {
101        if (typeof dispatcher[sid] === 'object') {
102            if (services[sid] === true && typeof dispatcher[sid].activate === 'function') {
103                dispatcher[sid].activate();
104            } else if (typeof dispatcher[sid].fallback === 'function') {
105                dispatcher[sid].fallback();
106            }
107        }
108    }
109});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.