PageSourceSearch

https://manodelfriki.com/modules/gdprpro//views/js/gdpr-consent.js

js manodelfriki.com collected 2026-10-04 13:24:44 UTC 17,446 bytes, 388 lines download raw bytes

1/**
2 * PrestaChamps
3 *
4 * NOTICE OF LICENSE
5 *
6 * This source file is subject to the Commercial License
7 * you can't distribute, modify or sell this code
8 *
9 * DISCLAIMER
10 *
11 * Do not edit or add to this file
12 * If you need help please contact [email protected]
13 *
14 * @author    PrestaChamps <[email protected]>
15 * @copyright PrestaChamps
16 * @license   commercial
17 */
18;(function ($, window, document, undefined) {
19
20    "use strict";
21
22    var pluginName = "prestaGdprConsent";
23    var defaults = {
24        content: "",
25        showOnPageLoad: false,
26        animateTabChange: false,
27        cookieStoreUrl: "/",
28        modules: {},
29        checkAllByDefault: true,
30        reloadAfterSave: false,
31        reloadAfterAcceptAll: false,
32        under18AlertText: "You need to be 18+ to visit this site",
33        closeModalOnlyWithButtons: false,
34        acceptByScroll: false
35    };
36
37    function Plugin(element, options) {
38        this.element = element;
39        this.settings = $.extend({}, defaults, options);
40        this.settings.acceptByScroll = options.acceptByScroll;
41        this._defaults = defaults;
42        this._name = pluginName;
43        this.init();
44    }
45
46    $.extend(Plugin.prototype, {
47        init: function () {
48            var that = this;
49            $(document).on("gdprModuleCheckBoxesChanged", function () {
50                that.updateSelectedModules();
51            });
52            var instance = gdprModal.create(
53                this.settings.content,
54                {
55                    closable: !that.settings.closeModalOnlyWithButtons
56                }
57            );
58            instance.init();
59
60            if (that.settings.checkAllByDefault && typeof(this.settings.showOnPageLoad) !== "undefined" && this.settings.showOnPageLoad) {
61                for (var key in that.settings.modules) {
62                    that.settings.modules[key] = "true";
63                }
64            }
65            this.mdlCheckboxes = $('.module-cookies-chkbox');
66            this.initTabs();
67            this.initCheckboxes();
68
69            $('#close-gdpr-consent').on('click', function () {
70                if (that.settings.reloadAfterSave) {
71                    $(document).ajaxStop(function () {
72                        location.reload();
73                    });
74                }
75                instance.close();
76                that.saveSettingsToCookie();
77            });
78            $(document).on('click', '#under-18', function (event) {
79                if (confirm(that.settings.under18AlertText) !== true) {
80                    window.location.href = "about:blank";
81                }
82                $(this).removeClass('all_checked');
83                $(this).addClass('not_checked');
84                event.preventDefault();
85                event.stopPropagation();
86            });
87            if (this.settings.showOnPageLoad) {
88                instance.show();
89            }
90
91            $('.show-gdpr-modal').on('click', function () {
92                instance.show();
93                return false;
94            });
95            this.postInit();
96            $(document).on('gdprModuleCheckBoxesChanged', function (event, name, isEnabled) {
97                name = name.replace("_","-");
98                if (isEnabled) {
99                    $('body').removeClass(name + "-off").addClass(name + "-on");
100                } else {
101                    $('body').removeClass(name + "-on").addClass(name + "-off");
102                }
103            });
104
105            var acceptByScroll = gdprSettings.acceptByScroll;
106            console.log(acceptByScroll);
107            $(window).scroll(function () {
108                if (acceptByScroll && $('.gdprModal').is(":visible")) {
109                    instance.close();
110                    that.saveSettingsToCookie();
111                }
112            });
113        },
114        updateSelectedModules: function () {
115            $('#gdpr-selected-count').text($('.module-cookies-chkbox:checked').length);
116        },
117        /**
118         * Initiate the tabs
119         */
120        initTabs: function () {
121            /**
122             * Init the modal tabs
123             */
124            var tabs = $('.gdpr-consent-tabs');
125
126            tabs.each(function () {
127                var tab = $(this),
128                    tabItems = tab.find('ul.gdpr-consent-tabs-navigation'),
129                    tabContentWrapper = tab.find('ul.gdpr-consent-tabs-content'),
130                    tabNavigation = tab.find('nav');
131
132                tabItems.on('click', 'a', function (event) {
133                    var selectedItem = $(this);
134                    if ($(selectedItem).attr("href")) {
135                        return true;
136                    }
137                    event.preventDefault();
138                    if (!selectedItem.hasClass('selected')) {
139                        var selectedTab = selectedItem.data('content'),
140                            selectedContent = tabContentWrapper.find('li[data-content="' + selectedTab + '"]'),
141                            slectedContentHeight = window.innerHeight * 0.8;
142
143                        tabItems.find('a.selected').removeClass('selected');
144                        selectedItem.addClass('selected');
145                        selectedContent.addClass('selected').siblings('li').removeClass('selected');
146                    }
147                });
148
149                //hide the .gdpr-consent-tabs::after element when tabbed navigation has scrolled to the end (mobile version)
150                checkScrolling(tabNavigation);
151                tabNavigation.on('scroll', function () {
152                    checkScrolling($(this));
153                });
154            });
155            tabs.each(function () {
156                var tab = $(this);
157                checkScrolling(tab.find('nav'));
158                //tab.find('.gdpr-consent-tabs-content').css('height', window.innerHeight * 0.8);
159            });
160            $(window).on('resize', function () {
161                tabs.each(function () {
162                    var tab = $(this);
163                    checkScrolling(tab.find('nav'));
164                    //tab.find('.gdpr-consent-tabs-content').css('height', window.innerHeight * 0.8);
165                });
166            });
167
168            function checkScrolling(tabs) {
169                var totalTabWidth = parseInt(tabs.children('.gdpr-consent-tabs-navigation').width()),
170                    tabsViewport = parseInt(tabs.width());
171                if (tabs.scrollLeft() >= totalTabWidth - tabsViewport) {
172                    tabs.parent('.gdpr-consent-tabs').addClass('is-ended');
173                } else {
174                    tabs.parent('.gdpr-consent-tabs').removeClass('is-ended');
175                }
176            }
177        },
178        initCheckboxes: function () {
179            var that = this;
180            this.mdlCheckboxes.each(function () {
181                this.addEventListener('change', function (event) {
182                    console.log(this);
183                    that.settings.modules[$(this).data('mdl')] = this.checked;
184                    that.saveSettingsToCookie();
185                    $(document).trigger("gdprModuleCheckBoxesChanged", [$(this).data('mdl'), this.checked]);
186                    if (this.checked) {
187                        $(this).closest(".td_checkbox").addClass('allowed');
188
189                        $('.div_cookie_category #span_under_16').removeClass('all_checked').addClass('not_checked');
190                    }
191                    else {
192                        $(this).closest(".td_checkbox").removeClass('allowed');
193                    }
194
195                    var category_stat = 'not_checked';
196                    var not_checked_checkboxes = $(this).closest(".cookie-category-tab").find('.module-cookies-chkbox:not(:checked)').length;
197                    var checked_checkboxes = $(this).closest(".cookie-category-tab").find('.module-cookies-chkbox:checked').length;
198                    var checkboxes = $(this).closest(".cookie-category-tab").find('.module-cookies-chkbox').length;
199                    if (checked_checkboxes == checkboxes) {
200                        category_stat = 'all_checked';
201                    }
202                    else {
203                        if (not_checked_checkboxes == checkboxes) {
204                            category_stat = 'not_checked';
205                        }
206                        else {
207                            category_stat = 'partial_checked';
208                        }
209                    }
210
211                    var checkboxgroup = $(this).closest(".cookie-category-tab");
212
213                    $('.div_summary_checkboxes .div_cookie_category').each(function () {
214                        var cookiecategory = $(this).attr('id');
215                        if (checkboxgroup.hasClass(cookiecategory)) {
216                            $(this).children('span').removeClass().addClass('span-preferences').addClass(category_stat);
217                        }
218                    });
219                });
220
221                try {
222                    var moduleName = $(this).data('mdl');
223                    if (that.settings.modules[moduleName] === "true") {
224                        this.checked = true;
225                        $(this).closest(".td_checkbox").addClass('allowed');
226                    }
227                    else {
228                        $(this).closest(".td_checkbox").removeClass('allowed');
229                    }
230                } catch (error) {
231                    console.error(error);
232                }
233            });
234            $(document).trigger("gdprModuleCheckBoxesChanged");
235            $(document).on('click', '#gdpr-check-all-modules', function () {
236                $(this).closest('.table').find('.module-cookies-chkbox:not(:checked)').trigger('click');
237                $('.div_cookie_category #span_under_16').removeClass('all_checked').addClass('not_checked');
238            });
239            $(document).on('click', '#accept-all-gdpr', function () {
240                if (that.settings.reloadAfterAcceptAll) {
241                    $(document).ajaxStop(function () {
242                        location.reload();
243                    });
244                }
245                $('.module-cookies-chkbox:not(:checked)').trigger('click');
246                $('#close-gdpr-consent').trigger('click');
247
248                $('.div_cookie_category #span_under_16').removeClass('all_checked').addClass('not_checked');
249            });
250        },
251        saveSettingsToCookie: function () {
252            $.post(this.settings.cookieStoreUrl, {gdprSettings: this.settings.modules});
253        },
254        postInit: function () {
255
256            $('.div_summary_checkboxes .div_cookie_category').each(function () {
257                var cookiecategory = $(this).attr('id');
258                var category_stat = 'not_checked';
259                $('.gdpr-consent-tabs-content li').each(function () {
260                    if ($(this).hasClass(cookiecategory)) {
261                        var not_checked_checkboxes = $(this).find('.module-cookies-chkbox:not(:checked)').length;
262                        var checked_checkboxes = $(this).find('.module-cookies-chkbox:checked').length;
263                        var checkboxes = $(this).find('.module-cookies-chkbox').length;
264                        if (checked_checkboxes == checkboxes) {
265                            category_stat = 'all_checked';
266                        }
267                        else {
268                            if (not_checked_checkboxes == checkboxes) {
269                                category_stat = 'not_checked';
270                            }
271                            else {
272                                category_stat = 'partial_checked';
273                            }
274                        }
275                    }
276                });
277                $(this).children('span').addClass(category_stat);
278            });
279
280            $('.div_summary_checkboxes .div_cookie_category').on('click', function () {
281                if ($(this).hasClass('div_under_16')) {
282                    $('.module-cookies-chkbox:checked').trigger('click');
283                    //$('.module-cookies-chkbox:checked').prop("disabled", true);
284
285                    if ($('.div_summary_checkboxes .div_cookie_category:not(#div_necessary):not(.div_under_16) > span').hasClass('all_checked')) {
286                        $('.div_summary_checkboxes .div_cookie_category:not(#div_necessary):not(.div_under_16) > span').removeClass('all_checked').addClass('not_checked');
287                    }
288                    else {
289                        if ($('.div_summary_checkboxes .div_cookie_category:not(#div_necessary):not(.div_under_16) > span').hasClass('partial_checked')) {
290                            $('.div_summary_checkboxes .div_cookie_category:not(#div_necessary):not(.div_under_16) > span').removeClass('partial_checked').addClass('not_checked');
291                        }
292                    }
293
294                    if ($(this).children('span').hasClass('not_checked')) {
295                        $(this).children('span').removeClass('not_checked').addClass('all_checked');
296                    }
297                    else {
298                        if ($(this).children('span').hasClass('all_checked')) {
299                            $(this).children('span').removeClass('all_checked').addClass('not_checked');
300                        }
301                    }
302                }
303                else {
304                    var cookiecategory = $(this).attr('id');
305                    if (cookiecategory != 'div_necessary') {
306                        if ($(this).children('span').hasClass('not_checked') || $(this).children('span').hasClass('partial_checked')) {
307                            $('.gdpr-consent-tabs-content li').each(function () {
308                                if ($(this).hasClass(cookiecategory)) {
309                                    $(this).find('.module-cookies-chkbox:not(:checked)').trigger('click');
310                                }
311                            });
312                            $(this).children('span').removeClass('not_checked').removeClass('partial_checked').addClass('all_checked');
313                        }
314                        else {
315                            if ($(this).children('span').hasClass('all_checked')) {
316                                $('.gdpr-consent-tabs-content li').each(function () {
317                                    if ($(this).hasClass(cookiecategory)) {
318                                        $(this).find('.module-cookies-chkbox:checked').trigger('click');
319                                    }
320                                });
321                                $(this).children('span').removeClass('all_checked').addClass('not_checked');
322                            }
323                        }
324                    }
325                }
326            });
327
328
329            $(".div_summary_checkboxes + .div_hide_show .show_details").on("click", function () {
330                $(this).parent().toggleClass('open');
331                $(".div_center_area").slideDown("slow");
332            });
333            $(".div_summary_checkboxes + .div_hide_show .hide_details").on("click", function () {
334                $(this).parent().toggleClass('open');
335                $(".div_center_area").slideUp("slow");
336            });
337
338
339            $(".gdpr-consent-tabs .div_accept_moreinfo .span_moreinfo").on("click", function () {
340                $(this).toggleClass('open');
341                $(".div_show_moreinfo").slideToggle("slow");
342            });
343
344            $(".gdpr-consent-tabs-content .table-responsive .td_description").hover(function () {
345                $('.gdpr-consent-tabs-content .table-responsive td.td_description .tooltiptext').css({top: $(this).position().top - $(this).height() / 2 - $(this).children('.tooltiptext').outerHeight() - 15});
346            });
347
348            $(".gdpr-consent-tabs-content .table-responsive .td_description").on("click", function () {
349                $(".gdpr-consent-tabs-content .table-responsive tr").not($(this).parent()).removeClass('active');
350                $(this).parent().toggleClass("active");
351            });
352
353            $(window).resize(function () {
354                if ($(window).width() >= 650) {
355                    $('.gdprModal').height($('body').height());
356                }
357                else {
358                    $('.gdprModal').height($(document).height());
359                }
360            });
361        }
362    });
363
364    $.fn[pluginName] = function (options) {
365
366        return this.each(function () {
367            if (!$.data(this, "plugin_" + pluginName)) {
368                $.data(this, "plugin_" +
369                    pluginName, new Plugin(this, options));
370            }
371        });
372    };
373})(jQuery, window, document);
374$(document).ready(function () {
375    var content = $("#gdpr-modal-container").html();
376    $("#gdpr-modal-container").remove();
377    $("#gdpr-consent").prestaGdprConsent({
378        content: content,
379        showOnPageLoad: (gdprSettings.doNotTrackCompliance && navigator.doNotTrack == 1) ? false : gdprSettings.showWindow,
380        cookieStoreUrl: gdprSettings.gdprCookieStoreUrl,
381        modules: gdprSettings.gdprEnabledModules,
382        checkAllByDefault: gdprSettings.checkAllByDefault,
383        reloadAfterSave: gdprSettings.reloadAfterSave,
384        reloadAfterAcceptAll: gdprSettings.reloadAfterAcceptAll,
385        under18AlertText: gdprSettings.under18AlertText,
386        closeModalOnlyWithButtons: gdprSettings.closeModalOnlyWithButtons
387    });
388});

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.