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

rfq link #1539

Merged
merged 13 commits into from
Nov 18, 2024
26 changes: 16 additions & 10 deletions blocks/applications-carousel/applications-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ function getDescription(element) {
}

export default async function decorate(block) {
const placeholders = await fetchPlaceholders();
const hasApplicationTab = block.closest('main').querySelector('.page-tabs');
const fragmentPaths = [...block.querySelectorAll('a')].map((elem) => elem.getAttribute('href'));

const fragments = await Promise.all(fragmentPaths.map(async (path) => {
const fragmentHtml = await fetchFragment(path);
if (fragmentHtml) {
Expand All @@ -33,28 +36,31 @@ export default async function decorate(block) {
const h3Block = fragmentElement.querySelector('h3');
const imageBlock = fragmentElement.querySelector('picture');
const description = getDescription(fragmentElement);
const appLinks = fragmentElement.querySelectorAll('a:last-of-type');
const appLink = fragmentElement.querySelectorAll('a:last-of-type')[appLinks.length - 1];
return {
id: h3Block.id, title: h3Block.textContent, imageBlock, description,
id: h3Block.id,
title: h3Block.textContent,
imageBlock,
description,
c2aLinkConfig: {
href: hasApplicationTab ? '#applications' : appLink,
'aria-label': placeholders.readMore || 'Read More',
onclick: hasApplicationTab ? onReadMoreClick : null,
target: '_blank',
rel: 'noopener noreferrer',
},
};
}
return null;
}));
const sortedFragments = sortDataByTitle(fragments);

const placeholders = await fetchPlaceholders();

const cardRenderer = await createCard({
titleLink: false,
thumbnailLink: false,
descriptionLength: 100,
imageBlockReady: true,
c2aLinkConfig: {
href: '#applications',
'aria-label': placeholders.readMore || 'Read More',
onclick: onReadMoreClick,
target: '_blank',
rel: 'noopener noreferrer',
},
c2aLinkStyle: true,
});

Expand Down
9 changes: 5 additions & 4 deletions blocks/card/card.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable import/prefer-default-export */
/* eslint-disable no-alert */

import {
decorateIcons, loadCSS, createOptimizedPicture, fetchPlaceholders, toCamelCase,
} from '../../scripts/lib-franklin.js';
Expand Down Expand Up @@ -98,7 +95,8 @@ class Card {
? item.imageBlock : createOptimizedPicture(itemImage, item.title, 'lazy', [{ width: '800' }]);

/* default button */
let cardLink = this.isRequestQuoteCard ? `/quote-request?pid=${item.familyID}` : item.path;
let cardLink = item.path;

if (isGatedResource(item)) {
cardLink = item.gatedURL;
} else if (this.isShopifyCard && item.shopifyUrl) {
Expand All @@ -113,6 +111,9 @@ class Card {
if (this.c2aLinkConfig) {
c2aLinkBlock = a(this.c2aLinkConfig, buttonText);
}
if (item.c2aLinkConfig) {
c2aLinkBlock = a(item.c2aLinkConfig, buttonText);
}
if (this.c2aLinkStyle) {
c2aLinkBlock.classList.remove('button', 'primary');
c2aLinkBlock.append(
Expand Down
13 changes: 12 additions & 1 deletion blocks/request-quote-carousel/request-quote-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { createCarousel } from '../carousel/carousel.js';
import { createCard } from '../card/card.js';
import ffetch from '../../scripts/ffetch.js';
import { getCountryCode, sortDataByTitle } from '../../scripts/scripts.js';
import { fetchPlaceholders } from '../../scripts/lib-franklin.js';

export default async function decorate(block) {
const fragmentPaths = [...block.querySelectorAll('a')].map((elem) => elem.getAttribute('href'));
const isCountryCodeUS = await getCountryCode() === 'US';
const placeholders = await fetchPlaceholders();
const cardRenderer = await createCard({
titleLink: false,
thumbnailLink: false,
c2aLinkStyle: true,
isShopifyCard: isCountryCodeUS,
c2aLinkStyle: !isCountryCodeUS,
isRequestQuoteCard: !isCountryCodeUS,
defaultButtonText: placeholders.requestQuote || 'Request Quote',
});

let fragments;
Expand All @@ -24,6 +27,14 @@ export default async function decorate(block) {
fragments = await ffetch('/query-index.json')
.filter((frag) => fragmentPaths.includes(frag.path))
.all();
fragments.forEach((fragment) => {
fragment.c2aLinkConfig = {
href: `/quote-request?pid=${fragment.familyID}`,
'aria-label': placeholders.requestQuote || 'Request Quote',
target: '_blank',
rel: 'noopener noreferrer',
};
});
}

await createCarousel(
Expand Down