Skip to content
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

Nojs meganav #13141

Merged
merged 69 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
713452d
add global nav
sowasred2012 Oct 17, 2022
0f40cc2
add tabbed content js to main js
sowasred2012 Oct 24, 2022
1c2c9a5
fix global nav chevron position on reduced view
sowasred2012 Dec 5, 2022
e77432f
Add second view for mobile
petesfrench Jun 16, 2023
df82e08
Refactor to work with new sliding nav
petesfrench Jun 20, 2023
4f7b43e
Fix css issues from refactoring html structure
petesfrench Jul 3, 2023
efca6f9
lint-scss
petesfrench Jul 3, 2023
70552a5
Update with design usggestions from initial ux review
petesfrench Jul 4, 2023
4b530c8
Further ux review changes
petesfrench Jul 5, 2023
1291fa4
Make user dropdown work wit sliding nav
petesfrench Jul 6, 2023
6ea8a1a
Fix bug in account dropdown where clicking outside the made navigatio…
petesfrench Jul 10, 2023
5d7fa77
Format prettier
petesfrench Jul 10, 2023
f9c3183
revert use-cases changes for demo
petesfrench Jul 10, 2023
6d491f8
Increase default grid width
petesfrench Jul 10, 2023
f18fe89
Implemened redesigned use-cases
petesfrench Jul 10, 2023
575ef42
Lint-scss
petesfrench Jul 11, 2023
ba7ed61
Further ux changes for demo purpose - global nav not working on mobile
petesfrench Jul 19, 2023
f744fda
Implement new global nav for desktop
petesfrench Jul 25, 2023
70472d8
Implement new global nav for mobile view
petesfrench Jul 25, 2023
4aa47fa
Changes based on code and QA
petesfrench Jul 27, 2023
1381861
Content QA
juanruitina Jul 28, 2023
436dc27
Reposition search icon
petesfrench Jul 28, 2023
1db0161
Merge branch 'sliding-nav' of github.com:canonical/ubuntu.com into sl…
petesfrench Jul 28, 2023
dc41a56
Add content fixes
juanruitina Aug 8, 2023
a1e1f8b
Some final ux improvement and a small bug fix
petesfrench Aug 9, 2023
a8cced7
Merge branch 'sliding-nav' of github.com:canonical/ubuntu.com into sl…
petesfrench Aug 9, 2023
ae09ee1
Fix spacing issue and highlight not appearing on account dropdown
petesfrench Aug 16, 2023
a46b519
Fix global nav item alignment
petesfrench Aug 16, 2023
35d962b
Implement global-nav 3.5.0 changes
petesfrench Aug 17, 2023
065644e
Changes based on Hans feedback
petesfrench Aug 22, 2023
84abe2c
Tweak bubble labels
juanruitina Aug 28, 2023
6694151
Remove redundant headings ("Products")
juanruitina Aug 29, 2023
d753ace
Visual design review changes
petesfrench Sep 6, 2023
6dfefc3
Merge branch 'sliding-nav' of github.com:canonical/ubuntu.com into sl…
petesfrench Sep 6, 2023
a19f3eb
Fix navigation padding bug
petesfrench Sep 6, 2023
b1719df
Remove second 'skip to main content'
petesfrench Sep 6, 2023
179a7c8
Update with UX suggestions
petesfrench Sep 28, 2023
97a9e1f
Bump grid-max-width to 90rem
petesfrench Sep 28, 2023
4489cbc
Fix logo alignment in primary navigation
petesfrench Oct 2, 2023
c82d840
Refactor to use event delegation
petesfrench Oct 2, 2023
f497f66
Update alignment in reduced nav
petesfrench Oct 3, 2023
0062f6f
Add failsafe to prevent dropdowns being fetched multiple times
petesfrench Oct 4, 2023
db88f29
Bump global-nav version to 3.6.1
petesfrench Oct 4, 2023
8ae12fd
Align logos far left
petesfrench Oct 4, 2023
f2eec90
Make reduced nav not sticky
petesfrench Oct 4, 2023
de1ba5d
Allow dropdowns to be scrollable if viewport height is smaller than t…
petesfrench Oct 4, 2023
01284d0
Add missing links to mobile dropdowns
petesfrench Oct 4, 2023
42ced6b
Align top level mobile items with logo
petesfrench Oct 5, 2023
39d15db
Add fallback for hover loading on touchscreen devices
petesfrench Oct 6, 2023
cb3c69d
Use variables for repeated values
petesfrench Oct 10, 2023
05c61e8
Handle resize events
petesfrench Oct 10, 2023
ba436b8
Close meganav on any resize event
petesfrench Oct 11, 2023
37ff85f
Use grid-max-width variable
petesfrench Oct 11, 2023
baeda09
Handle resize event on secondary nav
petesfrench Oct 11, 2023
63b1573
Fix highlighted page alignment
petesfrench Oct 11, 2023
8e6d777
Delete unused 'navigation-meganav-base.html file
petesfrench Oct 16, 2023
9f00014
Only closeAll on resize event if mobile-breakpoint threshold is crossed
petesfrench Oct 16, 2023
8c9f054
Create basic static nojs-meganav
petesfrench Sep 1, 2023
5e821a1
Apply style changes from UX mockup
petesfrench Sep 7, 2023
f44f1b1
Enable nojs-meganav when JS is not enabled
petesfrench Sep 13, 2023
806e574
Apply changes from U review and make a basic mobile view mockup
petesfrench Sep 13, 2023
d548d45
Format prettier
petesfrench Sep 13, 2023
55ba0c4
Hide chevrons and implement fallbacks for 'menu' and 'search'
petesfrench Sep 15, 2023
df89712
Fix search not working on nojs mobile view
petesfrench Sep 27, 2023
0f70179
Ux updates
petesfrench Oct 16, 2023
e37d8a0
Merge branch 'meganav-rebase' into nojs-meganav
petesfrench Oct 17, 2023
c608fdc
Fix prettier errors
petesfrench Oct 18, 2023
a412979
Lint JS
petesfrench Oct 19, 2023
95716d2
Format prettier
petesfrench Oct 19, 2023
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
63 changes: 32 additions & 31 deletions static/js/src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ const topLevelNavDropdowns = Array.from(
);
const nav = navigation.querySelector(".js-show-nav");
const menuButtons = document.querySelectorAll(".js-menu-button");
const skipLink = document.querySelector(".p-link--skip");
const jsBackbuttons = document.querySelectorAll(".js-back");
const reducedNav = document.querySelector(".p-navigation--sliding.is-reduced ");
let dropdowns = [];
const mainList = document.querySelector(
"nav.p-navigation__nav > .p-navigation__items"
);
const currentBubble = window.location.pathname.split("/")[1];

