PageSourceSearch

https://cress-umr1153.fr/wp-content/themes/cress/vendor/mgdpr/mgdpr.js?ver=1.0.0

js cress-umr1153.fr collected 2026-10-02 08:07:07 UTC 15,817 bytes, 411 lines download raw bytes

1/* ==========================================================================
2@author: Thomas Rambaud
3@website: https://bonapp.studio
4@copyright 2021
5========================================================================== */
6var MGDPR = (function($){
7
8    var $doc = $(document);
9
10    var config = {
11        excludedUrls: [],
12        display: 'overlay',
13        i18n: {
14            title: 'Dear visitors,',
15            text: 'Our website www.domain.tld uses cookies to enhance your experience and provide usage statistics. You can accept all cookies, or manage your preferences as you wish.<br>' +
16            '<a href="/legals" target="_blank">Read more</a>',
17            managePreferences: 'Manage preferences',
18            managePreferencesTitle: 'Cookie Policy',
19            managePreferencesText: 'This site uses cookies deposited by the website, or by third parties.<br>' +
20            'This page allows you to determine your cookie preferences. For information, technical cookies are cookies necessary for the proper functioning of our site, used by the host for the technical management of the network. They allow you to use the main features of the site. They are essential to use the main functionalities of the site and therefore cannot be deactivated.',
21            savePreferences: 'Save my preferences',
22            refuseAll: 'Refuse all, but technical cookies',
23            acceptAll: 'Accept all',
24            acceptAllCookies: 'Accept all cookies',
25            accept: 'Accept',
26            allCookies: 'All cookies',
27            readMore: 'Read more',
28        },
29        cookies: [],
30        nullIsEnabled: true
31    };
32
33    return {
34        init: function(cfg){
35            for (var key in cfg) {
36                if (typeof config[key] != 'undefined') {
37                    config[key] = cfg[key];
38                }
39            }
40            
41            this.setup();
42
43            if(!this.excludedUrl() && !this.hasUserChose()){
44                this.showMainPopup();
45            }
46
47            this.ifsBlocks();
48        },
49
50        setDisplay: function(value){
51            config.display = value;
52            return this;
53        },
54
55        setNullIsEnabled: function(value){
56            config.nullIsEnabled = value;
57            return this;
58        },
59
60        getNullIsEnabled: function(){
61            return config.nullIsEnabled;
62        },
63
64        ifsBlocks: function(){
65            $('.mgdpr-if').each(function(){
66                var $this = $(this);
67                var cookieName = $this.data('cookie');
68                var code = $this.data('code');
69                var $text = $this.find('.mgdpr-if-text');
70
71                if(MGDPR.isEnabled(cookieName)){
72                    $this.replaceWith(code);
73                }else{
74                    $text.addClass('shown');
75                }
76            });
77        },
78
79		arrayContains: function(arr, obj){
80			var i = arr.length;
81			while (i--) {
82				if (arr[i] === obj) {
83					return true;
84				}
85			}
86			return false;
87		},
88
89        excludedUrl: function(){
90            return this.arrayContains(config.excludedUrls, window.location.pathname);
91        },
92
93        setCookiesList: function(cookies){
94            config.cookies = cookies;
95            return this;
96        },
97
98        getCookiesList: function(){
99            return config.cookies;
100        },
101
102        setExcludedUrls: function(excludedUrlsParam){
103            config.excludedUrls = excludedUrlsParam;
104            return this;
105        },
106
107        setI18n: function(i18n){
108            config.i18n = i18n;
109            return this;
110        },
111
112        buildPopupHtml: function(id, content){
113            var close = this.hasUserChose() ? '<span class="mgdpr-close">X</span>' : '';
114            return '<div class="mgdpr-popup ' + config.display + '" id="' + id + '">' +
115                '<div class="mgdpr-valign1">' +
116                    '<div class="mgdpr-valign2">' +
117                        '<div class="mgdpr-valign3">' +
118                            '<div class="mgdpr-popup-content">' +
119                                close +
120                                content +
121                            '</div>' +
122                        '</div>' +
123                    '</div>' +    
124                '</div>' +
125            '</div>';
126        },
127
128        isAllEnabled: function(){
129            for(var categoryIndex in config.cookies){
130                var cookieCategory = config.cookies[categoryIndex];
131                for(var cookieIndex in cookieCategory.list){
132                    var cookie = cookieCategory.list[cookieIndex];
133                    if(!this.isEnabled(cookie.name)){
134                        return false;
135                    }
136                }
137            }
138            return true;
139        },
140
141        isAllUnset: function(){
142            for(var categoryIndex in config.cookies){
143                var cookieCategory = config.cookies[categoryIndex];
144                for(var cookieIndex in cookieCategory.list){
145                    var cookie = cookieCategory.list[cookieIndex];
146                    if(this.cookieExists(cookie.name)){
147                        return false;
148                    }
149                }
150            }
151            return true;
152        },
153
154        isEnabled: function(cookieName){
155            var currentValue = this.getCookie('mgdpr_' + cookieName);
156            return (this.getNullIsEnabled() && currentValue === null) || currentValue == '1';
157        },
158
159        cookieExists: function(cookieName){
160            return this.getCookie('mgdpr_' + cookieName) !== null;
161        },
162
163        setup: function(){
164            var mainPopupHtml = this.buildPopupHtml('mgdpr-mainpopup', '<div class="mgdpr-title">' + config.i18n.title + '</div>' +
165            '<div class="mgdpr-text">' + config.i18n.text + '</div>' +
166            '<div class="mgdpr-buttons">' + 
167                '<a id="mgdpr-preferences" class="mgdpr-button" href="javascript:;">' + config.i18n.managePreferences + '</a>' +
168                '<a id="mgdpr-refuseall" class="mgdpr-button" href="javascript:;">' + config.i18n.refuseAll + '</a>' +
169                '<a id="mgdpr-acceptall" class="mgdpr-button" href="javascript:;">' + config.i18n.acceptAll + '</a>' +
170            '</div>');
171            $('body').append(mainPopupHtml);
172
173            var preferencesPopupHtml = '<div class="mgdpr-title">' + config.i18n.managePreferencesTitle + '</div>' +
174            '<div class="mgdpr-text">' + config.i18n.managePreferencesText + '</div>' +
175            '<div class="mgdpr-hr"></div>' +
176            '<div class="mgdpr-cookiescategory">' +
177                '<div class="mgdpr-cookiescategory-title">' + config.i18n.acceptAllCookies + '</div>' +
178                '<div class="mgdpr-cookie">' +
179                    '<div class="mgdpr-cookie-title">' + config.i18n.allCookies + '</div>' +
180                    '<button id="mgdpr-toggleall" class="mgdpr-toggle mgdpr-cantoggle' + (this.isAllEnabled() || this.isAllUnset() ? ' active' : '') + '"><span class="mgdpr-hidden">' + config.i18n.acceptAllCookies + '</span></button>' +
181                '</div>' +
182            '</div>';
183
184            for(var categoryIndex in config.cookies){
185                var cookieCategory = config.cookies[categoryIndex];
186                preferencesPopupHtml += '<div class="mgdpr-hr"></div><div class="mgdpr-cookiescategory">';
187
188                if(typeof cookieCategory.title != 'undefined'){
189                    preferencesPopupHtml += '<div class="mgdpr-cookiescategory-title">' + cookieCategory.title + '</div>';
190                }
191
192                if(typeof cookieCategory.text != 'undefined'){
193                    preferencesPopupHtml += '<div class="mgdpr-cookiescategory-text">' + cookieCategory.text + '</div>';
194                }
195
196                for(var cookieIndex in cookieCategory.list){
197                    var cookie = cookieCategory.list[cookieIndex];
198                    var isEnabled = this.isEnabled(cookie.name);
199                    var cookieExists = this.cookieExists(cookie.name);
200
201                    preferencesPopupHtml += '<div class="mgdpr-cookie" data-name="' + cookie.name + '">';
202
203                    if (typeof cookie.title != 'undefined') {
204                        preferencesPopupHtml += '<div class="mgdpr-cookie-title">' + cookie.title + '</div>';
205                    }
206
207                    if(typeof cookie.readMoreUrl != 'undefined'){
208                        var text = typeof cookie.readMoreText != 'undefined' ? cookie.readMoreText : config.i18n.readMore;
209                        preferencesPopupHtml += '<div class="mgdpr-cookie-readmore">' + 
210                            '<a href="' + cookie.readMoreUrl + '" target="_blank">' + text + '</a>' +
211                        '</div>';
212                    }
213
214                    if(typeof cookie.mention != 'undefined'){
215                        preferencesPopupHtml += '<div class="mgdpr-cookie-mention">' + 
216                            cookie.mention + 
217                        '</div>';
218                    }
219                    
220                    preferencesPopupHtml += '<button class="mgdpr-toggle' + ((typeof cookie.canToggle == 'undefined' || cookie.canToggle) ? (' mgdpr-cantoggle' + (isEnabled || !cookieExists ? ' active' : '')) : ' active mgdpr-canttoggle') + '"><span class="mgdpr-hidden">' + config.i18n.accept + '</span></button>';
221                    preferencesPopupHtml += '</div>';
222
223                    if(isEnabled && typeof cookie.onEnabled == 'function'){
224                        cookie.onEnabled(cookie);
225                    }
226                }
227
228                preferencesPopupHtml += '</div>';
229            }
230
231            preferencesPopupHtml += '<div class="mgdpr-hr"></div>';
232            preferencesPopupHtml += '<a id="mgdpr-savepreferences" class="mgdpr-button" href="javascript:;">' + config.i18n.savePreferences + '</a>';
233            preferencesPopupHtml = this.buildPopupHtml('mgdpr-preferencespopup', preferencesPopupHtml);
234            $('body').append(preferencesPopupHtml);
235
236            $('#mgdpr-preferences').on('click', function(e){
237                e.preventDefault();
238                MGDPR.hideMainPopup().showPreferencesPopup();
239            });
240
241            $('#mgdpr-refuseall').on('click', function(e){
242                e.preventDefault();
243                MGDPR.refuseAll(true);
244            });
245
246            $('#mgdpr-acceptall').on('click', function(e){
247                e.preventDefault();
248                MGDPR.acceptAll(true);
249            });
250
251            $('.mgdpr-cantoggle').on('click', function(e){
252                e.preventDefault();
253				var $this = $(this);
254                $this.toggleClass('active');
255
256				if(!$this.is('#mgdpr-toggleall')){
257					if($('.mgdpr-cantoggle').length == $('.mgdpr-cantoggle.active').length){
258						$('#mgdpr-toggleall').addClass('active');
259					}else{
260						$('#mgdpr-toggleall').removeClass('active');
261					}
262				}
263            });
264
265            $('#mgdpr-toggleall').on('click', function(e){
266                e.preventDefault();
267                var isActive = $(this).hasClass('active');
268                var $others = $('.mgdpr-cantoggle:not(#mgdpr-toggleall)');
269                if(isActive){
270                    $others.addClass('active');
271                }else{
272                    $others.removeClass('active');
273                }
274            });
275
276            $('#mgdpr-savepreferences').on('click', function(e){
277                e.preventDefault();
278                $('.mgdpr-cookie').each(function(){
279                    var $this = $(this);
280                    var cookieName = $this.data('name');
281
282                    if(typeof cookieName != 'undefined' && cookieName.length > 0){
283                        MGDPR.setCookie('mgdpr_' + cookieName, $this.find('.mgdpr-toggle.active').length > 0 ? '1' : '0');
284                    }
285                });
286                MGDPR.setUserChose();
287                window.location.reload();
288            });
289
290            $doc.on('click', '.mgdpr-manage-preferences', function(e){
291                e.preventDefault();
292                MGDPR.showPreferencesPopup();
293            });
294
295            $('.mgdpr-close').on('click', function(e){
296                e.preventDefault();
297                $(this).parents('.mgdpr-popup').fadeOut('fast');
298            });
299
300            if(this.hasUserChose()){
301                $('.mgdpr-popup').on('click', function(e){
302                    var $this = $(this);
303                    var $target = $(e.target);
304
305                    if(!$target.is('.mgdpr-popup-content') && $target.parents('.mgdpr-popup-content').length === 0){
306                        $this.fadeOut('fast');
307                    }
308                });
309            }
310
311            return this;
312        },
313
314        refuseAll: function(reloadPage){
315            this.setAll('0');
316            this.setUserChose();
317
318            if(typeof reloadPage != 'undefined' && reloadPage){
319                window.location.reload();
320            }
321
322            return this;
323        },
324
325        acceptAll: function(reloadPage){
326            this.setAll('1');
327            this.setUserChose();
328
329            if(typeof reloadPage != 'undefined' && reloadPage){
330                window.location.reload();
331            }
332
333            return this;
334        },
335
336        setAll: function(value){
337            for(var categoryIndex in config.cookies){
338                for(var cookieIndex in config.cookies[categoryIndex].list){
339                    MGDPR.setCookie('mgdpr_' + config.cookies[categoryIndex].list[cookieIndex].name, value);
340                }
341            }
342            return this;
343        },
344
345        showMainPopup: function(){
346            $('#mgdpr-mainpopup').fadeIn('fast');
347            return this;
348        },
349
350        hideMainPopup: function(){
351            $('#mgdpr-mainpopup').fadeOut('fast');
352            return this;
353        },
354
355        showPreferencesPopup: function(){
356            $('#mgdpr-preferencespopup').fadeIn('fast');
357            return this;
358        },
359
360        hidePreferencesPopup: function(){
361            $('#mgdpr-preferencespopup').fadeOut('fast');
362            return this;
363        },
364
365        hasUserChose: function(){
366            return this.getCookie('mgdpr_uc') == '1';
367        },
368
369        setUserChose: function(){
370            this.setCookie('mgdpr_uc', '1');
371            return this;
372        },
373
374        setCookie: function(name, value, days) {
375            if (typeof days == 'undefined') {
376                days = 6 * 31;
377            }
378
379            var date = new Date();
380            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
381            var expires = '; expires=' + date.toUTCString();
382
383            document.cookie = name + '=' + (value || '')  + expires + '; path=/';
384            return this;
385        },
386
387        getCookie: function(name) {
388            var nameEQ = name + '=';
389            var ca = document.cookie.split(';');
390
391            for(var i = 0; i < ca.length; i++) {
392                var c = ca[i];
393                while (c.charAt(0) == ' '){
394                    c = c.substring(1, c.length);
395                }
396
397                if (c.indexOf(nameEQ) == 0){
398                    return c.substring(nameEQ.length, c.length);
399                }
400            }
401
402            return null;
403        },
404
405        eraseCookie: function(name) {   
406            document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
407            return this;
408        }
409    }
410
411})(jQuery);

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.