Skip to content

Commit

Permalink
Make sure new nav works well with the donate banner
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmavis committed Sep 26, 2024
1 parent 485ba28 commit 1f9d153
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
{% fragment as content_desktop %}xlarge:tw-px-0 xlarge:tw-hidden{% endfragment %}
{% fragment as content_desktop_border %}xlarge:tw-border xlarge:tw-border-gray-20{% endfragment %}
{% comment %} 40 (5rem) is the height of the navbar {% endcomment %}
{% fragment as content_desktop_positioning %}xlarge:tw-fixed xlarge:tw-top-40 xlarge:tw-left-0 xlarge:tw-right-0 xlarge:tw-mx-auto{% endfragment %}
{% fragment as content_desktop_positioning %}xlarge:tw-fixed xlarge:tw-left-0 xlarge:tw-right-0 xlarge:tw-mx-auto{% endfragment %}

{% fragment as title_base_typography %}tw-font-sans tw-font-bold tw-text-xl tw-text-black{% endfragment %}
{% fragment as title_desktop_typography %}xlarge:tw-text-lg{% endfragment %}
Expand Down
6 changes: 6 additions & 0 deletions source/js/components/nav/desktop-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ class NavDesktopDropdown extends Accordion {
open() {
super.open();

let topOffset = document
.querySelector(".wide-screen-menu-container")
.getBoundingClientRect().bottom;

this.accordion.setAttribute("aria-selected", "true");
this.accordion.classList.remove("tw-grayed-out");

this.content.style.top = `${topOffset}px`;
this.content.classList.add("xlarge:tw-flex");
this.content.classList.remove("xlarge:tw-hidden");

Expand Down
13 changes: 12 additions & 1 deletion source/js/donate-banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const DonateBanner = {
: banner?.querySelector(`a.banner-close`);

// skip the banner if it got dismissed by the user today already
if (hideBanner) {
// remove the banner from the DOM to prevent it
// from creating unexpected behavior due to its absolute positioning.
banner.remove();
return;
}

if (!hideBanner && banner) {
banner.classList.remove(`tw-hidden`);
}
Expand Down Expand Up @@ -57,8 +64,12 @@ const DonateBanner = {
);

closeAnimation.onfinish = () => {
banner.classList.add(`tw-hidden`);
this.setDismissDate();

// The banner will not reappear after the user has dismissed it until the next day.
// We might as well remove it from the DOM to prevent it
// from creating unexpected behavior due to its absolute positioning.
banner.remove();
};
});
},
Expand Down
16 changes: 16 additions & 0 deletions source/js/primary-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,28 @@ let primaryNav = {
}

function setMenuState(openMenu) {
toggleDonateBanner(openMenu);
setNarrowMenuState(openMenu);
setBurgerState(openMenu);
trackMenuState(openMenu);
setBodyHeight(openMenu);
}

// temporary hide the donate banner when the menu is open
function toggleDonateBanner(hideDonateBanner) {
const donateBanner = document.querySelector(`.donate-banner`);

if (!donateBanner) {
return;
}

if (hideDonateBanner) {
donateBanner.classList.add(`tw-hidden`);
} else {
donateBanner.classList.remove(`tw-hidden`);
}
}

document.addEventListener(`keyup`, (e) => {
if (e.keyCode === 27) {
menuOpen = false;
Expand Down

0 comments on commit 1f9d153

Please sign in to comment.