Verified Commit 23115c9e authored by Laurent Heirendt's avatar Laurent Heirendt
Browse files

move js into place

parent a294ecb0
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
<script>
/* 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 = "{{ 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);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
/* loadMatomo: load the tracking code of the matomo instance */
function loadMatomo() {
if (settings.siteID > 0) {
var u = settings.matomoURL;
_paq.push(['setSiteId', settings.siteID]);
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setDoNotTrack', 1]);
_paq.push(['trackPageView']);
_paq.push(['setIgnoreClasses', ['no-tracking', 'colorbox']]);
_paq.push(['enableLinkTracking']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.defer = true;
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g,s);
}
}
/* showCookieBanner: show the banner */
function showCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
popup.slideDown('slow');
}
/* hideCookieBanner: show the banner */
function hideCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
console.log('removed the banner');
}
/* clearCookies: clear all cookies */
function clearCookies() {
var cookies = document.cookie.split('; ');
for (var i in cookies) {
var name = cookies[i].split('=')[0];
if (name.startsWith('_pk_')) {
Cookies.set(name, 0, { expires: -1, path: '/' });
}
}
}
$( document ).ready(function() {
/* accept */
$('.lap-cookies-accept').click(function (e) {
e.preventDefault(true);
Cookies.set('lap_cookie_agree', 1, { expires: parseInt(settings.expires), path: '/' });
hideCookieBanner();
jQuery('.lap-cookies-accept').addClass('disabled');
jQuery('.lap-cookies-refuse').removeClass('disabled');
jQuery(this).blur();
loadMatomo();
});
/* refuse */
$('.lap-cookies-refuse').click(function (e) {
e.preventDefault(true);
clearCookies();
Cookies.set('lap_cookie_agree', 0, { expires: parseInt(settings.expires), path: '/' });
hideCookieBanner();
jQuery('.lap-cookies-refuse').addClass('disabled');
jQuery('.lap-cookies-accept').removeClass('disabled');
jQuery(this).blur();
});
/* default mechanism */
if (window.doNotTrack || navigator.doNotTrack || navigator.msDoNotTrack || ('external' in window && 'msTrackingProtectionEnabled' in window.external)) {
if (window.doNotTrack == "1" || navigator.doNotTrack == "yes" || navigator.doNotTrack == "1" || navigator.msDoNotTrack == "1" || ('external' in window && 'msTrackingPronectionEnabled' in window.external && window.external.msTrackingProtectionEnabled())) {
/* Do Not Track is enabled => stop */
jQuery('.lap-cookies-accept, .lap-cookies-refuse').addClass('disabled');
}
} else {
lapCookieAgree = getCookie('lap_cookie_agree');
if (lapCookieAgree == '0') {
/* visitor refused cookies => remove Matomo trace if present */
jQuery('.lap-cookies-refuse').addClass('disabled');
clearCookies();
} else if (lapCookieAgree == '1') {
/* visitor accepted cookies => load Matomo */
jQuery('.lap-cookies-accept').addClass('disabled');
loadMatomo();
} else {
/* visitor did not choose yet */
showCookieBanner();
}
}
});
</script>
{% comment %}
Insert here CSS <link/> tags, and <style/> tags if needed.
{% endcomment %}
......@@ -18,6 +18,12 @@
{%- include css-imports.html -%}
{% if site.siteID > 0 %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script>
<script src="{{ '/assets/js/gdpr.js' | relative_url }}"></script>
{%- endif -%}
{%- if jekyll.environment == "review" -%}
<script defer
data-project-id='{{site.project_id}}'
......
/* 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 = "{{ 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);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
/* loadMatomo: load the tracking code of the matomo instance */
function loadMatomo() {
if (settings.siteID > 0) {
var u = settings.matomoURL;
_paq.push(['setSiteId', settings.siteID]);
_paq.push(['setTrackerUrl', u + 'matomo.php']);
_paq.push(['setDoNotTrack', 1]);
_paq.push(['trackPageView']);
_paq.push(['setIgnoreClasses', ['no-tracking', 'colorbox']]);
_paq.push(['enableLinkTracking']);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.defer = true;
g.async = true;
g.src = u + 'matomo.js';
s.parentNode.insertBefore(g,s);
}
}
/* showCookieBanner: show the banner */
function showCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
popup.slideDown('slow');
}
/* hideCookieBanner: show the banner */
function hideCookieBanner() {
var popup = jQuery('#lap-cookies-banner');
popup.hide();
console.log('removed the banner');
}
/* clearCookies: clear all cookies */
function clearCookies() {
var cookies = document.cookie.split('; ');
for (var i in cookies) {
var name = cookies[i].split('=')[0];
if (name.startsWith('_pk_')) {
Cookies.set(name, 0, { expires: -1, path: '/' });
}
}
}
$( document ).ready(function() {
/* accept */
$('.lap-cookies-accept').click(function (e) {
e.preventDefault(true);
Cookies.set('lap_cookie_agree', 1, { expires: parseInt(settings.expires), path: '/' });
hideCookieBanner();
jQuery('.lap-cookies-accept').addClass('disabled');
jQuery('.lap-cookies-refuse').removeClass('disabled');
jQuery(this).blur();
loadMatomo();
});
/* refuse */
$('.lap-cookies-refuse').click(function (e) {
e.preventDefault(true);
clearCookies();
Cookies.set('lap_cookie_agree', 0, { expires: parseInt(settings.expires), path: '/' });
hideCookieBanner();
jQuery('.lap-cookies-refuse').addClass('disabled');
jQuery('.lap-cookies-accept').removeClass('disabled');
jQuery(this).blur();
});
/* default mechanism */
if (window.doNotTrack || navigator.doNotTrack || navigator.msDoNotTrack || ('external' in window && 'msTrackingProtectionEnabled' in window.external)) {
if (window.doNotTrack == "1" || navigator.doNotTrack == "yes" || navigator.doNotTrack == "1" || navigator.msDoNotTrack == "1" || ('external' in window && 'msTrackingPronectionEnabled' in window.external && window.external.msTrackingProtectionEnabled())) {
/* Do Not Track is enabled => stop */
jQuery('.lap-cookies-accept, .lap-cookies-refuse').addClass('disabled');
}
} else {
lapCookieAgree = getCookie('lap_cookie_agree');
if (lapCookieAgree == '0') {
/* visitor refused cookies => remove Matomo trace if present */
jQuery('.lap-cookies-refuse').addClass('disabled');
clearCookies();
} else if (lapCookieAgree == '1') {
/* visitor accepted cookies => load Matomo */
jQuery('.lap-cookies-accept').addClass('disabled');
loadMatomo();
} else {
/* visitor did not choose yet */
showCookieBanner();
}
}
});
\ No newline at end of file
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