This repository has been archived by the owner on Oct 13, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
eclipsefdn.cookie-consent.js
155 lines (150 loc) · 4.72 KB
/
eclipsefdn.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*!
* Copyright (c) 2018 Eclipse Foundation, Inc.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* Contributors:
* Christopher Guindon <chris.guindon@eclipse-foundation.org>
*
* SPDX-License-Identifier: EPL-2.0
*/
import 'cookieconsent';
const eclipseFdnCookieConsent = (function (window, document) {
window.addEventListener('load', function () {
/**
* Override revokeChoice()
*
* Avoid cookie resets when the user
* clicks on cookie settings
*/
window.cookieconsent.Popup.prototype.revokeChoice = function (preventOpen) {
this.options.enabled = true;
this.options.onRevokeChoice.call(this);
if (!preventOpen) {
this.autoOpen();
}
this.open();
};
/**
* Add custom button to show cookie consent banner
* when it exist.
*/
document.addEventListener(
'click',
function (event) {
// If the clicked element doesn't have the right selector, bail
if (!event.target.classList.contains('toolbar-manage-cookies')) {
return;
}
// Log the clicked element in the console
const ccWindow = document.getElementsByClassName('cc-window');
ccWindow[0].style.display = '';
setTimeout(function () {
ccWindow[0].classList.remove('cc-invisible');
}, 20);
},
false
);
/**
* Remove Cookies
*
* Remove cookies except whitelist
*/
window.cookieconsent.Popup.prototype.removeCookies = function () {
var whitelist = ['eclipse_cookieconsent_status', 'has_js'];
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var cookie_index = cookie.indexOf('=');
var cookie_name =
cookie_index > -1 ? cookie.substr(0, cookie_index) : cookie;
cookie_name = cookie_name.trim();
if (
whitelist === undefined ||
whitelist.length == 0 ||
whitelist.indexOf(cookie_name) == -1
) {
document.cookie =
cookie_name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/;';
}
}
};
/**
* Helper function that hides the cc-revoke
* when it's not needed
*/
function hideShowCCRevokeButton() {
// This button is not needed when a .toolbar-manage-cookies link is present
// on the page.
if (!document.getElementsByClassName('toolbar-manage-cookies').length) {
document.getElementsByClassName('cc-revoke')[0].style.display = 'block';
} else {
document.getElementsByClassName('cc-revoke')[0].style.display = 'none';
}
}
/**
* Initialise cookieconsent
*/
window.cookieconsent.initialise({
type: 'opt-in',
position: 'bottom',
revokable: true,
enabled: true,
//animateRevokable: false,
cookie: {
name: 'eclipse_cookieconsent_status',
expiryDays: 90,
domain:
'.' +
location.hostname.split('.').reverse()[1] +
'.' +
location.hostname.split('.').reverse()[0],
},
compliance: {
'opt-in':
'<div class="cc-compliance cc-highlight">{{deny}}{{allow}}</div>',
},
onStatusChange: function (status, chosenBefore) {
// Cookies are not allowed, delete them
document.cookie =
'eclipse_cookieconsent_status=' + status + '; expires=0; path=/;';
if (status !== 'allow') {
this.removeCookies();
}
},
onPopupClose: function () {
hideShowCCRevokeButton();
},
onInitialise: function (status, options) {
setTimeout(function () {
hideShowCCRevokeButton();
});
},
revokeBtn: '<div class="cc-revoke {{classes}}">Cookie settings</div>',
palette: {
popup: {
background: '#353434',
text: '#ffffff',
},
highlight: {
background: '#fff',
text: '#000000',
},
button: {
background: '#da7a08',
text: '#ffffff',
},
},
content: {
href: 'https://www.eclipse.org/legal/privacy.php',
dismiss: 'Dismiss',
link: 'click here.',
message:
'Some Eclipse Foundation pages use cookies to better serve you when you return to the site. You can set your browser to notify you before you receive a cookie or turn off cookies. If you do so, however, some areas of some sites may not function properly. To read Eclipse Foundation Privacy Policy',
},
});
});
})(window, document);
export default eclipseFdnCookieConsent;