Skip to content

Added the notification banner on the top of the page #391

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 10 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
6 changes: 6 additions & 0 deletions _data/_notifications-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Notification Banner example
Instrumenting Sentry:
background: '#141845'
textcolor: '#fff'
title: Instrumenting Sentry
description: Instrumenting 1 Sentry for your backend project? Join us July 11th, at 10 AM PT for the Backend Error Monitoring 101 livestream. <a href="https://go.memfault.com/how-to-debug-android-devices-production">Register now.</a>
6 changes: 6 additions & 0 deletions _data/notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Notification Banner
Instrumenting Sentry:
background: '#141845'
textcolor: '#fff'
title: Instrumenting Sentry
description: '<i>Excited to introduce Memfault’s new sandbox demo!</i><a href="https://demo.memfault.com/demo/start"> Try it out for yourself</a>'
8 changes: 8 additions & 0 deletions _includes/notification-banner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<ul class="banner-notifications">
{% for notification in site.data.notifications %}
<li class="banner-notification" style="--notificationBackground: {{ notification[1].background }}; --notificationColor: {{ notification[1].textcolor }};">
<div style="text-align: center;">{{ notification[1].description | markdownify }}</div>
<button class="banner-notification-close js-banner-notification-close"></button>
</li>
{% endfor %}
</ul>
3 changes: 3 additions & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<!-- Navigation -->
{% include menu.html %}

<!-- Top banner -->
{% include notification-banner.html %}

<!-- Icon menu -->
<a {% if site.reverse == true %}id="nav-menu-left"{% else %}id="nav-menu"{% endif %}>
<div id="menu"></div>
Expand Down
3 changes: 3 additions & 0 deletions _layouts/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<!-- Navigation -->
{% include menu.html %}

<!-- Top banner -->
{% include notification-banner.html %}

<!-- Icon menu -->
<a {% if site.reverse == true %}id="nav-menu-left"{% else %}id="nav-menu"{% endif %}>
<div id="menu"></div>
Expand Down
5 changes: 4 additions & 1 deletion _layouts/split-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<!-- Navigation -->
{% include menu.html %}

<!-- Top banner -->
{% include notification-banner.html %}

<!-- Icon menu -->
<a {% if site.reverse == true %}id="nav-menu-left"{% else %}id="nav-menu"{% endif %}>
<div id="menu"></div>
Expand All @@ -34,7 +37,7 @@

<!-- Pagination links -->
{% include pagination.html %}

</div>

<!-- Footer -->
Expand Down
90 changes: 90 additions & 0 deletions _sass/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,93 @@ figcaption {
text-align: center;
font-size: 12px;
}

:root {
--notificationBackground: #faaf4e;
--notificationColor: #fff;
}

#nav-menu {
top: 35px;
margin-top: 35px;
width: 30px;
position: sticky;
margin-left: auto;
}

.menu-open ~ #nav-menu {
margin-top: 0;
top: 35px;
position: fixed;
}

.banner-notifications {
margin: 0;
list-style: none;
display: none;
}

.banner-notification {
position: relative;
margin: 0;
margin-bottom: 10px;
background-color: var(--notificationBackground);
color: var(--notificationColor);
padding: 10px 50px 10px 20px;

p {
margin: 0;
}

a {
color: inherit;
text-decoration: underline;

&:hover,
&:focus,
&:active {
color: inherit;
text-decoration: none;
}
}
}

.banner-notification-close {
background-color: color-mix(in srgb, var(--notificationBackground),#000 30%);
width: 25px;
height: 25px;
border-radius: 50%;
position: absolute;
right: 10px;
top: 15px;
border: none;
padding: 0;
box-shadow: none;
transform: rotate(-45deg);
cursor: pointer;

&::after,
&::before {
content: '';
width: 10px;
height: 1px;
background-color: var(--notificationColor);
display: block;
position: absolute;
left: 50%;
top: 50%;
transition: all 0.1s linear;
transform: translateX(-50%) translateY(-50%) rotate(-90deg);
}

&:hover {
&::after,
&::before {
width: 12px;
}
}

&::before {
transform: translateX(-50%) translateY(-50%) ;
}
}
58 changes: 57 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,63 @@ function searchScroll() {
}
}

// Function to set a cookie
function setCookie(name, value, days) {
const expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/`;
}

// Function to get the value of a cookie
function getCookie(name) {
const cookieName = `${name}=`;
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, cookie.length);
}
}
return null;
}

// Function to check the hideBanner cookie and show/hide the banner
function checkAndDisplayBanner() {
const hideBannerCookie = getCookie('hideBanner');
const banner = document.querySelector('.banner-notifications');

if (banner && hideBannerCookie === 'true') {
banner.style.display = 'none'; // Hide the banner if cookie is set to true
} else {
banner.style.display = 'block'; // Show the banner otherwise
}

notificationBannerClose();
}


// Closes the banner and save the cookie
function closeBanner() {
const banner = document.querySelector('.banner-notifications');
if (!banner) return;

banner.style.display = 'none';
setCookie('hideBanner', 'true', 1); // Set the cookie to expire in 1 day
}

// Closes the
function notificationBannerClose() {
const closeButton = document.querySelector('.js-banner-notification-close');

if (closeButton) {
closeButton.addEventListener('click', closeBanner);
}
}

// TODO dark mode
// darkModeSetup();
menuClick();
searchScroll();
searchScroll();

window.addEventListener('load', checkAndDisplayBanner);