Skip to content

Commit 77ce29b

Browse files
committed
Add cookie banner
1 parent dc7e71c commit 77ce29b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

static/css/cookie-banner.css

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#futurama-api-cookie-banner {
2+
position: fixed;
3+
bottom: 0;
4+
left: 0;
5+
width: 100%;
6+
z-index: 999;
7+
border-radius: 0;
8+
display: none;
9+
}

static/js/cookie-banner.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var FuturamaAPICookieName = "FuturamaAPI_CookieAccepted";
2+
var cookieBannerId = "futurama-api-cookie-banner"
3+
4+
function showCookieBanner(){
5+
let cookieBanner = document.getElementById(cookieBannerId);
6+
cookieBanner.style.display = "block";
7+
}
8+
9+
function hideCookieBanner(){
10+
localStorage.setItem(FuturamaAPICookieName, true);
11+
12+
let cookieBanner = document.getElementById(cookieBannerId);
13+
cookieBanner.style.display = "none";
14+
}
15+
16+
function initializeCookieBanner(){
17+
if(localStorage.getItem(FuturamaAPICookieName) === null) {
18+
showCookieBanner();
19+
}
20+
}
21+
22+
window.onload = initializeCookieBanner();
23+
window.futuramaapi_hideCookieBanner = hideCookieBanner;

templates/base.html

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<title>{% block title %}Welcome{% endblock %} | Futurama API</title>
1414
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
1515
<link href="{{ relative_path_for('static', path='/css/base.css') }}" rel="stylesheet">
16+
<link href="{{ relative_path_for('static', path='/css/cookie-banner.css') }}" rel="stylesheet">
1617
{% block extra_styles %}{% endblock %}
1718
</head>
1819
<body>
@@ -147,6 +148,20 @@ <h3>Hi, {{ current_user.full_name }}, welcome to</h3>
147148
</main>
148149
<footer>
149150
</footer>
151+
<div
152+
id="futurama-api-cookie-banner"
153+
class="alert alert-dark text-center mb-0"
154+
role="alert"
155+
>
156+
This website uses cookies to ensure you get the best experience on our website.
157+
<button
158+
type="button"
159+
class="btn btn-primary btn-sm ms-3"
160+
onclick="window.futuramaapi_hideCookieBanner()"
161+
>
162+
I Got It
163+
</button>
164+
</div>
150165
{% if _project.G_TAG %}
151166
<script
152167
async
@@ -164,6 +179,9 @@ <h3>Hi, {{ current_user.full_name }}, welcome to</h3>
164179
integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
165180
crossorigin="anonymous"
166181
></script>
182+
<script
183+
src="{{ relative_path_for('static', path='/js/cookie-banner.js') }}"
184+
></script>
167185
{% block extra_scripts %}{% endblock %}
168186
</body>
169187
</html>

0 commit comments

Comments
 (0)