-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurecookie.js
79 lines (68 loc) · 2.57 KB
/
purecookie.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
73
74
75
76
77
78
79
// --- Config --- //
//var purecookieTitle = "Cookies."; // Title
//var purecookieDesc = "We use cookies to give you the best experience and to help improve our website. <a href="cookie-policy.html" target="_blank">How we use cookies.</a>";
//var purecookieLink = '<a href="cookie-policy.html" target="_blank">Read our Cookie Policy</a>'; // link
var purecookieButton = "OK"; // Button text
// --- --- //
function pureFadeIn(elem, display) {
var el = document.getElementById(elem);
el.style.opacity = 0;
el.style.display = display || "block";
(function fade() {
var val = parseFloat(el.style.opacity);
if (!((val += .02) > 1)) {
el.style.opacity = val;
requestAnimationFrame(fade);
}
})();
};
function pureFadeOut(elem) {
var el = document.getElementById(elem);
el.style.opacity = 1;
(function fade() {
if ((el.style.opacity -= .02) < 0) {
el.style.display = "none";
} else {
requestAnimationFrame(fade);
}
})();
};
function setCookie(name, value, days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
document.cookie = name + '=; Max-Age=-99999999;';
}
function cookieConsent() {
if (!getCookie('purecookieDismiss')) {
var cookieDiv = document.createElement('div');
cookieDiv.id = 'menu';
cookieDiv.innerHTML = '<div class="cookieConsentContainer" id="cookieConsentContainer"><div class="cookieDesc"><p>This website may use cookies and other <br />technologies to improve the functionality and <br />performance of this site and your experience. <br />Learn more by reviewing our <a href="https://privacy.cornell.edu">Privacy</a> page.</p></div><button class="cookieButton" onClick="purecookieDismiss();">' + purecookieButton + '</button></div>';
document.body.appendChild(cookieDiv);
pureFadeIn("cookieConsentContainer");
}
}
function purecookieDismiss() {
setCookie('purecookieDismiss', '1', 7);
pureFadeOut("cookieConsentContainer");
}
window.onload = function () {
cookieConsent();
//eraseCookie('purecookieDismiss'); // swap-in eraseCookie() to reset
};