Skip to content

Commit

Permalink
Merge pull request #12 from hlxsites/main
Browse files Browse the repository at this point in the history
Merge Staging into Prod
  • Loading branch information
davenichols-DHLS authored Jan 15, 2024
2 parents 6d566d2 + 26144e1 commit 0f5092f
Show file tree
Hide file tree
Showing 41 changed files with 6,895 additions and 617 deletions.
10 changes: 1 addition & 9 deletions blocks/category-family/category-family.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-unresolved */
import { getMetadata, loadScript } from '../../scripts/lib-franklin.js';
import { getCookie } from '../../scripts/scripts.js';
import { getCookie, isOTEnabled } from '../../scripts/scripts.js';

const categoryFamily = `
<atomic-search-interface class="category-search" localization-compatibility-version="v4"
Expand Down Expand Up @@ -151,14 +151,6 @@ const categoryFamily = `
</atomic-search-interface>
`;

const isOTEnabled = () => {
const otCookie = getCookie('OptanonConsent');
if (typeof otCookie === 'string') {
return otCookie.includes('C0002:1');
}
return true;
};

export default async function decorate(block) {
const category = getMetadata('fullcategory');
const host = (window.location.host === 'lifesciences.danaher.com') ? window.location.host : 'stage.lifesciences.danaher.com';
Expand Down
17 changes: 17 additions & 0 deletions blocks/embed/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ const embedVimeo = (block, url, autoplay) => {
return embedHTML;
};

// To play vidyard videos
const embedVidyard = (block, url, autoplay) => {
const video = url.pathname.split('/').pop();
const suffix = autoplay ? '?muted=1&autoplay=1' : '';
const embedHTML = `<div style="flex justify-center left: 0; width: 100%; height: 0; position: relative; padding-bottom: 56.25%;">
<iframe src="https://play.vidyard.com/${video}${suffix}"
style="border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;"
frameborder="0" allowtransparency="true" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen
title="video" loading="lazy"></iframe>
</div>`;
return embedHTML;
};

const loadEmbed = (block, link, autoplay) => {
if (block.classList.contains('embed-is-loaded')) {
return;
Expand All @@ -86,6 +99,10 @@ const loadEmbed = (block, link, autoplay) => {
match: ['vimeo'],
embed: embedVimeo,
},
{
match: ['vidyard'],
embed: embedVidyard,
},
{
match: ['/content/dam/danaher/', '.pdf'],
embed: embedPdfViewer,
Expand Down
29 changes: 5 additions & 24 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
} from '../../scripts/dom-builder.js';
import { decorateIcons } from '../../scripts/lib-franklin.js';
import { getAuthorization, getCommerceBase, isLoggedInUser } from '../../scripts/commerce.js';
import { getCookie } from '../../scripts/scripts.js';
import { getCookie, makeCoveoApiRequest } from '../../scripts/scripts.js';

const baseURL = getCommerceBase();

Expand Down Expand Up @@ -91,25 +91,6 @@ function getCoveoApiPayload(searchValue, type) {
return payload;
}

async function makeCoveoApiRequest(path, payload = {}) {
const accessToken = window.DanaherConfig !== undefined
? window.DanaherConfig.searchKey
: 'xx2a2e7271-78c3-4e3b-bac3-2fcbab75323b';
const organizationId = window.DanaherConfig !== undefined
? window.DanaherConfig.searchOrg
: 'danahernonproduction1892f3fhz';
const resp = await fetch(`https://${organizationId}.org.coveo.com${path}?organizationId=${organizationId}`, {
method: 'POST',
headers: {
authorization: `Bearer ${accessToken}`,
'content-type': 'application/json',
},
body: JSON.stringify(payload),
});
const jsonData = await resp.json();
return jsonData;
}

async function submitSearchQuery(searchInput, actionCause = '') {
let searchLocation = '/us/en/search.html';
const redirectList = [];
Expand All @@ -118,8 +99,8 @@ async function submitSearchQuery(searchInput, actionCause = '') {
const requestPayload = getCoveoApiPayload(searchTerm, 'search');
const triggerRequestPayload = getCoveoApiPayload(searchTerm, 'trigger');
requestPayload.analytics.actionCause = actionCause || searchInput.getAttribute('data-action-cause') || 'searchFromLink';
await makeCoveoApiRequest('/rest/search/v2', requestPayload);
const triggerResponseData = await makeCoveoApiRequest('/rest/search/v2/plan', triggerRequestPayload);
await makeCoveoApiRequest('/rest/search/v2', 'searchKey', requestPayload);
const triggerResponseData = await makeCoveoApiRequest('/rest/search/v2/plan', 'searchKey', triggerRequestPayload);
const { preprocessingOutput } = triggerResponseData;
const { triggers } = preprocessingOutput;
if (triggers != null && triggers.length > 0) {
Expand Down Expand Up @@ -182,7 +163,7 @@ async function buildSearchSuggestions(searchbox) {
const searchboxInput = searchbox.querySelector('input');
const inputText = searchboxInput.value;
const requestPayload = getCoveoApiPayload(inputText, 'search');
const suggestionsResponseData = await makeCoveoApiRequest('/rest/search/v2/querySuggest', requestPayload);
const suggestionsResponseData = await makeCoveoApiRequest('/rest/search/v2/querySuggest', 'searchKey', requestPayload);
const suggestions = suggestionsResponseData.completions;
const wrapper = searchbox.querySelector('.search-suggestions-wrapper');
const searchSuggestions = wrapper.querySelector('.search-suggestions');
Expand Down Expand Up @@ -642,7 +623,7 @@ function buildFlyoutMenus(headerBlock) {
{ class: 'inline-flex justify-between items-center mb-2' },
span({ class: 'text-left text-xl font-bold py-2 pl-1 text-gray-900 w-1/2' }, menuTitle),
menuItemEl.querySelector(':scope > p > a')
? a({ class: 'btn btn-info', href: menuItemEl.querySelector(':scope > p > a').href }, 'Explore All') : '',
? a({ class: 'btn btn-info rounded-full', href: menuItemEl.querySelector(':scope > p > a').href }, 'Explore All') : '',
),
linkList,
),
Expand Down
88 changes: 88 additions & 0 deletions blocks/product-hero/product-hero.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
.product-hero-container {
@apply bg-gray-100 pt-6 pb-24;
}

.product-hero {
@apply p-4;
}

.product-hero .product-hero-content {
@apply grid md:grid-cols-12 lg:gap-16 md:gap-12 gap-2;
}

.product-hero .hero-default-content {
@apply md:col-span-6;
}

.product-hero .hero-default-content > div {
@apply w-full h-full text-center md:text-left text-gray-500;
}

.product-hero .hero-default-content > div .category-name {
@apply text-sm font-normal leading-5 text-danaherlightblue-500;
}

.product-hero .hero-default-content > div h1.title {
@apply mt-3 text-4xl font-extrabold leading-10 text-gray-900 mb-3;
}

.product-hero .hero-default-content > div h4 {
@apply font-bold text-gray-500;
}

.product-hero .hero-default-content > div ul,
.product-hero .hero-default-content > div p {
@apply text-base;
}

.product-hero .hero-default-content > div ul {
@apply list-disc ml-12 mt-3;
}

.product-hero .hero-default-content > div ul li {
@apply mb-2.5;
}

.product-hero .hero-default-content > div .basic-info {
@apply flex justify-between mt-8 text-gray-500;
}

.product-hero .hero-default-content > div .basic-info div > p:nth-child(1) {
@apply text-base font-bold;
}

.product-hero .hero-default-content > div .basic-info a {
@apply border-b-2 border-danaherlightblue-500;
}

.product-hero .vertical-gallery-container {
@apply md:col-span-5 order-first;
}

.product-hero .vertical-gallery-container > div {
@apply grid grid-rows-1 gap-2.5 bg-transparent overflow-hidden md:grid-cols-4;
}

.product-hero .vertical-gallery-container > div div:nth-child(1) {
@apply relative col-span-3 bg-white;
}

.product-hero .vertical-gallery-container > div div:nth-child(1) img {
@apply w-full h-full max-h-[380px] max-h-96 rounded shadow object-contain transition duration-700;
}

.product-hero .vertical-gallery-container > div > div:not(:nth-child(1)) {
@apply flex flex-row md:flex-col col-span-1 gap-2 md:order-first overflow-auto bg-transparent scroll-pl-6 snap-x;
}

.product-hero .vertical-gallery-container .view-more {
@apply flex flex-col p-2 my-auto bg-opacity-50 text-sm text-blue-500 font-semibold bg-white rounded text-center cursor-pointer;
}

.product-hero .vertical-gallery-container > div > div:not(:nth-child(1)) img {
@apply w-32 h-20 object-cover rounded cursor-pointer transition duration-500 hover:border hover:border-lightblue-500 hover:scale-95;
}

.product-hero .vertical-gallery-container > div div:not(:nth-child(1)) img.active {
@apply border border-4 border-lightblue-500 opacity-80 scale-95;
}
81 changes: 81 additions & 0 deletions blocks/product-hero/product-hero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
a, div, h1, img, p, span,
} from '../../scripts/dom-builder.js';
import { decorateModals, getProductResponse } from '../../scripts/scripts.js';

function showImage(e) {
const selectedImage = document.querySelector('.image-content');
if (e.target) {
const currentActive = e.target.parentElement.querySelector('.active');
if (currentActive) currentActive.classList.toggle('active');
if (e.target.src !== selectedImage.src) {
selectedImage.src = e.target.src;
e.target.classList.toggle('active');
}
}
}

function loadMore() {
const allImageContainer = document.querySelector('.vertical-gallery-container div div img.active').parentElement;
const shownImage = allImageContainer.querySelectorAll('img:not(.hidden)');
const notShownImage = allImageContainer.querySelectorAll('img.hidden');
if (shownImage.length > 0) {
if (shownImage[shownImage.length - 1].nextElementSibling && !shownImage[shownImage.length - 1].nextElementSibling.className.includes('view-more')) {
shownImage[0].classList.add('hidden');
shownImage[shownImage.length - 1].nextElementSibling.classList.remove('hidden');
} else {
// REMOVE THE LASTS FIRST-INDEXED NON-HIDDEN VALUE
const firstNonActive = allImageContainer.querySelector('.hidden');
firstNonActive.classList.remove('hidden');
// HIDE THE LAST-HIDDEN-ELEMENT'S NEXT-SIBLING
notShownImage[notShownImage.length - 1].nextElementSibling.classList.add('hidden');
}
}
}

function imageSlider(allImages) {
const slideContent = div(img({ src: allImages[0], class: 'image-content' }));
const verticalSlides = div();
allImages.map((image, index) => {
const imageElement = img({ src: image });
let imageClass = (index === 0) ? 'active' : '';
if (index > 2) imageClass += ' hidden';
if (imageClass !== '') imageElement.className = imageClass;
imageElement.addEventListener('click', showImage);
verticalSlides.append(imageElement);
return image;
});
const showMore = div({ class: 'view-more' }, 'View More ->');
showMore.addEventListener('click', loadMore);
verticalSlides.append(showMore);
return div({ class: 'vertical-gallery-container' }, div(slideContent, verticalSlides));
}

export default async function decorate(block) {
const response = getProductResponse();
if (response?.length > 0) {
const allImages = response[0]?.raw.images;
const verticalImageGallery = imageSlider(allImages);
const defaultContent = div();
defaultContent.innerHTML = response[0]?.raw.richdescription;
defaultContent.prepend(h1({ class: 'title' }, response[0]?.Title));
defaultContent.prepend(span({ class: 'category-name' }, response[0]?.raw.defaultcategoryname));
const rfqEl = block.querySelector('div')?.firstElementChild;
if (rfqEl && rfqEl.textContent && rfqEl.textContent === 'Request for Quote') {
rfqEl.classList.add(...'btn-outline-trending-brand text-lg rounded-full px-4 py-2 !no-underline'.split(' '));
const rfqParent = p({ class: 'show-modal-btn w-[36%] pt-6 cursor-pointer' }, rfqEl);
defaultContent.append(rfqParent);
}
defaultContent.append(
div(
{ class: 'basic-info' },
div(p('Brand'), p(response[0]?.raw.opco)),
div(p('For additional information'), a({ href: `${response[0]?.raw.externallink}?utm_source=dhls_website`, target: '_blank' }, `Visit ${response[0]?.raw.opco}`)),
),
);
block.parentElement.classList.add(...'stretch'.split(' '));
block.innerHTML = '';
block.append(div({ class: 'product-hero-content' }, div({ class: 'hero-default-content' }, defaultContent), verticalImageGallery));
decorateModals(block);
}
}
Loading

0 comments on commit 0f5092f

Please sign in to comment.