Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Miroslav Kratochvil
jekyll-theme-lcsb-default
Commits
d8218c44
Verified
Commit
d8218c44
authored
Apr 10, 2020
by
Laurent Heirendt
✈
Browse files
comments in js
parent
e0ab02a9
Changes
1
Hide whitespace changes
Inline
Side-by-side
_includes/css-imports.html
View file @
d8218c44
...
...
@@ -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.
analytics
url }}
"
;
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
:
'
/
'
});
hide
lap
CookieBanner
();
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
:
'
/
'
});
hide
lap
CookieBanner
();
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
'
);
clear
Matomo
();
clear
Cookies
();
}
else
if
(
lapCookieAgree
==
'
1
'
)
{
/* Visitor accepted our cookies => load Matomo */
/* visitor accepted cookies => load Matomo */
jQuery
(
'
.lap-cookies-accept
'
).
addClass
(
'
disabled
'
);
loadMatomo
();
}
else
{
/*
V
isitor did not choose yet */
show
lap
CookieBanner
();
/*
v
isitor did not choose yet */
showCookieBanner
();
}
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment