-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathcookies.js
89 lines (81 loc) · 2.99 KB
/
cookies.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
80
81
82
83
84
85
86
87
88
89
var manager = klaro.getManager(),
consents = manager.loadConsents(),
$cookieBanner = $('#cookie-banner'),
$confirmationAccept = $('#cookie-banner-accept'),
$confirmationReject = $('#cookie-banner-reject'),
$cookiePageSubmit = $('#cookie-page-submit');
if (!manager.confirmed) {
$cookieBanner.show();
$('#cookie-accept').click(function() {
if (typeof consents['google-analytics'] !== 'undefined') {
consents['google-analytics'] = true;
}
if (typeof consents['hotjar'] !== 'undefined') {
consents['hotjar'] = true;
}
manager.saveAndApplyConsents();
$cookieBanner.hide();
$confirmationAccept.show();
});
$('#cookie-reject').click(function() {
if (typeof consents['google-analytics'] !== 'undefined') {
consents['google-analytics'] = false;
}
if (typeof consents['hotjar'] !== 'undefined') {
consents['hotjar'] = false;
}
manager.saveAndApplyConsents();
$cookieBanner.hide();
$confirmationReject.show();
});
$('#hide-accept').click(function(e) {
e.preventDefault();
$confirmationAccept.hide();
});
$('#hide-reject').click(function(e) {
e.preventDefault();
$confirmationReject.hide();
});
}
if ($cookiePageSubmit.length > 0) {
var $analyticsYes = $('#analytics-cookies'),
$cookiePageSuccess = $('#cookie-page-success'),
$cookiePageGoBack = $('#cookie-page-go-back'),
saveCookieSettings = function(e) {
e.preventDefault();
var choice = Boolean($analyticsYes.prop('checked'));
if (typeof consents['google-analytics'] !== 'undefined') {
consents['google-analytics'] = choice;
}
if (typeof consents['hotjar'] !== 'undefined') {
consents['hotjar'] = choice;
}
manager.saveAndApplyConsents();
$cookiePageSuccess.show();
$([document.documentElement, document.body]).animate({
scrollTop: $cookiePageSuccess.offset().top
}, 500, 'swing', function() { $cookiePageGoBack.focus(); });
};
// We want the confirmation to be above the H1.
$cookiePageSuccess.prependTo($cookiePageSuccess.parent().parent());
// Set pre-selected options.
if (typeof consents['google-analytics'] !== 'undefined' || typeof consents['hotjar'] !== 'undefined') {
var preselected = Boolean(consents['google-analytics']) || Boolean(consents['hotjar']);
$analyticsYes.prop('checked', preselected);
}
$cookiePageSubmit.click(saveCookieSettings);
// For semantics and accessibility, wrap the page in a form and add
// a submit handler.
$('#main-content > div').first().wrap('<form id="cookie-page-form" novalidate></form>');
$('#cookie-page-form').submit(saveCookieSettings);
// Go back behavior.
$cookiePageGoBack.click(function(e) {
e.preventDefault();
window.history.back();
});
}
// Update any Cookies links.
$('a[href*="cookies-no-javascript"]').each(function() {
var href = $(this).attr('href');
$(this).attr('href', href.replace('cookies-no-javascript', 'cookies'));
});