Skip to content

Commit 85e2a51

Browse files
committed
Merge branch '129-revise-cookie-compliance-to-meet-eu-regs'
2 parents 31f8832 + c48a4fd commit 85e2a51

File tree

7 files changed

+254
-84
lines changed

7 files changed

+254
-84
lines changed

_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defaults:
3131
layout: "default"
3232

3333
# change the following to false to re-enable flash pop-ups
34-
ignore-flash: true
34+
ignore-flash: false
3535

3636
# minify CSS geerated from SASS
3737
sass:

_includes/footer.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
<p>
2323
<span role="license" class="hidden-xs">Website content copyright &copy; {{ "now" | date: "%Y" }}, <a href="https://gravatar.com/delphidabbler">Peter Johnson</a> and licensed under the Creative Commons Attribution 4.0 International (<a href="{{ site.data.core.cc-40-url }}" aria-label="{{ site.data.core.cc-40-link-title }}">CC BY-4.0</a>) license.</span> For full details of license, copyright and 3rd party code see the <a href="{{ site.data.core.credits-link }}" aria-label="{{ site.data.core.credits-link-title }}">license &amp; credits page</a>.
2424
</p>
25+
<p id="cookie-consent--opt-out-text">
26+
<small>You are opted in to <a href="/cookies.html">cookies</a>. <a href="#" id="cookie-consent--revoke">Opt out</a>.</small>
27+
</p>
2528
<p>
2629
<small>Build date: {{ site.time }}</small>
2730
</p>
2831
</div> <!-- .pagefoot-credits -->
2932

3033
</footer> <!-- /.pagefoot -->
31-
<!-- END footer -->
34+
<!-- END footer -->

_sass/_dd-custom-styles.scss

