-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from City-of-Helsinki/cookie-consent
Cookie consent
- Loading branch information
Showing
11 changed files
with
384 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#cookie-consent { | ||
display: none; | ||
position: fixed; | ||
bottom: -200px; | ||
width: 100%; | ||
background-color: white; | ||
border-top: 8px solid #0000bf; | ||
max-height: 80vh; | ||
z-index: 2; | ||
} | ||
|
||
#cookie-consent__container { | ||
box-sizing: border-box; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
position: relative; | ||
width: 100%; | ||
} | ||
|
||
#cookie-consent__title-container { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
#cookie-consent__title { | ||
font-size: 2rem; | ||
} | ||
|
||
.cookie-consent__accordion-btn { | ||
display: flex; | ||
line-height: 1.25rem; | ||
padding: 0 0.75rem; | ||
align-items: center; | ||
background: transparent; | ||
border: none; | ||
color: black; | ||
cursor: pointer; | ||
outline: none; | ||
text-decoration: none; | ||
} | ||
|
||
.cookie-consent__accordion-btn > span { | ||
font-size: 1.5rem; | ||
padding-right: 0.75rem; | ||
} | ||
|
||
.cookie-consent__accordion-btn > svg { | ||
width: 24px; | ||
} | ||
|
||
#cookie-consent__content { | ||
display: none; | ||
} | ||
|
||
#cookie-consent__description { | ||
font-size: 1.5rem; | ||
padding: 0.75rem 0; | ||
} | ||
|
||
#cookie-consent__more-content__container { | ||
padding: 0.75rem 0; | ||
} | ||
|
||
#cookie-consent__more-content { | ||
padding: 0.75rem 0; | ||
} | ||
|
||
#cookie-consent__more-content__title { | ||
font-size: 1.75rem; | ||
padding-bottom: 0.75rem; | ||
} | ||
|
||
.cookie-consent__more-content__section { | ||
padding: 0.75rem; | ||
} | ||
|
||
.cookie-consent__more-content__section p { | ||
padding: 0.75rem 0; | ||
} | ||
|
||
#cookie-consent__actions { | ||
display: flex; | ||
padding: 0.75rem 0; | ||
gap: 8px; | ||
} | ||
|
||
#consent-table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
max-width: 860px; | ||
} | ||
|
||
#consent-table td, | ||
th { | ||
border: 1px solid #dddddd; | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
#consent-table th { | ||
background-color: black; | ||
color: white; | ||
} | ||
|
||
#consent-table tr:nth-child(even) { | ||
background-color: #dddddd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
(function($) { | ||
var cookieName = "hki_consent" | ||
var cookie = $.cookie(cookieName) | ||
var _paq = window._paq = window._paq || []; | ||
|
||
const $cookieConsentContainer = $("#cookie-consent"), | ||
$readMoreBtn = $("#cookie-consent__readmore-btn"), | ||
$cookieContents = $("#cookie-consent__content"), | ||
$acceptBtn = $("#consent_accept"), | ||
$rejectBtn = $("#consent_reject"), | ||
$consentLink = $("#cookie-consent-link"); | ||
|
||
// if rejected | ||
if(cookie && cookie === 0) { | ||
_paq.push(['forgetCookieConsentGiven']); | ||
_paq.push(['requireCookieConsent']); | ||
} | ||
|
||
// if accepted | ||
if(cookie && cookie === 1) { | ||
_paq.push(['setCookieConsentGiven']); | ||
} | ||
|
||
if(!cookie && _paq) { | ||
_paq.push(['requireCookieConsent']); | ||
|
||
$cookieConsentContainer.fadeIn(); | ||
$cookieConsentContainer.animate({ "bottom": "0" }, "slow" ); | ||
|
||
$readMoreBtn.on('click', function (e) { | ||
$readMoreBtn.hide(); | ||
$cookieContents.show(); | ||
}); | ||
|
||
$cookieConsentContainer.on('click', function (e) { | ||
$readMoreBtn.hide(); | ||
$cookieContents.show(); | ||
}); | ||
} | ||
|
||
$acceptBtn.on('click', function (e) { | ||
if(_paq) { | ||
_paq.push(['setCookieConsentGiven']); | ||
$.cookie(cookieName, 1, { expires : 393 }); | ||
$cookieConsentContainer.fadeOut(); | ||
} | ||
}); | ||
|
||
$rejectBtn.on('click', function (e) { | ||
if(_paq) { | ||
_paq.push(['forgetCookieConsentGiven']); | ||
$.cookie(cookieName, 0, { expires : 393 }); | ||
$cookieConsentContainer.fadeOut(); | ||
} | ||
}); | ||
|
||
// click cookie consent footer navi link to force open | ||
$consentLink.on('click', function (e) { | ||
e.preventDefault() | ||
$cookieConsentContainer.fadeIn(); | ||
$cookieConsentContainer.animate({ "bottom": "0" }, "slow" ); | ||
$cookieContents.show(); | ||
$readMoreBtn.hide(); | ||
}); | ||
|
||
// click outside to collapse cookie consent | ||
$(document).on('click', function (e) { | ||
if ($(e.target).closest("#cookie-consent").length === 0) { | ||
$cookieContents.hide(); | ||
$readMoreBtn.show(); | ||
} | ||
}); | ||
})(jQuery); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% load i18n %} | ||
|
||
<div id="cookie-consent"> | ||
<div id="cookie-consent__container"> | ||
<div id="cookie-consent__title-container"> | ||
<div id="cookie-consent__title">{% trans 'Helsinki photos uses cookies' %}</div> | ||
<button type="button" id="cookie-consent__readmore-btn" class="cookie-consent__accordion-btn"> | ||
<span>{% trans 'Read more' %}</span> | ||
<svg class="" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-label="angle-up" aria-hidden="true"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 11.5L17 16.5L18.5 15L12 8.5L5.5 15L7 16.5L12 11.5Z" fill="currentColor"></path></svg> | ||
</button> | ||
</div> | ||
<div id="cookie-consent__content"> | ||
<div id="cookie-consent__description"> | ||
{% trans 'This website uses required cookies' %} | ||
</div> | ||
<div id="cookie-consent__more-content__container"> | ||
<div id="cookie-consent__more-content__title">{% trans 'Cookie settings' %}</div> | ||
<div class="cookie-consent__more-content__section"> | ||
<p>{% trans 'The cookies used on the website'%}</p> | ||
</div> | ||
<div class="cookie-consent__more-content__section"> | ||
<span>{% trans 'Matomo (optional)' %}</span> | ||
<p>{% trans 'Matomo description' %}</p> | ||
<table id="consent-table"> | ||
<thead> | ||
<th>{% trans 'Cookie name' %}</th> | ||
<th>{% trans 'Cookie set by' %}</th> | ||
<th>{% trans 'Purpose of use' %}</th> | ||
<th>{% trans 'Period of validity' %}</th> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>_pk*</td> | ||
<td>digia.fi</td> | ||
<td>{% trans 'A cookie of the Matomo statistics system' %}</td> | ||
<td>393 {% trans 'Cookie days' %}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<div id="cookie-consent__actions"> | ||
<button aria-label="{% trans 'Zoom in' %}" id="consent_accept" class="hkm-button hkm-button__filled" type="submit">{% trans 'Accept all cookies' %}</button> | ||
<button id="consent_reject" class="hkm-button hkm-button__outlined" type="submit">{% trans 'Accept essential cookies' %}</button> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.