-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
144 lines (134 loc) · 6.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap Cookie Banner</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<!-- Cookie Banner -->
<link rel="stylesheet" href="./src/cookie-banner.css">
<script async src="./src/cookie-banner.js"></script>
<!-- Simple script to switch bootstrap theme -->
<script>
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'dark');
console.log('switching to dark theme');
}
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
document.documentElement.setAttribute('data-bs-theme', 'light');
console.log('switching to light theme');
}
</script>
</head>
<body>
<nav class="navbar navbar-expand-lg">
<div class="container-fluid">
<span class="navbar-brand">
Bootstrap Cookie Banner
<span class="badge rounded-pill bg-primary">Demo</span></h1>
</span>
</div>
</nav>
<main class="container mt-5">
<p>
Demo website for Bootstrap Cookie Banner. If you don't see the cookie banner below, clear the localstorage.
</p>
<ul>
<li>
<a href="https://github.com/kolappannathan/bootstrap-cookie-banner" target="_blank">GitHub</a>
</li>
<li>
Bootstrap Version used: 5.3.3
</li>
</ul>
<h5>Code </h5>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="HTML-tab" data-bs-toggle="tab" data-bs-target="#HTML" type="button"
role="tab" aria-controls="HTML" aria-selected="true">HTML</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="css-tab" data-bs-toggle="tab" data-bs-target="#css" type="button" role="tab"
aria-controls="css" aria-selected="false">CSS</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="js-tab" data-bs-toggle="tab" data-bs-target="#js" type="button" role="tab"
aria-controls="js" aria-selected="false">Javascript</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="HTML" role="tabpanel" aria-labelledby="HTML-tab">
<code>
<!-- Cookie Banner --><br>
<div id="cb-cookie-banner" class="alert alert-dark text-center mb-0" role="alert"><br>
🍪 This website uses cookies to ensure you get the best experience on our website.<br>
<a href="https://www.cookiesandyou.com/" target="blank">Learn more</a><br>
<button type="button" class="btn btn-primary btn-sm ms-3" onclick="window.cb_hideCookieBanner()"><br>
I Got It<br>
</button><br>
</div><br>
<!-- End of Cookie Banner --><br>
</code>
</div>
<div class="tab-pane fade" id="css" role="tabpanel" aria-labelledby="css-tab">
<code>
#cb-cookie-banner {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
z-index: 999;
border-radius: 0;
display: none;
}
</code>
</div>
<div class="tab-pane fade" id="js" role="tabpanel" aria-labelledby="js-tab">
<code>
/* Javascript to show and hide cookie banner using localstorage */
<br>/* Shows the Cookie banner */
<br>function showCookieBanner(){
<br> let cookieBanner = document.getElementById("cb-cookie-banner");
<br> cookieBanner.style.display = "block";
<br>}
<br>
<br>/* Hides the Cookie banner and saves the value to localstorage */
<br>function hideCookieBanner(){
<br> localStorage.setItem("cb_isCookieAccepted", "yes");
<br> let cookieBanner = document.getElementById("cb-cookie-banner");
<br> cookieBanner.style.display = "none";
<br>}
<br>
<br>/* Checks the localstorage and shows Cookie banner based on it. */
<br>function initializeCookieBanner(){
<br> let isCookieAccepted = localStorage.getItem("cb_isCookieAccepted");
<br> if(isCookieAccepted === null)
<br> {
<br> localStorage.setItem("cb_isCookieAccepted", "no");
<br> showCookieBanner();
<br> }
<br> if(isCookieAccepted === "no"){
<br> showCookieBanner();
<br> }
<br>}
<br>
<br>// Assigning values to window object
<br>window.onload = initializeCookieBanner();
<br>window.cb_hideCookieBanner = hideCookieBanner;
</code>
</div>
</div>
</main>
<!-- Cookie Banner -->
<div id="cb-cookie-banner" class="alert alert-dark text-center mb-0" role="alert">
🍪 This website uses cookies to ensure you get the best experience on our website.
<a href="https://www.cookiesandyou.com/" target="blank">Learn more</a>
<button type="button" class="btn btn-primary btn-sm ms-3" onclick="window.cb_hideCookieBanner()">
I Got It
</button>
</div>
<!-- End of Cookie Banner -->
</body>
</html>