Skip to content

Commit

Permalink
remove $ from js code
Browse files Browse the repository at this point in the history
  • Loading branch information
jsandland committed Dec 13, 2024
1 parent 06fdef7 commit b94e54f
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions express/blocks/how-to-steps-accordion/how-to-steps-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,62 @@ function setStepDetails(block, indexOpenedStep) {
const listItems = block.querySelectorAll(':scope li');

listItems.forEach((item, i) => {
const $detail = item.querySelector('.detail-container');
const detail = item.querySelector('.detail-container');

if (i === indexOpenedStep) {
$detail.classList.remove('closed');
$detail.style.maxHeight = `${$detail.scrollHeight}px`;
detail.classList.remove('closed');
detail.style.maxHeight = `${detail.scrollHeight}px`;
} else {
$detail.classList.add('closed');
$detail.style.maxHeight = '0';
detail.classList.add('closed');
detail.style.maxHeight = '0';
}
});
}

function buildAccordion(block, rows, $stepsContent) {
function buildAccordion(block, rows, stepsContent) {
let indexOpenedStep = 0;
const $list = createTag('OL', { class: 'steps' });
const list = createTag('OL', { class: 'steps' });

rows.forEach((row, i) => {
const [stepTitle, stepDetail] = row.querySelectorAll(':scope div');

const $newStepTitle = createTag('h3');
$newStepTitle.replaceChildren(...stepTitle.childNodes);
const newStepTitle = createTag('h3');
newStepTitle.replaceChildren(...stepTitle.childNodes);

const $listItem = createTag('LI', { class: 'step', tabindex: '0' });
$list.append($listItem);
const listItem = createTag('LI', { class: 'step', tabindex: '0' });
list.append(listItem);

const $listItemIndicator = createTag('div', { class: 'step-indicator' });
const $listItemContent = createTag('div', { class: 'step-content' });
const listItemIndicator = createTag('div', { class: 'step-indicator' });
const listItemContent = createTag('div', { class: 'step-content' });

const $detailText = stepDetail;
$detailText.classList.add('detail-text');
const detailText = stepDetail;
detailText.classList.add('detail-text');

const $detailContainer = createTag('div', { class: 'detail-container' });
const detailContainer = createTag('div', { class: 'detail-container' });

if (i !== 0) {
$detailContainer.classList.add('closed');
detailContainer.classList.add('closed');
}

$detailContainer.append($detailText);
detailContainer.append(detailText);

$listItem.append($listItemIndicator);
$listItem.append($listItemContent);
listItem.append(listItemIndicator);
listItem.append(listItemContent);

$listItemContent.append($newStepTitle);
$listItemContent.append($detailContainer);
listItemContent.append(newStepTitle);
listItemContent.append(detailContainer);

const handleOpenDetails = (ev) => {
indexOpenedStep = i;
setStepDetails(block, indexOpenedStep);
ev.preventDefault();
};

$newStepTitle.addEventListener('click', handleOpenDetails);
$listItem.addEventListener('keyup', (ev) => ev.which === 13 && handleOpenDetails(ev));
newStepTitle.addEventListener('click', handleOpenDetails);
listItem.addEventListener('keyup', (ev) => ev.which === 13 && handleOpenDetails(ev));
});

$stepsContent.append($list);
stepsContent.append(list);

// set this in the next event cycle when scrollHeight has been established
setTimeout(() => {
Expand All @@ -86,15 +86,15 @@ export default async function decorate(block) {
}

if (isVideoVariant || isImageVariant) {
const $stepsContent = createTag('div', { class: 'steps-content' });
const stepsContent = createTag('div', { class: 'steps-content' });

if (hasBackground) {
// So that background image goes beyond container
const $stepsContentBackground = createTag('div', { class: 'steps-content-backg' });
const $stepsContentBackgroundImg = createTag('img', { class: 'steps-content-backg-image' });
$stepsContent.append($stepsContentBackground);
$stepsContentBackground.append($stepsContentBackgroundImg);
$stepsContentBackgroundImg.src = backgroundURL;
const stepsContentBackground = createTag('div', { class: 'steps-content-backg' });
const stepsContentBackgroundImg = createTag('img', { class: 'steps-content-backg-image' });
stepsContent.append(stepsContentBackground);
stepsContentBackground.append(stepsContentBackgroundImg);
stepsContentBackgroundImg.src = backgroundURL;
}

if (isVideoVariant) {
Expand All @@ -113,17 +113,17 @@ export default async function decorate(block) {
videoEl.classList.add('video-how-to-steps-accordion');

videoContainerEl.append(videoEl);
$stepsContent.append(videoContainerEl);
stepsContent.append(videoContainerEl);
} else {
const imageData = rows.shift();
const imageEl = imageData.querySelector('picture');
const imageContainerEl = createTag('div', { class: 'image-container' });
imageContainerEl.append(imageEl);
$stepsContent.append(imageContainerEl);
stepsContent.append(imageContainerEl);
}

const heading = section.querySelector('h2, h3, h4');
block.replaceChildren(heading, $stepsContent);
buildAccordion(block, rows, $stepsContent);
block.replaceChildren(heading, stepsContent);
buildAccordion(block, rows, stepsContent);
}
}

0 comments on commit b94e54f

Please sign in to comment.