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

Mega Menu Features Updated #1597

Merged
merged 12 commits into from
Jan 16, 2025
25 changes: 19 additions & 6 deletions blocks/header/header-megamenu-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import { formatEventDates } from '../latest-events/latest-events.js';
import { sortDataByDate, summariseDescription } from '../../scripts/scripts.js';

function wrapLinkAroundComponent(link, component, removeLink = false) {
const linkCopy = a({ href: link.href });
let linkCopy;

if (component.nextElementSibling && component.nextElementSibling.tagName === 'A') {
linkCopy = a({ href: component.nextElementSibling.href });
component.nextElementSibling.remove();
} else {
linkCopy = a({ href: link.href });
}

// Insert the new div before the existing div
component.parentNode.insertBefore(linkCopy, component);
// Move the existing div inside the new div
Expand All @@ -24,11 +32,16 @@ function wrapLinkAroundComponent(link, component, removeLink = false) {
}

function buildLargeCardsMenu(cardContent) {
const link = cardContent.querySelector('a');
const picture = cardContent.querySelector('picture');

if (link && picture) {
wrapLinkAroundComponent(link, picture);
const links = cardContent.querySelectorAll('a');
const pictures = cardContent.querySelectorAll('picture');

if (links && pictures) {
wrapLinkAroundComponent(links[0], pictures[0]);
pictures.forEach((picture) => {
if (picture.nextElementSibling && picture.nextElementSibling.tagName === 'A') {
wrapLinkAroundComponent(picture.nextElementSibling.href, picture);
}
});
}

return cardContent;
Expand Down
12 changes: 6 additions & 6 deletions blocks/header/header-megamenu.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable linebreak-style */
import buildRightSubmenu from './header-megamenu-components.js';
import { decorateIcons } from '../../scripts/lib-franklin.js';
import buildSearch from './menus/search.js';
Expand Down Expand Up @@ -30,13 +29,14 @@ function getTitlesWithLineDividers(content) {
const titleIds = [];
const lineDividers = content.querySelectorAll('p');
lineDividers.forEach((lineDivider) => {
if (!lineDivider.textContent.includes('--')) {
if (!lineDivider.textContent.trim().includes('--')) {
return;
}

// get the h2 id immediately after the p element
const h2Id = lineDivider.nextElementSibling.id;
titleIds.push(h2Id);
if (lineDivider.nextElementSibling !== null) {
// get the h2 id immediately after the p element
const h2Id = lineDivider.nextElementSibling.id;
titleIds.push(h2Id);
}
});

return titleIds;
Expand Down
Loading
Loading