+26-8
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,24 @@ a {
879879
// ** Custom
880880
#cookie-popup {
881881

882-
background-color: $brand-danger;
882+
background-color: $navbar-default-bg;
883883
color: white;
884884
border: 1px white solid;
885885
padding: 1rem;
886+
font-size: $font-size-small;
887+
position: fixed;
888+
bottom: 0px;
889+
z-index: 999;
890+
margin: 0;
891+
width: 100%;
892+
893+
&:hover {
894+
opacity: 1;
895+
}
886896

887897
p.cookie-msg {
888898
padding: 0;
899+
margin-bottom: $line-height-computed / 4;
889900

890901
a {
891902
text-decoration: underline;
@@ -894,19 +905,26 @@ a {
894905
}
895906

896907
p.cookie-btn {
908+
897909
padding: 0;
898-
text-align: right;
910+
text-align: center;
911+
margin-bottom: 0;
912+
margin-top: 0;
899913

900914
button {
901-
text-align: center;
902-
background-color: transparent;
903-
color: white;
915+
904916
border: 1px white solid;
905-
padding: 4px 2rem;
906-
&:hover {
907-
background-color: lighten($brand-danger, 10%);
917+
margin-right: 1rem;
918+
font-size: $font-size-small;
919+
padding: 2px 8px;
920+
921+
&:last-child {
922+
margin-right: 0;
908923
}
909924
}
910925
}
926+
}
911927

928+
#cookie-consent--opt-out-text {
929+
display: none;
912930
}

assets/scripts/cookieConsent.js

+70-23
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,79 @@
77
* To style this item provide CSS for:
88
* #cookie-popup (bounding <div>)
99
* p.cookie-msg (message string <p>)
10-
* p.cookie-btn (<p> containing close button)
11-
* p.cookie-btn button (close <button> itself)
10+
* p.cookie-btn (<p> containing accept/reject buttons)
11+
* p.cookie-btn button (accept/reject buttons)
12+
* #cookie-consent-reject-btn (reject button)
13+
* #cookie-consent-accept-btn (accept button)
1214
*/
1315

14-
var CookieConsent = {
15-
exec: function() {
16-
let cookieName = 'dd_inhibit_cookie_consent';
17-
if ( Cookie.isSet(cookieName) ) {
18-
return;
19-
}
20-
$(document.body).prepend(
21-
'<div id="cookie-popup" class="container-fluid">'
22-
+ '<p class="cookie-msg">This website uses a minimum number of cookies. '
23-
+ 'There are no trackers or advertising cookies. '
24-
+ '<a href="/cookies">More info</a>.'
25-
+ '</p>'
26-
+ '<p class="cookie-btn"><button id="cookie-close-btn">Dismiss</button></p>'
27-
+ '</div>'
28-
);
29-
$('#cookie-close-btn').click(function() {
30-
Cookie.set(cookieName, "dismissed", 91); // expires in apx 3 mths
31-
$('#cookie-popup').hide();
16+
$( function() {
17+
18+
const cookieName = 'dd-base--cookies-accepted';
19+
const sessionCookieName = 'dd-base--cookie-reject-session';
20+
const optOutPara = '#cookie-consent--opt-out-text';
21+
const messageHTMLPath = '/assets/scripts/includes/cookie-consent-msg.html';
22+
23+
// Remove redundant cookies
24+
Cookie.delete('cookieconsent_status');
25+
Cookie.delete('dd_inhibit_cookie_consent');
26+
Cookie.delete('dd_flash_1');
27+
28+
if ( Cookie.isSet(cookieName) ) {
29+
// User has accepted cookies: add opt-out link to footer
30+
const revokeBtn = '#cookie-consent--revoke';
31+
$(optOutPara).css('display', 'block');
32+
$(revokeBtn).on('click', function() {
33+
Cookie.delete(cookieName);
34+
location.reload(true);
3235
});
3336
}
34-
}
3537

36-
$( function() {
37-
CookieConsent.exec();
38+
else if ( sessionStorage[sessionCookieName] !== '1' ) {
39+
// No cookie decision recorded: display pop-up message
40+
$(document.body).prepend('<div id="cookie-message"></div>');
41+
$('#cookie-message').load(
42+
messageHTMLPath,
43+
function (response, status, jqHXR) {
44+
45+
$('#cookie-consent-accept-btn').click(function() {
46+
Cookie.set(cookieName, "1", 182); // expires in apx 6 mths
47+
$('#cookie-popup').fadeOut();
48+
$(optOutPara).css('display', 'block');
49+
location.reload(true);
50+
});
51+
52+
$('#cookie-consent-reject-btn').click(function() {
53+
Cookie.delete(cookieName);
54+
sessionStorage[sessionCookieName] = '1';
55+
$('#cookie-popup').fadeOut();
56+
location.reload(true);
57+
});
58+
59+
$(window).on('scroll', function() {
60+
61+
let documentHeight = document.body.scrollHeight;
62+
let currentScroll = window.scrollY + window.innerHeight;
63+
// When the user is [modifier]px from the bottom, fire the event.
64+
let pageEndDelta = 150;
65+
if(currentScroll + pageEndDelta > documentHeight) {
66+
// at end: hide the message
67+
console.log('At end');
68+
if ($('#cookie-popup').css('display') !== 'none') {
69+
console.log('hiding')
70+
$('#cookie-popup').fadeOut();
71+
}
72+
}
73+
else {
74+
// not at end
75+
if ($('#cookie-popup').css('display') === 'none') {
76+
console.log('showing')
77+
$('#cookie-popup').fadeIn();
78+
}
79+
}
80+
});
81+
}
82+
);
83+
}
84+
3885
});

assets/scripts/flashMessage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $( function() {
1515
return;
1616
}
1717
const id = flash.data('flash-id');
18-
const cookieName = 'dd_flash_' + id;
18+
const cookieName = 'dd-base--flash-' + id;
1919
flash.on('closed.bs.alert', function () {
2020
// set cookie for 1yr: can't set for more per EU regs
2121
Cookie.set(cookieName, "dismissed", 365);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div id="cookie-popup">
2+
<p class="cookie-msg">This website uses a limited number of preferences cookies, but no tracking or marketing cookies. Please read the <a href="/cookies">cookies information page</a> before deciding whether to accept or reject cookies by clicking one of the buttons below.</p>
3+
<p class="cookie-btn"><button class="btn btn-success" id="cookie-consent-accept-btn">Accept</button><button class="btn btn-danger" id="cookie-consent-reject-btn">Reject</button></p>
4+
</div>

0 commit comments

Comments
 (0)