Skip to content

Commit

Permalink
Add user-consent js event
Browse files Browse the repository at this point in the history
  • Loading branch information
frankstrater committed Jul 21, 2020
1 parent 3ee51f9 commit 790fd41
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions _includes/user_consent.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ <h3>Where can I go with my questions?</h3>
<p>If you have questions about our processing of your personal data, or if you want to make use of one or more of your legal rights, then contact:</p>

<ul>
<li>Our privacy officer, who is available via: <a href="mailto:[email protected]">Webmaster</a> </li>
<li>Our privacy officer, who is available via: <a href="mailto:[email protected]">[email protected]</a> </li>
</ul>

</div>

<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Accept</button>
<button id="btn-accept-user-consent" type="button" class="btn btn-primary" data-dismiss="modal">Accept</button>
</div>
</div>
</div>
Expand Down
43 changes: 33 additions & 10 deletions assets/js/common.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
$(document).ready(function() {

// Browser recommendation
function isCookieSet(cookieName) {
return document.cookie.split(';').filter(item => item.trim().startsWith(cookieName + '=')).length > 0;
}

const isChrome = () => navigator.userAgent.indexOf('Chrome') > -1;
const cookieExists = (cookieName) => !!document.cookie.split(';').filter((item) => item.trim().startsWith(cookieName + '=')).length;
const setCookies = (cookieName) => {
const expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + 1);
document.cookie = cookieName + '=accepted; expires=' + expiryDate;
};
function setCookie(cookieName, intMonth) {
var expiryDate = new Date();
expiryDate.setMonth(expiryDate.getMonth() + intMonth);
document.cookie = cookieName + '=accepted; expires=' + expiryDate + '; path=/';
}

if(!isChrome() && !cookieExists('bg__browser-recommendation')) {
// Browser recommendation

if((navigator.userAgent.indexOf('Chrome') < 0) && !isCookieSet('bg__browser-recommendation')) {
$("#browser-recommendation").toast('show');
};

$('#browser-recommendation').on('hidden.bs.toast', function () {
setCookies('bg__browser-recommendation');
setCookie('bg__browser-recommendation', 1);
$("#browser-recommendation").toast('dispose');
});

// User consent

$('#menu_login a.nav-link').click(function(e) {
e.preventDefault();

if (!isCookieSet('bg__user-consent')) {
$('#user-consent').modal('show');
} else {
window.location = $(this).attr('href');
};
});

$('#btn-accept-user-consent').click(function(e) {
e.preventDefault();

setCookie('bg__user-consent', 6);

var href = $('#menu_login a.nav-link').attr('href');
window.location = href;
});

});

0 comments on commit 790fd41

Please sign in to comment.