Verified Commit 57a11695 authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

fix behavior

parent 8533dd86
......@@ -7,16 +7,17 @@
<div class="banner-text">{{ site.banner_text }}</div>
</div>
<div>
<div class="banner-checkboxes">
<label class="input-toggle">
<input type="checkbox" checked disabled>
<input id="checkbox-1" type="checkbox" checked disabled>
<span></span>
</label>&nbsp;&nbsp;&nbsp;Necessary
</label>
<span class="checkbox-label">Necessary</span>
<label class="input-toggle">
<input type="checkbox">
<input id="checkbox-2" type="checkbox">
<span></span>
</label>&nbsp;&nbsp;&nbsp;Analytics
</label>
<span class="checkbox-label">Analytics</span>
</div>
<div class="banner-buttons">
......
......@@ -85,7 +85,7 @@ function setCookie(name, value) {
}
function isCookieSetTo(val) {
return document.cookie.indexOf(settings.cookieName + '=1') > -1;
return document.cookie.indexOf(settings.cookieName + '=' + val) > -1;
}
/*
......@@ -105,14 +105,12 @@ function hasConsent() {
/*
* accept: accept the cookies
*/
function accept(cookieMgmt) {
function accept() {
// action
loadMatomo();
// cookie management
if (cookieMgmt) {
setCookie(settings.cookieName, 1);
}
setCookie(settings.cookieName, 1);
// feedback
hideBanner();
......@@ -121,17 +119,19 @@ function accept(cookieMgmt) {
// style
$('.lap-cookies-accept').addClass('selected');
$('.lap-cookies-refuse').removeClass('selected');
$('input#checkbox-2')[0].checked = true;
}
/*
* accept: refuse the cookies
*/
function refuse(cookieMgmt) {
function refuse(doNotTrack) {
// action
clearCookies();
// cookie management
if (cookieMgmt) {
// only set the refusal cookie if actually allowed (i.e. doNotTrack = false)
if (doNotTrack === false) {
setCookie(settings.cookieName, 0);
}
......@@ -142,6 +142,7 @@ function refuse(cookieMgmt) {
// style
$('.lap-cookies-refuse').addClass('selected');
$('.lap-cookies-accept').removeClass('selected');
$('input#checkbox-2')[0].checked = false;
}
/*
......@@ -157,7 +158,7 @@ $(document).ready(function() {
// refuse
$('.lap-cookies-refuse').click(function(e) {
e.preventDefault(true);
refuse();
refuse(false);
});
// detect if the visitor is a bot or not
......@@ -170,16 +171,16 @@ $(document).ready(function() {
var doNotTrack = false;
// do nothing if it is a bot or if DoNotTrack is active
if (isBot || !isToTrack || !hasConsent()) {
refuse(false);
if (isBot || !isToTrack || hasConsent() === false) {
doNotTrack = true;
refuse(doNotTrack);
}
if (doNotTrack === false) {
if (hasConsent() === true) {
// user has already given consent to use cookies to tracking
accept(true);
} else if (hasConsent() === false) {
accept();
} else if (hasConsent() === false || hasConsent() === null) {
// all other cases considered, show banner
showBanner();
}
......
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