Skip to content

Commit a806960

Browse files
authored
Add persistence to ad banner (#710)
* feature: add persistence to the ad banner with localStorage * fix: smooth transition * fix: remove class not required * update copy for best of devday * remove not used properties * delete GH test action * move GH test action * fix: fixed height logo hero banner * fix: fixed height logo Auth0 by Okta * fix: render the ttb banner smoothly when loading
1 parent c4ecc6d commit a806960

File tree

5 files changed

+133
-15
lines changed

5 files changed

+133
-15
lines changed
File renamed without changes.

src/website/top-banner.js

+95-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,103 @@
1+
const MESSAGE_BAR_STATE = {
2+
CLOSED: "CLOSED",
3+
OPEN: "OPEN",
4+
};
5+
6+
const MESSAGE_BAR_STATUS = {
7+
ACTIVE: "ACTIVE",
8+
INACTIVE: "INACTIVE",
9+
};
10+
11+
const messageBar = {
12+
status: MESSAGE_BAR_STATUS.ACTIVE,
13+
id: {
14+
key: "messageBar_id",
15+
value: "BEST_OF_DEVDAY_2024",
16+
},
17+
state: {
18+
key: "messageBar_state",
19+
},
20+
};
21+
22+
const closeMessageBar = () => {
23+
const isMessageBarActive = messageBar.status === MESSAGE_BAR_STATUS.ACTIVE;
24+
25+
if (!isMessageBarActive) {
26+
return;
27+
}
28+
29+
window.localStorage.setItem(messageBar.state.key, MESSAGE_BAR_STATE.CLOSED);
30+
31+
document.querySelector(".top-banner-bg").classList.add("closed");
32+
document.querySelector(".top-banner").classList.add("closed");
33+
document.querySelector(".content").classList.remove("top-banner-open");
34+
document.querySelector(".top-mobile").classList.remove("top-banner-open");
35+
document.querySelector(".navbar").classList.remove("top-banner-open");
36+
};
37+
38+
const renderTopBanner = () => {
39+
document.querySelector(".top-banner-bg").classList.remove("closed");
40+
document.querySelector(".top-banner").classList.remove("closed");
41+
document.querySelector(".content").classList.add("top-banner-open");
42+
document.querySelector(".top-mobile").classList.add("top-banner-open");
43+
document.querySelector(".navbar").classList.add("top-banner-open");
44+
};
45+
46+
const loadBannerStateFromLocalStorage = () => {
47+
let messageBarId = window.localStorage.getItem(messageBar.id.key);
48+
let messageBarState = window.localStorage.getItem(messageBar.state.key);
49+
50+
if (!messageBarId) {
51+
window.localStorage.setItem(messageBar.id.key, messageBar.id.value);
52+
messageBarId = window.localStorage.getItem(messageBar.id.key);
53+
}
54+
55+
if (!messageBarState) {
56+
window.localStorage.setItem(messageBar.state.key, MESSAGE_BAR_STATE.OPEN);
57+
messageBarState = window.localStorage.getItem(messageBar.state.key);
58+
}
59+
60+
switch (messageBar.status) {
61+
case MESSAGE_BAR_STATUS.ACTIVE: {
62+
const isExistingCta = messageBarId === messageBar.id.value;
63+
64+
if (!isExistingCta) {
65+
window.localStorage.setItem(messageBar.id.key, messageBar.id.value);
66+
window.localStorage.setItem(
67+
messageBar.state.key,
68+
MESSAGE_BAR_STATE.OPEN
69+
);
70+
71+
renderTopBanner();
72+
73+
return;
74+
}
75+
76+
switch (messageBarState) {
77+
case MESSAGE_BAR_STATE.OPEN: {
78+
renderTopBanner();
79+
80+
return;
81+
}
82+
default: {
83+
return;
84+
}
85+
}
86+
}
87+
default: {
88+
return;
89+
}
90+
}
91+
};
92+
193
export function TopBanner() {
294
document.addEventListener("DOMContentLoaded", function () {
95+
loadBannerStateFromLocalStorage();
96+
397
document
498
.querySelector(".close-top-banner")
599
.addEventListener("click", () => {
6-
document.querySelector(".top-banner-bg").classList.add("closed");
7-
document.querySelector(".top-banner").classList.add("closed");
8-
document.querySelector(".top-banner-spacer").classList.add("hide");
9-
document.querySelector(".navbar").classList.remove("top-banner-open");
100+
closeMessageBar();
10101
});
11102
});
12103
}

stylus/website/index.styl

+32-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ body {
126126

127127
&.top-banner-open {
128128
margin-top: 5px;
129-
transition: all 0.2s linear;
129+
transition: margin-top 0.4s linear;
130130

131131
+breakpoint('tablet') {
132132
margin-top: 48px;
@@ -141,11 +141,21 @@ body {
141141
border-bottom: 1px solid rgba(#4A4A4A, 0.6);
142142
clearfix();
143143
margin: 0 -15px;
144+
padding-top: 0;
145+
transition: padding-top 0.4s linear;
144146

145147
+breakpoint('tablet') {
146148
border: none;
147149
margin: 0;
148150
}
151+
152+
&.top-banner-open {
153+
padding-top: 50px;
154+
155+
+breakpoint('tablet') {
156+
padding-top: 0;
157+
}
158+
}
149159
}
150160

151161
.menu-trigger {
@@ -299,6 +309,7 @@ body {
299309
position: absolute;
300310
right: 15px;
301311
top: 28px;
312+
height: 32px;
302313
}
303314

304315
+breakpoint('desktop') {
@@ -442,6 +453,19 @@ body {
442453
}
443454
}
444455

456+
.content {
457+
+breakpoint('tablet') {
458+
padding-top: 0;
459+
transition: padding-top 0.4s linear;
460+
}
461+
462+
&.top-banner-open {
463+
+breakpoint('tablet') {
464+
padding-top: 50px;
465+
}
466+
}
467+
}
468+
445469
// banner-jwt
446470
.banner-jwt {
447471
background: black;
@@ -503,10 +527,12 @@ body {
503527

504528
img {
505529
width: 70px;
530+
height: 70px;
506531
display: block;
507532

508533
+breakpoint('desktop') {
509534
width: 80px;
535+
height: 80px;
510536
}
511537
}
512538
}
@@ -1848,13 +1874,14 @@ footer {
18481874
width: 100%;
18491875
height: 48px;
18501876
z-index: 100;
1877+
transition: height 0.4s linear;
18511878

18521879
&.closed {
18531880
visibility: hidden;
18541881
height: 0;
18551882
opacity: 0;
18561883
padding: 0;
1857-
transition: all 0.1s linear;
1884+
transition: height 0.4s linear;
18581885
}
18591886
}
18601887

@@ -1875,13 +1902,14 @@ footer {
18751902
left: 0;
18761903
right: 0;
18771904
overflow: hidden;
1905+
transition: all 0.4s linear;
18781906

18791907
&.closed {
18801908
visibility: hidden;
18811909
height: 0;
18821910
opacity: 0;
18831911
padding: 0;
1884-
transition: all 0.2s linear;
1912+
transition: all 0.4s linear;
18851913
}
18861914

18871915
.top-banner-container {
@@ -1947,6 +1975,6 @@ footer {
19471975

19481976
&.hide {
19491977
height: 0;
1950-
transition: all 0.2s linear;
1978+
transition: all 0.4s linear;
19511979
}
19521980
}

views/website/layout.pug

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ html(lang='en')
4545

4646
include ./navigation.pug
4747

48-
block content
48+
.content
49+
block content
4950

5051
footer
5152
.container

views/website/navigation.pug

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
.top-banner-bg
2-
.top-banner
1+
.top-banner-bg.closed
2+
.top-banner.closed
33
.top-banner-container
4-
a(href="https://a0.to/jwt-io-feedback" target="_blank") Learn about the upcoming changes to jwt.io and share your feedback
4+
a(href="https://pages.okta.com/2024-11-WBN-Best-of-Dev-Day_LP/" target="_blank") Missed DevDay24? Register for the Best of DevDay
55
span(aria-hiden="true")
66
button.close-top-banner +
77

8-
.top-banner-spacer
9-
10-
nav.navbar.closed.top-banner-open
8+
nav.navbar
119
.container
1210
.top-mobile
1311
.menu-trigger

0 commit comments

Comments
 (0)