PageSourceSearch

https://www.ottojakob.com/packages/eu_cookie_law/js/cookie-disclos…=e444ae73c63c04070eb6991bac9a754ca9d9877d

js ottojakob.com collected 2026-09-25 21:48:47 UTC 9,251 bytes, 287 lines download raw bytes

1/**
2 * Project: EU Cookie Law Add-On
3 *
4 * @copyright 2017 Fabian Bitter
5 * @author Fabian Bitter ([email protected])
6 * @version 1.0
7 */
8
9var CookieDisclosure = {
10    settings: [],
11    popup: null,
12    originalTop: null,
13    
14    buildUrl: function (methodName) {
15        return this.settings.serviceUrl + "/" + methodName;
16    },
17
18    callMethod: function (methodName, clb) {
19        $.ajax({
20            dataType: "json",
21            url: this.buildUrl(methodName),
22            success: function () {
23                clb();
24            }
25        });
26    },
27
28    optIn: function () {
29        // remove popup
30        this.removePopup();
31        
32        this.setStatus(true);
33        
34        // Remove Cookies server side
35        this.callMethod("optIn", function () {
36            if (CookieDisclosure.settings.enablePageReload) {
37                location.reload();
38            }
39        });
40    },
41  
42    optOutAndRemove: function() {
43        // remove popup
44        this.removePopup();
45        
46        this.clearAll();
47      
48        Cookies.remove('cookie-disclosure');
49        
50        // Remove Cookies server side
51        this.callMethod("optOut", function () {
52            if (CookieDisclosure.settings.enablePageReload) {
53                location.reload();
54            }
55        });
56    },
57
58    optOut: function () {
59        // remove popup
60        this.removePopup();
61        
62        this.clearAll();
63      
64        this.setStatus(false);
65        
66        // Remove Cookies server side
67        this.callMethod("optOut", function () {
68            if (CookieDisclosure.settings.enablePageReload) {
69                location.reload();
70            }
71        });
72    },
73    
74    setStatus: function(status) {
75        Cookies.set('cookie-disclosure', status,  { expires: 365 });
76    },
77
78    getStatus: function() {
79        return Cookies.get('cookie-disclosure');
80    },
81
82    clearAll: function() {
83        return this.clearLocalStorage() && this.clearSessionStorage() && this.clearCookies();
84    },
85    
86    clearLocalStorage: function() {
87        // clear local storage if available
88        if (typeof localStorage !== "undefined") {
89            localStorage.clear();
90        }
91        
92        return true;
93    },
94
95    clearSessionStorage: function() {
96        // clear session storage if available
97        if (typeof sessionStorage !== "undefined") {
98            sessionStorage.clear();
99        }
100        
101        return true;
102    },
103
104    clearCookies: function() {
105        // Remove cookies client side
106        Object.keys(Cookies.get()).forEach(function (cookie) {
107            Cookies.remove(cookie, {domain: window.location.hostname});
108            Cookies.remove(cookie, {domain: "." + window.location.hostname});
109            Cookies.remove(cookie, {domain: window.location.hostname, path : "/"});
110            Cookies.remove(cookie, {domain: "." + window.location.hostname, path : "/"});
111            Cookies.remove(cookie);
112        });
113        
114        return true;
115    },
116    
117    init: function (settings) {
118        this.settings = settings;
119
120        if (typeof this.getStatus() === "undefined") {
121            this.createPopup();
122        
123            this.bindEventHandlers();
124        }
125    },
126    
127    bindEventHandlers: function() {
128        var self = this;
129        
130        $(window).bind("scroll resize", function() {
131            self.refresh();
132        });
133        
134        self.refresh();
135    },
136
137    createPopup: function () {
138        var self = this;
139        
140        var infoText = $('<p/>', {
141            class: 'message',
142            text: this.settings.content.message,
143            style: "color: " + this.settings.colors.popup.text + "; "
144        });
145        
146        infoText.append(
147            $('<a/>', {
148                class: 'privacy-link',
149                href: this.settings.content.href,
150                text: this.settings.content.link,
151                style: "color: " + this.settings.colors.popup.text + "; "
152            })
153        );
154        
155        var infoContainer = $('<div/>', {
156            class: 'info-container'
157        });
158
159        infoContainer.append(
160            infoText
161        );
162
163        var buttonsContainer = $('<div/>', {
164            class: 'buttons-container'
165        });
166
167        switch (this.settings.type) {
168            case "opt-out":
169                buttonsContainer.append(
170                    $('<a/>', {
171                        class: 'btn btn-default',
172                        text: this.settings.content.decline,
173                        click: function() {
174                            self.optOut();
175                        },
176                        style: "background-color: " + this.settings.colors.button.secondary.background + "; " +
177                               "border-color: " + this.settings.colors.button.secondary.background + "; " +
178                               "color: " + this.settings.colors.button.secondary.text + "; "
179                    })
180                );
181                
182                buttonsContainer.append(
183                    $('<a/>', {
184                        class: 'btn btn-primary',
185                        text: this.settings.content.dismiss,
186                        click: function() {
187                            self.optIn();
188                        },
189                        style: "background-color: " + this.settings.colors.button.primary.background + "; " +
190                               "border-color: " + this.settings.colors.button.primary.border + "; " +
191                               "color: " + this.settings.colors.button.primary.text + "; "
192                    })      
193                );
194        
195                break;
196
197            case "opt-in":
198                buttonsContainer.append(
199                    $('<a/>', {
200                        class: 'btn btn-default',
201                        text: this.settings.content.deny,
202                        click: function() {
203                            self.optOut();
204                        },
205                        style: "background-color: " + this.settings.colors.button.secondary.background + "; " +
206                               "border-color: " + this.settings.colors.button.secondary.background + "; " +
207                               "color: " + this.settings.colors.button.secondary.text + "; "
208                    })
209                );
210                
211                buttonsContainer.append(
212                    $('<a/>', {
213                        class: 'btn btn-primary',
214                        text: this.settings.content.allow,
215                        click: function() {
216                            self.optIn();
217                        },
218                        style: "background-color: " + this.settings.colors.button.primary.background + "; " +
219                               "border-color: " + this.settings.colors.button.primary.border + "; " +
220                               "color: " + this.settings.colors.button.primary.text + "; "
221                    })      
222                );
223        
224                break;
225
226            default:
227                buttonsContainer.addClass("single-button");
228                
229                buttonsContainer.append(
230                    $('<a/>', {
231                        class: 'btn btn-primary',
232                        text: this.settings.content.dismiss,
233                        click: function() {
234                            self.optIn();
235                        },
236                        style: "background-color: " + this.settings.colors.button.primary.background + "; " +
237                               "border-color: " + this.settings.colors.button.primary.border + "; " +
238                               "color: " + this.settings.colors.button.primary.text + "; "
239                    })
240                );
241                
242                break;
243        }
244        
245        this.popup = $('<div/>', {
246            class: 'cookie-disclosure ' + (this.settings.isRTL ? "rtl" : "") + ' ' + this.settings.position,
247            style: "background-color: " + this.settings.colors.popup.background + "; " +
248                   ($("#ccm-toolbar").length ? "margin-top: " + $("#ccm-toolbar").height() + "px" : "")
249        }).prependTo('body');
250
251        this.popup.append(infoContainer);
252        this.popup.append(buttonsContainer);
253
254    },
255    
256    refresh: function() {
257        if (this.settings.position === "top") {
258            if (this.popup === null) {
259                $("body").css("paddingTop", this.originalTop);
260                
261            } else {
262                if (this.originalTop === null) {
263                    this.originalTop = parseInt($("body").css("paddingTop"));
264                }
265
266                var newTop = 
267                        this.originalTop +
268                        this.popup.height() +
269                        parseInt(this.popup.css("paddingTop")) +
270                        parseInt(this.popup.css("paddingBottom"));
271                $("body").css("paddingTop", newTop);
272                
273            } 
274            
275        }
276    },
277    
278    removePopup: function() {
279        if (typeof this.popup !== "undefined" && this.popup !== null) {
280            this.popup.remove();
281        
282            this.popup = null;
283      
284            this.refresh();
285        }
286    }
287};

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.