-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrt-cookie-consent.js
62 lines (48 loc) · 1.26 KB
/
grt-cookie-consent.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
/*!
* GRT Cookie Consent - jQuery Plugin
* Version: 1.0
* Author: GRT107
*
* Copyright (c) 2020 GRT107
* Released under the MIT license
*/
(function ($) {
$.fn.grtCookie = function (options) {
// Default options
var settings = $.extend({
textcolor: "#333",
background: "#fff",
buttonbackground: "#333",
buttontextcolor: "#fff",
duration: 365
}, options);
// Check cookie
if (!(document.cookie.indexOf("acceptgrt=0") > -1)) {
// Text and Background color
this.css({
color: settings.textcolor,
background: settings.background,
});
// Button Colors
$('span.grt-cookie-button').css({
background: settings.buttonbackground,
color: settings.buttontextcolor
});
// Show message and calculate date
this.addClass("grt-cookie-active");
var d1 = new Date();
var days1 = settings.duration;
d1.setTime(d1.getTime() + days1 * 24 * 60 * 60 * 1000);
var expiredate = "expires=" + d1.toUTCString();
document.cookie = "acceptgrt=1;" + expiredate + ";path=/";
// On click accept button
$(".grt-cookie-button").on("click", function () {
$(this).parent().remove();
document.cookie = "acceptgrt=0;" + expiredate + ";path=/";
});
} else {
this.remove();
}
return this;
};
}(jQuery));