-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathnavbar.html
More file actions
353 lines (324 loc) · 12.7 KB
/
navbar.html
File metadata and controls
353 lines (324 loc) · 12.7 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<header>
<nav
class="td-navbar navbar-dark js-navbar-scroll td-navbar-cover navbar-bg-onscroll--fade"
>
<div class="container-fluid flex-column flex-md-row">
<a class="navbar-brand" href="/" aria-label="Home">
<span class="navbar-brand__logo navbar-logo">
{{ $svg := resources.Get "icons/logo.svg" }}
<img class="footer-logo" src="/images/logo.svg" alt="logo" data-modal="false" />
</span>
<span class="navbar-brand__name"></span
></a>
<div
class="td-navbar-nav-scroll main-nav-items flex-grow-1"
id="main_navbar"
>
<ul class="navbar-nav d-flex align-items-center" >
<!-- <li class="nav-item nav-external">
<a class="nav-link nav-link-external" href="https://playground.meshery.io" target="_blank">
<span>Playground</span>
</a>
</li> -->
<div class="d-flex">
<li class="nav-item">
<a id="cloud" class="nav-link" href="/cloud/"> Cloud</a>
</li>
<li class="nav-item">
<a id="kanvas" class="nav-link" href="/kanvas/"> Kanvas</a>
</li>
<li class="nav-item dropdown" data-bs-theme="dark">
<div
class="nav-link"
id="resourcesDropdown"
role="button"
data-toggle="dropdown"
>
Resources<span class="down-icon"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 4a.5.5 0 0 1 .5.5v5.793l2.146-2.147a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 1 1 .708-.708L7.5 10.293V4.5A.5.5 0 0 1 8 4"/></svg></span>
</div>
<div class="dropdown-menu dropdown-menu--col" aria-labelledby="resourcesDropdown" style="visibility:hidden;">
<a
class="dropdown-item dropdown-item--row"
href="https://cloud.layer5.io/academy"
target="_blank"
aria-label="Academy"
>
<div class="logo-container">
<img
src="/images/academy-icon.svg"
alt="Meshery Logo"
/>
</div>
<span>Academy</span>
</a>
<div class="dropdown-divider"></div>
<a
class="dropdown-item dropdown-item--row"
href="/videos"
aria-label="Videos"
>
<div class="logo-container">
<img
src="/images/video-play.svg"
alt="Meshery Logo"
/>
</div>
<span>Videos</span>
</a>
</div>
</li>
</div>
<div class="d-flex ms-auto">
<!-- <li class="nav-item">
<a class="nav-link" href="/cloud/tutorials/"> Tutorials</a>
</li> -->
<li class="d-none d-lg-block nav-item">
<!-- <div class="td-search">
<div class="td-search__icon"></div>
<input type="search" class="td-search__input form-control td-search-input" placeholder="Search"
aria-label="Search this site…" autocomplete="off">
<button id="searchKey" style="margin-left:-2rem;" class="kbc-button kbc-button-xs">/</button>
</div> -->
{{ partial "search-input-nav.html" . }}
</li>
<li class="nav-item dropdown" data-bs-theme="dark">
<div
class="nav-link"
id="productsDropdown"
role="button"
data-toggle="dropdown"
style="padding-top:6px"
>
<img width="28px" src="/images/grid-icon.svg" alt="Products" class="grid-icon" data-modal="false" />
</div>
<div class="dropdown-menu" aria-labelledby="productsDropdown" style="margin-left:-4.5rem;visibility:hidden;">
<a
class="dropdown-item"
href="https://docs.meshery.io/"
aria-label="Meshery Docs"
target="_blank"
>
<div class="logo-container">
<img
src="/images/logos/meshery-light-icon.svg"
alt="Meshery Logo"
/>
</div>
<span>Meshery</span></a
>
<div class="dropdown-divider"></div>
<a
class="dropdown-item"
href="https://layer5.io/cloud-native-management/kanvas"
aria-label="Kanvas"
target="_blank"
>
<div class="logo-container">
<img
src="/images/logos/kanvas-icon-color.svg"
alt="Layer5 Kanvas Logo"
style="height:40px; width:40px;"
/>
</div>
<span>Kanvas</span></a
>
<div class="dropdown-divider"></div>
<a
class="dropdown-item"
href="https://layer5.io/cloud-native-management/catalog"
aria-label="Catalog"
target="_blank"
>
<div class="logo-container">
<img
src="/images/logos/catalog.svg"
alt="Layer5 Catalog Logo"
/>
</div>
<span>Catalog</span></a
>
<div class="dropdown-divider"></div>
<a
class="dropdown-item"
href="https://smp-spec.io/"
aria-label="SMP Spec"
target="_blank"
>
<div class="logo-container">
<img
src="/images/logos/smp-light.png"
alt="Layer5 Cloud Native Performance Logo"
/>
</div>
<span>CNP</span></a
>
<div class="dropdown-divider"></div>
<a
class="dropdown-item"
href="https://getnighthawk.dev/"
aria-label="Nighthawk"
target="_blank"
>
<div class="logo-container">
<img
src="/images/logos/nighthawk-logo.svg"
alt="Layer5 Nighthawk Logo"
/>
</div>
<span>Nighthawk</span></a
>
<div class="dropdown-divider"></div>
<a
class="dropdown-item"
href="https://cloud.layer5.io/academy"
target="_blank"
aria-label="Layer5 Academy"
>
<div class="logo-container">
<img
src="/images/logos/academy.svg"
alt="Layer5 Academy Logo"
/>
</div>
<span>Academy</span></a
>
</div>
</li>
<li class="nav-item" id="signin-button" style="display: none;">
<a class="nav-link" href="https://cloud.layer5.io/login" target="_blank">Sign In</a>
</li>
<li class="nav-item dropdown" data-bs-theme="dark" id="userlist" style="display: none;">
<a href="https://cloud.layer5.io" id="user-profile-url" aria-label="User Profile">
<div
class="nav-link avatar-container"
id="avatarDropdown"
role="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"
>
</div>
</a>
</li>
</div>
</ul>
</div>
</div>
</nav>
<script>
function setupDropdown(dropdownId) {
const dropdown = document.querySelector(`#${dropdownId}`);
const dropdownMenu = dropdown.nextElementSibling;
dropdown.addEventListener("click", function (event) {
event.stopPropagation();
// hide any other active dropdowns
const allActiveDropdowns = document.querySelectorAll(".nav-link.current");
allActiveDropdowns.forEach((otherDropdown) => {
if (otherDropdown !== dropdown) {
otherDropdown.classList.remove("current");
otherDropdown.nextElementSibling.classList.remove("show");
otherDropdown.nextElementSibling.style.visibility = "hidden";
}
});
if (dropdown.classList.contains("current")) {
dropdown.classList.remove("current");
dropdownMenu.classList.remove("show");
dropdownMenu.style.visibility = "hidden";
} else {
dropdown.classList.toggle("current");
dropdownMenu.classList.toggle("show");
dropdownMenu.style.visibility = "visible";
}
});
document.body.addEventListener('click', function() {
if (dropdown.classList.contains("current")) {
dropdown.classList.remove("current");
dropdownMenu.classList.remove("show");
dropdownMenu.style.visibility = "hidden";
}
});
}
setupDropdown("productsDropdown");
setupDropdown("resourcesDropdown");
// console.log(window.location.pathname == "/cloud/");
// check if the current page ic cloud
let cur;
if (window.location.pathname.includes("/cloud/"))
cur = document.querySelector("#cloud");
else if (window.location.pathname.includes("/kanvas/"))
cur = document.querySelector("#kanvas");
if (cur) {
cur.classList.add("current");
cur.style.pointerEvents = "none";
cur.style.cursor = "default";
}
let isUserAuthenticated = false;
let expiredToken = "";
function removeCookie(cookieName) {
document.cookie = cookieName + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
}
function getCookieValue(cookieName) {
const cookies = document.cookie.split(";");
for (let i = 0; i < cookies.length; i++) {
let cookie = cookies[i].trim();
if (cookie.indexOf(cookieName + "=") === 0) {
return cookie.substring(cookieName.length + 1);
}
}
return null;
}
const checkUserAuth = async () => {
try {
const token = getCookieValue("provider_token");
if (!token || token === expiredToken) { // cookie doesn't exist or has expired (due to user logout)
if (isUserAuthenticated) {
showSignInButton();
isUserAuthenticated = false;
}
throw new Error("missing or expired cookie");
}
const re = await fetch("https://cloud.layer5.io/api/identity/users/profile", {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`,
},
});
if (re.status === 401) { // cookie has expired
expiredToken = token;
throw new Error("unauthorized");
}
if (re.status !== 200) {
throw new Error(`HTTP error! status: ${re.status}`);
}
const response = await re.json();
updateUI(response);
} catch (error) {
// console.error("could not set user details.", error);
showSignInButton();
}
};
function updateUI(response) {
document.getElementById('signin-button').style.display = 'none';
document.getElementById("userlist").style.display = "block";
const avatarUrl = response.avatar_url;
const avatarContainer = document.querySelector('.avatar-container');
avatarContainer.style.backgroundImage = `url("${avatarUrl}")`;
avatarContainer.style.backgroundSize = 'cover';
const userId = response.id;
const cloudLink = document.getElementById('user-profile-url');
cloudLink.href = `https://cloud.layer5.io/user/${userId}`;
isUserAuthenticated = true;
}
function showSignInButton() {
document.getElementById("userlist").style.display = "none";
document.getElementById("signin-button").style.display = "block";
}
function handleVisibilityChange() {
if (document.visibilityState === 'visible' && !isUserAuthenticated ) {
checkUserAuth();
}
}
checkUserAuth();
document.addEventListener('visibilitychange', handleVisibilityChange);
</script>
</header>