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

MWPW-157888 - Hero marquee w/ no-min-height and no l/r padding when using a full-width variant in masonry(repost) #2923

Open
wants to merge 5 commits into
base: stage
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 libs/blocks/hero-marquee/hero-marquee.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
align-items: center;
}

.hero-marquee.no-min-height { min-height: unset;}
.hero-marquee.s-min-height { min-height: var(--s-min-height); }
.hero-marquee.l-min-height { min-height: var(--l-min-height); }

Expand Down Expand Up @@ -150,6 +151,11 @@ html[dir="rtl"] .hero-marquee .foreground {
display: none;
}

div[class*='-up'] .hero-marquee.has-bg.grid-full-width {
padding-left: 0;
padding-right: 0;
}

/* Row Types */
.hero-marquee .row-list {
text-align: left;
Expand Down
26 changes: 22 additions & 4 deletions libs/blocks/hero-marquee/hero-marquee.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
button.classList.add('button-xl', 'button-justified-mobile');
});
}

function parseKeyString(str) {
const regex = /^(\w+)\s*\((.*)\)$/;
const match = str.match(regex);
Expand All @@ -132,6 +133,21 @@
return result;
}

function isElementEmpty(element) {
for (const node of element.childNodes) {
if (node.nodeType === Node.TEXT_NODE && !node.nodeValue.trim()) {
element.removeChild(node);
}
}
if (element.childNodes.length === 0) return true;
for (const child of element.children) {
if (child.hasChildNodes()) {
return false;
}
}
return true;

Check warning on line 148 in libs/blocks/hero-marquee/hero-marquee.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/hero-marquee/hero-marquee.js#L148

Added line #L148 was not covered by tests
}

async function loadContentType(el, key, classes) {
if (classes !== undefined && classes.length) el.classList.add(...classes);
switch (key) {
Expand Down Expand Up @@ -164,14 +180,16 @@
export default async function init(el) {
el.classList.add('con-block');
let rows = el.querySelectorAll(':scope > div');
if (rows.length > 1 && rows[0].textContent !== '') {
if (rows.length <= 1) return;
const [head, ...tail] = rows;
rows = tail;
if (isElementEmpty(head)) {
head.remove();

Check warning on line 187 in libs/blocks/hero-marquee/hero-marquee.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/hero-marquee/hero-marquee.js#L187

Added line #L187 was not covered by tests
} else {
el.classList.add('has-bg');
const [head, ...tail] = rows;
handleObjectFit(head);
decorateBlockBg(el, head, { useHandleFocalpoint: true });
rows = tail;
}

// get first row that's not a keyword key/value row
const mainRowIndex = rows.findIndex((row) => {
const firstColText = row.children[0].textContent.toLowerCase().trim();
Expand Down
Loading