Skip to content

Commit

Permalink
hero modal
Browse files Browse the repository at this point in the history
  • Loading branch information
webjsavella committed Feb 4, 2025
1 parent 1599405 commit abcaa1b
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion eds/blocks/hero/hero.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
import { createAutoplayedVideo } from '../../scripts/scripts.js';
import { calciteButton } from '../../scripts/dom-helpers.js';

// decorate modal
function decorateModal() {
const iframe = document.createElement('iframe');
iframe.classList.add('co3-modal', 'iframe');
const videoLink = document.querySelector('.video-link');
if (videoLink) {
iframe.setAttribute('src', videoLink.getAttribute('href'));
}
const modal = document.createElement('div');
modal.classList.add('co3-modal', 'calcite-mode-dark');
const closeButton = document.createElement('calcite-icon');
closeButton.classList.add('co3-modal-container', 'calcite-icon');
closeButton.setAttribute('icon', 'x');
closeButton.setAttribute('scale', 'm');
closeButton.setAttribute('aria-label', 'close modal');
closeButton.setAttribute('aria-hidden', 'false');
closeButton.setAttribute('tabindex', '0');
closeButton.addEventListener('click', () => {
removeModal(modal);

Check failure on line 22 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

'removeModal' is not defined
});
closeButton.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ' ' || event.key === 'Escape') {
removeModal(modal);

Check failure on line 26 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

'removeModal' is not defined
}
});

const modalContainer = document.createElement('div');
modalContainer.classList.add('co3-modal-container');
modalContainer.setAttribute('tabindex', '0');
modalContainer.appendChild(iframe);
modalContainer.appendChild(closeButton);
modal.appendChild(modalContainer);
document.body.setAttribute('tabindex', '-1');
document.body.setAttribute('aria-hidden', 'true');
document.body.appendChild(modal);
document.addEventListener('keydown', handleEscKeyPress);

Check failure on line 39 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

'handleEscKeyPress' is not defined
modal.addEventListener('click', (event) => {
if (event.target === modal) {
removeModal(modal);

Check failure on line 42 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

'removeModal' is not defined
}
});

iframe.addEventListener('load', () => {
toggleLoader();

Check failure on line 47 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

'toggleLoader' is not defined
modalContainer.focus();
});
}

export default function decorate(block) {
const newChildren = [...block.children].map((entry) => {
Expand Down Expand Up @@ -36,7 +85,6 @@ export default function decorate(block) {
}

const videoAssets = block.querySelectorAll('a');

if (videoAssets.length > 0) {
const videoAsset = videoAssets[videoAssets.length - 1];

Expand All @@ -52,4 +100,27 @@ export default function decorate(block) {
block.append(videoElement);
}
}

// Query the video link and enable the play button
const videoLink = block.querySelector('.video-link');
const btnContainer = videoLink.closest('.button-container');
console.log('btnContainer', btnContainer);

Check warning on line 107 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement

if ((videoLink) && (btnContainer)) {
btnContainer.replaceWith(calciteButton({
'icon-end': 'play-f',
appearance: 'solid',
href: videoLink.href,
label: videoLink.textContent,
}, videoLink.textContent));
}
// listen for click events on 'calcite-button'
const calciteBtn = block.querySelector('calcite-button');
if (calciteBtn) {
calciteBtn.addEventListener('click', (evt) => {
console.log('clicked', calciteBtn);

Check warning on line 121 in eds/blocks/hero/hero.js

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
evt.preventDefault();
decorateModal();
});
}
}

0 comments on commit abcaa1b

Please sign in to comment.