Verified Commit d8218c44 authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

comments in js

parent e0ab02a9
......@@ -70,13 +70,20 @@
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
<script>
/* Matomo global variable */
/* Matomo global variable
note: most code has been inspired from:
https://edps.europa.eu/sites/edp/modules/features/edpsweb_cookies/js/cookies-popup.js
*/
var _paq = window._paq || _paq || [];
var settings = [];
settings.expires = 180;
settings.matomoURL = "https://analytics.lcsb.uni.lu/hub/";
settings.siteID = 4;
settings.expires = "{{ site.cookies_expire }}";
settings.matomoURL = "{{ site.analyticsurl }}";
settings.siteID = "{{ site.siteID }}";
/*
getCookie: retrieve a cookie that has been set.
inspired from https://www.w3schools.com/js/js_cookies.asp
*/
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
......@@ -93,6 +100,7 @@ function getCookie(cname) {
return "";
}
/* loadMatomo: load the tracking code of the matomo instance */
function loadMatomo() {
var u = settings.matomoURL;
_paq.push(['setSiteId', settings.siteID]);
......@@ -108,18 +116,23 @@ function loadMatomo() {
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g,s);
}
function showlapCookieBanner() {
/* showCookieBanner: show the banner */
function showCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
popup.slideDown('slow');
console.log('popped the banner');
}
function hidelapCookieBanner() {
/* hideCookieBanner: show the banner */
function hideCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
console.log('removed the banner');
}
function clearMatomo() {
/* clearCookies: clear all cookies */
function clearCookies() {
var cookies = document.cookie.split('; ');
for (var i in cookies) {
var name = cookies[i].split('=')[0];
......@@ -127,7 +140,6 @@ function clearMatomo() {
Cookies.set(name, 0, { expires: -1, path: '/' });
}
}
console.log('cleared all cookies');
}
$( document ).ready(function() {
......@@ -135,9 +147,8 @@ $( document ).ready(function() {
/* accept */
$('.lap-cookies-accept').click(function (e) {
e.preventDefault(true);
console.log('clicked on accept');
Cookies.set('lap_cookie_agree', 1, { expires: parseInt(settings.expires), path: '/' });
hidelapCookieBanner();
hideCookieBanner();
jQuery('.lap-cookies-accept').addClass('disabled');
jQuery('.lap-cookies-refuse').removeClass('disabled');
jQuery(this).blur();
......@@ -147,10 +158,9 @@ $( document ).ready(function() {
/* refuse */
$('.lap-cookies-refuse').click(function (e) {
e.preventDefault(true);
console.log('clicked on refuse');
clearMatomo();
clearCookies();
Cookies.set('lap_cookie_agree', 0, { expires: parseInt(settings.expires), path: '/' });
hidelapCookieBanner();
hideCookieBanner();
jQuery('.lap-cookies-refuse').addClass('disabled');
jQuery('.lap-cookies-accept').removeClass('disabled');
jQuery(this).blur();
......@@ -166,18 +176,16 @@ $( document ).ready(function() {
lapCookieAgree = getCookie('lap_cookie_agree');
if (lapCookieAgree == '0') {
/* Visitor refused our cookies => remove Matomo trace if present */
/* visitor refused cookies => remove Matomo trace if present */
jQuery('.lap-cookies-refuse').addClass('disabled');
clearMatomo();
clearCookies();
} else if (lapCookieAgree == '1') {
/* Visitor accepted our cookies => load Matomo */
/* visitor accepted cookies => load Matomo */
jQuery('.lap-cookies-accept').addClass('disabled');
loadMatomo();
} else {
/* Visitor did not choose yet */
showlapCookieBanner();
/* visitor did not choose yet */
showCookieBanner();
}
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment