PageSourceSearch

https://www.vibra-schultheis.de/bundles/ixtensacookienotice/js/logic.js

js vibra-schultheis.de collected 2026-10-09 22:50:10 UTC 9,371 bytes, 304 lines download raw bytes

1/**
2 *
3 * INFO: the firefox developer tools doesn't show
4 * localStorage data for permissionsGtm correctly
5 *
6 **/
7
8var permissions = [];
9var timeout = 1000;
10var flagConsentBanner = false;
11var body = document.body;
12
13window.addEventListener("load", function() {
14    if(flagConsentBanner) return;
15
16    // show banner
17    if(cnbGetItem('hideConsentBanner') === null) {
18        cnbSetItem('hideConsentPopup',true);
19        cnbRemoveItem('hideConsentBanner');
20    }
21
22    toggleBannerPopup();
23    getPermissions();
24    showConsentBannerIfDateExpired();
25
26    console.log('INFO: use as class or id the following names (showConsentBanner, showCookieNoticeBanner, showConsent or showCookieNotice) by a link to show consent banner again');
27    flagConsentBanner = true;
28
29    // show popup by click on settings or show consent buttons
30    var inputs = document.querySelectorAll('.showConsentBanner, .showCookieNoticeBanner, .showConsent, .showCookieNotice, #showConsentBanner, #showCookieNoticeBanner, #showConsent, #showCookieNotice');
31    for (i = 0; i < inputs.length; i++) {
32        inputs[i].addEventListener('click', function(e) {
33            cnbSetItem('hideConsentBanner', true);
34            cnbRemoveItem('hideConsentPopup');
35
36            toggleBannerPopup();
37            e.preventDefault();
38            e.stopPropagation();
39            return false;
40        });
41    }
42
43    // fired when dennyAll-Button in banner is clicked
44    // denyAll in banner
45    if(document.getElementById('cnb-denyAll')) {
46        document.getElementById('cnb-denyAll').onclick = function(e) {
47            permissions = [];
48            dataLayer.length = 0;
49            cnbRemoveItem('permissionsGtm');
50
51            checkBoxes.forEach(denyAllOptions);
52            setOnlyNecessary();
53
54            // hide popup and banner
55            cnbSetItem('hideConsentPopup', true);
56            cnbSetItem('hideConsentBanner', true);
57            cnbSetItem('permissionsGtm', JSON.stringify(permissions));
58
59            toggleBannerPopup();
60            getPermissions();
61            storeConsentData();
62        }
63    }
64
65    // fired when selectSpecific-Button in popup is clicked
66    // selectSpecific in popup
67    if(document.getElementById('cn-selectSpecific-Popup')) {
68        document.getElementById('cn-selectSpecific-Popup').onclick = function(e) {
69            permissions = [];
70            dataLayer.length = 0;
71            cnbRemoveItem('permissionsGtm');
72
73            checkBoxes.forEach(selectSpecificOptions);
74            e.stopPropagation();
75
76            // hide popup and banner
77            cnbSetItem('hideConsentPopup', true);
78            cnbSetItem('hideConsentBanner', true);
79            cnbSetItem('permissionsGtm', JSON.stringify(permissions));
80
81            toggleBannerPopup();
82            getPermissions();
83            storeConsentData();
84        }
85    }
86
87    // fired when selectAllCheckboxes-Button is clicked
88    // selectAllCheckboxes
89    var selectAll = document.querySelectorAll('#cn-selectAllCheckboxes, #cnb-selectAllCheckboxes');
90    if(selectAll) {
91        for (i = 0; i < selectAll.length; i++) {
92            selectAll[i].addEventListener('click', function(e) {
93                permissions = [];
94                cnbRemoveItem('permissionsGtm');
95
96                checkBoxes.forEach(selectAllOptions);
97
98                // hide popup and banner
99                cnbSetItem('hideConsentPopup', true);
100                cnbSetItem('hideConsentBanner', true);
101                cnbSetItem('permissionsGtm', JSON.stringify(permissions));
102
103                setTimeout(function() {
104                    document.getElementById('cookieNoticeBanner').className = "cookieNoticeBanner block";
105                    getPermissions();
106                }, timeout);
107
108                toggleBannerPopup();
109                storeConsentData();
110            });
111        }
112    }
113
114    // close Popup by click on close button
115    var closeButton = document.querySelectorAll('.close_popup');
116    if(closeButton) {
117        for (i = 0; i < closeButton.length; i++) {
118            closeButton[i].addEventListener('click', function(e) {
119                // hide popup and banner
120                cnbSetItem('hideConsentPopup', true);
121
122                if(cnbGetItem('permissionsGtm') === null) {
123                    cnbRemoveItem('hideConsentBanner');
124                }
125                toggleBannerPopup();
126            });
127        }
128    }
129});
130
131
132
133// show consent banner if date expired
134function showConsentBannerIfDateExpired() {
135    if(typeof(dateExpire) != 'undefined' && dateExpire != null) {
136        var storedDate = cnbGetItem('consentCheckedDate');
137        var selectedDuration = (dateExpire * 30 * 24 * 3600 * 1000);
138        var endDate = parseInt(storedDate) + parseInt(selectedDuration);
139
140        // console.log('Date stored: '+storedDate);
141        // console.log('Date duration: '+selectedDuration);
142        // console.log('Date end: '+endDate);
143
144        if(Date.now() >= endDate) {
145            forceHide = 1;
146            cnbRemoveItem('hideConsentBanner');
147        }
148    }
149}
150
151
152// show/hide details
153function reply_click(clicked_id) {
154
155    if(window.matchMedia('(max-width: 767px)').matches) {
156        if(document.getElementById('details-'+clicked_id).classList.contains('show')) {
157            document.getElementById('details-'+clicked_id).style.display = 'none';
158            document.getElementById('details-'+clicked_id).className = 'hide cnb-details';
159            return;
160        }
161    }
162
163    // hide all other details
164    var details = [...document.getElementsByClassName('cnb-details')];
165    details.forEach(function(elem) {
166        elem.style.display = 'none';
167        elem.className = 'hide cnb-details';
168    });
169
170    // show clicked detail
171    document.getElementById('details-'+clicked_id).className = " show cnb-details";
172    document.getElementById('details-'+clicked_id).style.display = 'block';
173
174    // highlight categorie buttons
175    var elems = document.querySelectorAll(".ui-state-active");
176    [].forEach.call(elems, function(el) {
177        el.classList.remove("ui-state-active");
178    });
179    document.getElementById(clicked_id).classList.add('ui-state-active');
180
181}
182
183
184// pushes all possible permissions into the dataLayer and localStorage
185function selectAllOptions(item, _index) {
186    addDatalayer(item);
187    permissions.push(item);
188}
189
190// push specificPermission into the dataLayer and locaStorage by popup
191function selectSpecificOptions(item, _index) {
192    if(document.getElementById('ck_'+item+'-Popup').checked) {
193        addDatalayer(item);
194        permissions.push(item);
195    }
196}
197
198// deny all - uncheck all options
199function denyAllOptions(item, _index) {
200    document.getElementById('ck_'+item+'-Popup').checked = false;
201}
202// push necessary into the dataLayer and localStorage by popup
203function setOnlyNecessary() {
204    addDatalayer('gtmNecessary');
205    permissions.push('gtmNecessary');
206}
207
208// fetches localy stored permissions
209function getPermissions() {
210    var permissionsLocal = cnbGetItem('permissionsGtm');
211
212    if(permissionsLocal !== null) {
213        JSON.parse(permissionsLocal).forEach(setPermissions);
214    }
215}
216
217// show consent
218function toggleBannerPopup() {
219    var timeInMs = Date.now();
220
221    var checkPopup = cnbGetItem('hideConsentPopup');
222    var elemPopup = document.getElementById('cookieNoticePopup');
223
224    var checkBanner = cnbGetItem('hideConsentBanner');
225    var elemBanner = document.getElementById('cookieNoticeBanner');
226
227    // show bopup
228    if (typeof(elemPopup) != 'undefined' && elemPopup != null) {
229        if(checkPopup === null && !forceHide) {
230            cnbSetItem('consentCheckedDate',timeInMs);
231
232            if(!elemPopup.classList.contains('show')) {
233                elemPopup.classList.add('show');
234                elemBanner.classList.remove('show');
235            }
236        }
237        else {
238            elemPopup.classList.remove('show');
239        }
240    }
241
242    // show banner on page bottom
243    if (typeof(elemBanner) != 'undefined' && elemBanner != null) {
244        if(checkBanner === null && !forceHide) {
245            cnbSetItem('consentCheckedDate',timeInMs);
246
247            if(!elemBanner.classList.contains('show')) {
248                elemBanner.classList.add('show');
249                elemPopup.classList.remove('show');
250            }
251        }
252        else {
253            elemBanner.classList.remove('show');
254        }
255    }
256}
257
258// push to the dataLayer
259function setPermissions(item, _index) {
260    addDatalayer(item);
261
262    // set items as active in popup
263    if(document.getElementById('ck_'+item+'-Popup')) {
264        document.getElementById('ck_'+item+'-Popup').checked = true;
265    }
266}
267
268// set item
269function cnbSetItem(k,v) {
270    localStorage.removeItem(k);
271    localStorage.setItem(k, v);
272}
273
274// get item
275function cnbGetItem(k) {
276    return localStorage.getItem(k);
277}
278
279// remove item
280function cnbRemoveItem(k) {
281    localStorage.removeItem(k);
282}
283
284// add item to dataLayer
285function addDatalayer(item) {
286    for(var i=0; i<dataLayer.length; i++) {
287        if(dataLayer[i]['event']==item) return false; // entry exists
288    }
289    dataLayer.push({'event': item});
290    return true;
291}
292
293// store checked permissions
294function storeConsentData() {
295    jQuery.post(
296        window.location.href,
297        {consentData: permissions, checkedDate: cnbGetItem('consentCheckedDate')},
298        'json' // 'text' or 'json'
299    );
300}
301
302function logging(v) {
303    console.log(v);
304}

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.