navigation.classList.add("js-enabled");
nav.classList.remove("u-hide");

//Helper functions
Expand Down Expand Up @@ -52,7 +49,8 @@ function getAllElements(queryString) {
}

// Attach initial event listeners
mainList.addEventListener("click", function(e) {
mainList.addEventListener("click", function (e) {
e.preventDefault();
let target = e.target;
if (target.classList.contains("p-navigation__link")) {
if (target.classList.contains("js-back")) {
Expand All @@ -61,11 +59,11 @@ mainList.addEventListener("click", function(e) {
handleDropdownClick(e.target.parentNode);
}
}
})
});

window.addEventListener("load", closeAll);
let wasBelowSpecificWidth = window.innerWidth < MOBILE_VIEW_BREAKPOINT;
window.addEventListener("resize", function() {
window.addEventListener("resize", function () {
// Only closeAll if the resize event crosses the MOBILE_VIEW_BREAKPOINT threshold
const currentViewportWidth = window.innerWidth;
const isBelowSpecificWidth = currentViewportWidth < MOBILE_VIEW_BREAKPOINT;
Expand All @@ -75,7 +73,6 @@ window.addEventListener("resize", function() {
wasBelowSpecificWidth = isBelowSpecificWidth;
});


dropdownWindowOverlay?.addEventListener("click", () => {
if (dropdownWindow.classList.contains("is-active")) {
closeAll();
Expand All @@ -98,7 +95,9 @@ document.addEventListener("global-nav-opened", () => {

function toggleSecondaryMobileNavDropdown(e) {
const mobileNavDropdown = secondaryNav.querySelector(".p-navigation__nav");
const mobileNavDropdownToggle = secondaryNav.querySelector(".p-navigation__toggle--open");
const mobileNavDropdownToggle = secondaryNav.querySelector(
".p-navigation__toggle--open"
);
let isDropdownOpen;
if (e && e.type == "click") {
e.preventDefault();
Expand Down Expand Up @@ -161,22 +160,23 @@ function updateNavMenu(dropdown, show) {
dropdown.id + "-content-mobile"
);
let isAccountDropdown = dropdown.classList.contains("js-account");


function handleMutation(mutationsList, observer) {
mutationsList.forEach((mutation) => {
if (mutation.type === "childList") {
handleDropdownClick(mutation.target);
observer.disconnect();
}
});
}

if ((dropdownContent && dropdownContentMobile) || isAccountDropdown) {
if (!show) updateDropdownStates(dropdown, show, ANIMATION_DELAY);
else updateDropdownStates(dropdown, show);
showDesktopDropdown(show);
} else if (dropdownContentMobile) {
updateMobileDropdownState(dropdown, show);
} else {
function handleMutation(mutationsList, observer) {
mutationsList.forEach(mutation => {
if (mutation.type === 'childList') {
handleDropdownClick(mutation.target);
observer.disconnect();
}
});
}
const observer = new MutationObserver(handleMutation);
const observerConfig = { childList: true, subtree: true };
observer.observe(dropdown, observerConfig);
Expand All @@ -200,9 +200,7 @@ function updateDropdownStates(dropdown, show, delay) {
}

function updateDesktopDropdownStates(dropdown, show, delay) {
let dropdownContent = document.getElementById(
dropdown.id + "-content"
);
let dropdownContent = document.getElementById(dropdown.id + "-content");
toggleIsActiveState(dropdown, show);
if (dropdownContent) {
toggleDropdownContentVisibility(dropdownContent, show, delay);
Expand Down Expand Up @@ -286,7 +284,7 @@ function fetchDropdown(url, id) {
const key = `${url}-${id}`;
if (fetchedMap[key] === true) return;
fetchedMap[key] = true;

const desktopContainer = document.getElementById(id + "-content");
const mobileContainer = document.getElementById(id);

Expand All @@ -312,10 +310,7 @@ function fetchDropdown(url, id) {
const activeCTAs = mobileContainer.querySelectorAll("a.is-active");
activeCTAs.forEach(deactivateActiveCTA);
});
} else {
resolve();
}
isFetching = false;
}

/**
Expand Down Expand Up @@ -373,7 +368,10 @@ function closeMobileDropdown() {
const dropdownElements = getAllElements(
".p-navigation__item--dropdown-toggle"
);
removeClassesFromElements([navigation, mainList], ["has-menu-open", "is-active"]);
removeClassesFromElements(
[navigation, mainList],
["has-menu-open", "is-active"]
);
if (secondaryNav) {
toggleSecondaryMobileNavDropdown();
}
Expand Down Expand Up @@ -407,7 +405,9 @@ function openMenu(e) {

// Setup and functions for navigaiton search
function initNavigationSearch() {
searchButtons.forEach((searchButton) => searchButton.addEventListener("click", toggleSearch));
searchButtons.forEach((searchButton) =>
searchButton.addEventListener("click", toggleSearch)
);

searchOverlay.addEventListener("click", toggleSearch);

Expand Down Expand Up @@ -467,8 +467,11 @@ function setUpGlobalNav() {
const globalNavMainTab = globalNavTab.querySelector("ul.p-navigation__items");

globalNavMainTab.classList.replace("u-hide", "dropdown-content-mobile");
globalNavMainTab.classList.replace("p-navigation__items", "p-navigation__dropdown",);

globalNavMainTab.classList.replace(
"p-navigation__items",
"p-navigation__dropdown"
);

globalNavMainTab.setAttribute("id", "all-canonical-content-mobile");

globalNavTab
Expand All @@ -485,7 +488,6 @@ function setUpGlobalNav() {
dropdownToggle
.querySelector("button.p-navigation__link")
.setAttribute("href", `#${newDropdownId}-content-mobile`);

}
const tempHTMLContainer = document.createElement("div");
tempHTMLContainer.innerHTML = `<li class="p-navigation__item--dropdown-close" id="${dropdown.id}-back">
Expand Down Expand Up @@ -534,7 +536,6 @@ if (accountContainer) {
<a class="p-link--inverted" href="/logout" onclick="event.stopPropagation()">Logout</a>
</li>
</ul>`;

}
});
}
Expand Down
40 changes: 21 additions & 19 deletions static/sass/_pattern_navigation-dropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
box-shadow: 0 1px 32px 1px transparentize($color-dark, 0.8);
flex-direction: column;
height: auto;
max-height: calc(100vh - 3rem);
overflow-y: auto;
position: fixed;
width: 100%;
overflow-y: auto;
max-height: calc(100vh - 3rem);
z-index: 11;
}

Expand Down Expand Up @@ -112,23 +112,6 @@
}
}

.dropdown-window__side-panel {
margin: 2.5rem 0;
padding: 0;

.p-list__item {
padding-left: 0.5rem;

a {
color: #69c;

&:visited {
color: #a679d2;
}
}
}
}

.dropdown-window__main-panel,
.dropdown-window__side-panel {
margin: 2.5rem 0;
Expand Down Expand Up @@ -184,6 +167,25 @@
}
}

.dropdown-window__side-panel {
margin: 2.5rem 0;
padding: 0;

.p-list {
.p-list__item {
padding-left: 0.5rem;

a.dropdown-window__side-panel-link {
color: #69c;

&:visited {
color: #a679d2;
}
}
}
}
}

.dropdown-window__sidenav-back {
color: $color-light;
display: block;
Expand Down
Loading