Skip to content

Add persistence to ad banner #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
2 changes: 2 additions & 0 deletions src/website/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
shareJwtTextElement,
} from "./dom-elements.js";
import { CCPAModal } from "./ccpa-modal.js";
import { TopBanner } from "./top-banner.js";

import queryString from "querystring";

Expand Down Expand Up @@ -55,3 +56,4 @@ setupHighlighting();
setupJwtCounter();
setupShareJwtButton(shareJwtButton, shareJwtTextElement);
CCPAModal();
TopBanner();
2 changes: 2 additions & 0 deletions src/website/introduction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { CCPAModal } from "../ccpa-modal.js";
import { setupJwtCounter } from "../counter.js";
import { setupHighlighting } from "../highlighting.js";
import { setupNavbar } from "../navbar.js";
import { TopBanner } from "../top-banner.js";

// Initialization
setupNavbar();
setupHighlighting();
setupJwtCounter();
CCPAModal();
TopBanner();
2 changes: 2 additions & 0 deletions src/website/libraries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CCPAModal } from "../ccpa-modal.js";
import { setupJwtCounter } from "../counter.js";
import { setupHighlighting } from "../highlighting.js";
import { setupNavbar } from "../navbar.js";
import { TopBanner } from "../top-banner.js";
import { setupLibraries } from "./libraries.js";

// Initialization
Expand All @@ -10,3 +11,4 @@ setupLibraries();
setupHighlighting();
setupJwtCounter();
CCPAModal();
TopBanner();
97 changes: 93 additions & 4 deletions src/website/top-banner.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,101 @@
const MESSAGE_BAR_STATE = {
CLOSED: "CLOSED",
OPEN: "OPEN",
};

const MESSAGE_BAR_STATUS = {
ACTIVE: "ACTIVE",
INACTIVE: "INACTIVE",
};

const messageBar = {
status: MESSAGE_BAR_STATUS.ACTIVE,
id: {
key: "messageBar_id",
value: "BEST_OF_DEVDAY_2024",
},
state: {
key: "messageBar_state",
},
};

const closeMessageBar = () => {
const isMessageBarActive = messageBar.status === MESSAGE_BAR_STATUS.ACTIVE;

if (!isMessageBarActive) {
return;
}

window.localStorage.setItem(messageBar.state.key, MESSAGE_BAR_STATE.CLOSED);

document.querySelector(".top-banner-bg").classList.add("closed");
document.querySelector(".top-banner").classList.add("closed");
document.querySelector(".top-banner-spacer").classList.add("hide");
document.querySelector(".navbar").classList.remove("top-banner-open");
};

const renderTopBanner = () => {
document.querySelector(".top-banner-bg").classList.remove("closed");
document.querySelector(".top-banner").classList.remove("closed");
document.querySelector(".top-banner-spacer").classList.remove("hide");
document.querySelector(".navbar").classList.add("top-banner-open");
};

const loadBannerStateFromLocalStorage = () => {
let messageBarId = window.localStorage.getItem(messageBar.id.key);
let messageBarState = window.localStorage.getItem(messageBar.state.key);

if (!messageBarId) {
window.localStorage.setItem(messageBar.id.key, messageBar.id.value);
messageBarId = window.localStorage.getItem(messageBar.id.key);
}

if (!messageBarState) {
window.localStorage.setItem(messageBar.state.key, MESSAGE_BAR_STATE.OPEN);
messageBarState = window.localStorage.getItem(messageBar.state.key);
}

switch (messageBar.status) {
case MESSAGE_BAR_STATUS.ACTIVE: {
const isExistingCta = messageBarId === messageBar.id.value;

if (!isExistingCta) {
window.localStorage.setItem(messageBar.id.key, messageBar.id.value);
window.localStorage.setItem(
messageBar.state.key,
MESSAGE_BAR_STATE.OPEN
);

renderTopBanner();

return;
}

switch (messageBarState) {
case MESSAGE_BAR_STATE.OPEN: {
renderTopBanner();

return;
}
default: {
return;
}
}
}
default: {
return;
}
}
};

export function TopBanner() {
document.addEventListener("DOMContentLoaded", function () {
loadBannerStateFromLocalStorage();

document
.querySelector(".close-top-banner")
.addEventListener("click", () => {
document.querySelector(".top-banner-bg").classList.add("closed");
document.querySelector(".top-banner").classList.add("closed");
document.querySelector(".top-banner-spacer").classList.add("hide");
document.querySelector(".navbar").classList.remove("top-banner-open");
closeMessageBar();
});
});
}
10 changes: 6 additions & 4 deletions stylus/website/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ body {

&.top-banner-open {
margin-top: 5px;
transition: all 0.2s linear;
transition: all 0.4s linear;

+breakpoint('tablet') {
margin-top: 48px;
Expand Down Expand Up @@ -1848,13 +1848,14 @@ footer {
width: 100%;
height: 48px;
z-index: 100;
transition: all 0.4s linear;

&.closed {
visibility: hidden;
height: 0;
opacity: 0;
padding: 0;
transition: all 0.1s linear;
transition: all 0.4s linear;
}
}

Expand All @@ -1875,13 +1876,14 @@ footer {
left: 0;
right: 0;
overflow: hidden;
transition: all 0.4s linear;

&.closed {
visibility: hidden;
height: 0;
opacity: 0;
padding: 0;
transition: all 0.2s linear;
transition: all 0.4s linear;
}

.top-banner-container {
Expand Down Expand Up @@ -1947,6 +1949,6 @@ footer {

&.hide {
height: 0;
transition: all 0.2s linear;
transition: all 0.4s linear;
}
}
11 changes: 10 additions & 1 deletion views/website/navigation.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
nav.navbar.closed
.top-banner-bg.closed
.top-banner.closed
.top-banner-container
a(href="https://pages.okta.com/2024-11-WBN-Best-of-Dev-Day_LP/" target="_blank") Missed DevDay24? Register for the Best of DevDay
span(aria-hiden="true") →
button.close-top-banner +

.top-banner-spacer.hide

nav.navbar
.container
.top-mobile
.menu-trigger
Expand Down