Skip to content

Commit

Permalink
Merge branch 'main' into ebartholomew/aside-bg-breakpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
honstar authored Sep 21, 2023
2 parents bf5c1d0 + db1af1a commit ca5d01a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions libs/blocks/marquee-anchors/marquee-anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,19 @@ export default function init(el) {
const aTag = i.querySelector('a');
if (aTag?.textContent.charAt(0) === '#') {
const content = i.querySelector(':scope > div');
const aTagText = aTag.textContent.toLowerCase();
aTag.textContent = '';
aTag.classList.add('anchor-link');
i.parentElement.replaceChild(aTag, i);
aTag.append(content);
const hrefPathEqual = (aTag.href.split(/\?|#/)[0] === window.location.href.split(/\?|#/)[0]);
const hrefUrl = (hrefPathEqual)
? `${aTag.textContent}`
: `${aTag.href}`;
const link = createTag('a', {
class: 'anchor-link',
href: hrefUrl,
}, content);
if (!hrefPathEqual) link.classList.add('external');
i.parentElement.replaceChild(link, i);
aTag.parentElement.remove();
if (hrefPathEqual) {
aTag.href = aTagText;
} else {
aTag.classList.add('external');
}
}
});

const emptyLinkRows = links.querySelectorAll(':scope > div:not([class])');
if (emptyLinkRows[0]) emptyLinkRows[0].classList.add('links-header');
if (emptyLinkRows[1]) emptyLinkRows[1].classList.add('links-footer', 'body-s');
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/marquee-anchors/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3 id="this-is-the-title-of-the-section">This is the title of the section</h3>
<div>
<h4 id="marquee-label">Marquee Label</h4>
<p>Actionable data that drives real-time personalization.</p>
<p><a href="">#marquee-block</a></p>
<p><a href="" target="_blank">#marquee-block</a></p>
</div>
</div>
<div>
Expand Down

0 comments on commit ca5d01a

Please sign in to comment.