Skip to content

Commit

Permalink
Merge pull request #304 from City-of-Helsinki/cookie-consent
Browse files Browse the repository at this point in the history
Cookie consent
  • Loading branch information
melniiv committed Nov 6, 2023
2 parents 0533211 + 92a8d33 commit ac59550
Show file tree
Hide file tree
Showing 11 changed files with 384 additions and 1 deletion.
107 changes: 107 additions & 0 deletions hkm/static/hkm/css/consent.css
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;
}
73 changes: 73 additions & 0 deletions hkm/static/hkm/js/cookie-consent.js
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);
2 changes: 2 additions & 0 deletions hkm/static/hkm/js/jquery.cookie.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion hkm/templates/hkm/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<link rel="stylesheet" type="text/css" href="/static/hkm/css/main.css" />
<link rel="stylesheet" type="text/css" href="/static/hkm/css/cropper.css" />
<link rel="stylesheet" type="text/css" href="/static/hkm/css/leaflet.css" />
<link rel="stylesheet" type="text/css" href="/static/hkm/css/consent.css" />
{% endblock %}


Expand Down Expand Up @@ -144,6 +145,7 @@ <h1 class="login-modal__body_title">{% trans 'Sign up' %}</h1>
<a href="{% url 'hkm_siteinfo_privacy' %}"><p>{% trans 'Privacy policy' %}</p></a>
<a href="{% url 'hkm_siteinfo_accessibility' %}"><p>{% trans 'Accessibility statement' %}</p></a>
<p><a href="{% url 'hkm_info' %}">{% trans 'Feedback' %}</a></p>
<p><a id="cookie-consent-link" href="#">{% trans 'Cookie consent link' %}</a></p>
</div>
<div class="links-box">
<!-- <p>{% trans 'This service is provided by' %}</p> -->
Expand All @@ -168,11 +170,14 @@ <h1 class="login-modal__body_title">{% trans 'Sign up' %}</h1>
</div>
{% endblock %}

{% include 'hkm/snippets/cookie_consent.html' %}

{% block js %}
<script>
document.querySelector('#meta-url').setAttribute('content', location.href)
</script>
<script src="/static/hkm/js/jquery.js"></script>
<script src="/static/hkm/js/jquery.cookie.js"></script>
<script src="/static/hkm/js/jquery.csrf.js"></script>
<script src="/static/hkm/js/velocity.js"></script>
<script src="/static/hkm/js/hammer.js"></script>
Expand All @@ -184,6 +189,7 @@ <h1 class="login-modal__body_title">{% trans 'Sign up' %}</h1>
<script src="/static/hkm/js/leaflet.js"></script>
<script src="/static/hkm/js/clipboard.js"></script>
<script src="/static/hkm/js/hkm-v2.js"></script>
<script src="/static/hkm/js/cookie-consent.js"></script>

{% if ENABLE_ANALYTICS %}
<!-- Matomo -->
Expand All @@ -199,7 +205,7 @@ <h1 class="login-modal__body_title">{% trans 'Sign up' %}</h1>
g.async=true; g.src=u+'piwik.min.js'; s.parentNode.insertBefore(g,s);
})();
</script><!-- End Matomo Code -->
{% endif %}
{% endif %}
{% endblock %}
{% block extra_js %}
{% endblock %}
Expand Down
49 changes: 49 additions & 0 deletions hkm/templates/hkm/snippets/cookie_consent.html
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 modified kuvaselaamo/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
49 changes: 49 additions & 0 deletions kuvaselaamo/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,52 @@ msgstr "Your favorite pictures are collected here"

msgid "Password alphabetic"
msgstr "Password contains only letters"

msgid "Helsinki photos uses cookies"
msgstr "Helsinkiphotos uses cookies"

msgid "Read more"
msgstr "Read more"

msgid "This website uses required cookies"
msgstr "This website uses required cookies to ensure the basic functionality and performance. In addition, we use targeting cookies to improve the user experience, perform analytics and display personalised content."

msgid "Cookie settings"
msgstr "Cookie settings"

msgid "The cookies used on the website"
msgstr "The cookies used on the website have been classified according to their intended use. Below, you can read about the various categories and accept or reject the use of cookies."

msgid "Matomo (optional)"
msgstr "Matomo"

msgid "Matomo description"
msgstr "Matomo Analytics software is being used to follow and improve the website to better attend to user's needs."

msgid "Cookie name"
msgstr "Name"

msgid "Cookie set by"
msgstr "Cookie set by"

msgid "Purpose of use"
msgstr "Purpose of use"

msgid "Period of validity"
msgstr "Period of validity"

msgid "A cookie of the Matomo statistics system"
msgstr "A cookie of the Matomo statistics system"

msgid "Cookie days"
msgstr "days"

msgid "Accept all cookies"
msgstr "Accept all cookies"

msgid "Accept essential cookies"
msgstr "Accept only essential cookies"

msgid "Cookie consent link"
msgstr "Cookie settings"

Binary file modified kuvaselaamo/locale/fi/LC_MESSAGES/django.mo
Binary file not shown.
49 changes: 49 additions & 0 deletions kuvaselaamo/locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -706,3 +706,52 @@ msgstr "Suosikkikuvasi on kerätty tänne"

msgid "Password alphabetic"
msgstr "Salasana sisältää pelkkiä kirjaimia"

msgid "Helsinki photos uses cookies"
msgstr "Helsinkikuvia käyttää evästeitä"

msgid "Read more"
msgstr "Lue lisää"

msgid "This website uses required cookies"
msgstr "Tämä sivusto käyttää välttämättömiä evästeitä sivun perustoimintojen ja suorituskyvyn varmistamiseksi. Lisäksi käytämme kohdennusevästeitä käyttäjäkokemuksen parantamiseksi, analytiikkaan ja yksilöidyn sisällön näyttämiseen."

msgid "Cookie settings"
msgstr "Evästeasetukset"

msgid "The cookies used on the website"
msgstr "Sivustolla käytetyt evästeet on luokiteltu käyttötarkoituksen mukaan. Alla voit lukea eri luokista ja sallia tai kieltää evästeiden käytön."

msgid "Matomo (optional)"
msgstr "Matomo"

msgid "Matomo description"
msgstr "Matomo-analytiikkaohjelmistolla seurataan ja kehitetään verkkosivustoa käyttäjien tarpeita vastaavaksi."

msgid "Cookie name"
msgstr "Nimi"

msgid "Cookie set by"
msgstr "Evästeen asettaja"

msgid "Purpose of use"
msgstr "Käyttötarkoitus"

msgid "Voimassaoloaika"
msgstr "Period of validity"

msgid "A cookie of the Matomo statistics system"
msgstr "Matomo-tilastointijärjestelmän eväste"

msgid "Cookie days"
msgstr "päivää"

msgid "Accept all cookies"
msgstr "Hyväksy valitut evästeet"

msgid "Accept essential cookies"
msgstr "Hyväksy vain välttämättömät evästeet"

msgid "Cookie consent link"
msgstr "Evasteasetukset"

Binary file modified kuvaselaamo/locale/sv/LC_MESSAGES/django.mo
Binary file not shown.

0 comments on commit ac59550

Please sign in to comment.