-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimalCookie.js
72 lines (56 loc) · 1.71 KB
/
minimalCookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
A tiny library to help uphold the EU cookie law.
*/
(function(global) {
"use strict";
var MinimalCookie = function() {
var self = this;
if (MinimalCookie.prototype._singletonInstance) {
return MinimalCookie.prototype._singletonInstance;
}
MinimalCookie.prototype._singletonInstance = self;
self.CHOICE_KEY = 'eu_cookie_choice';
self.ACCEPT = 'cookie_accept';
self.DECLINE = 'cookie_decline';
self.EXPIRES = 365 * 24 * 60 * 60;
self.choice_made = function() {
return global.Cookies.get(self.CHOICE_KEY) != undefined;
};
self.forget_choice = function() {
global.Cookies.expire(self.CHOICE_KEY);
};
self.allowed = function() {
return global.Cookies.get(self.CHOICE_KEY) == self.ACCEPT;
};
self.accept = function() {
global.Cookies.set(
self.CHOICE_KEY,
self.ACCEPT,
{ expires: self.EXPIRES }
);
};
self.decline = function() {
global.Cookies.set(
self.CHOICE_KEY,
self.DECLINE,
{ expires: self.EXPIRES }
);
};
return self;
};
global.MinimalCookie = new MinimalCookie();
}(window));
$(function() {
$('#cookie-accept').on('click', function() {
MinimalCookie.accept();
location.reload();
});
$('#cookie-decline').on('click', function() {
MinimalCookie.decline();
location.reload();
});
if (!MinimalCookie.choice_made()) {
$('#cookies-prompt').toggleClass('hidden');
}
});