Skip to content

Commit

Permalink
increasing hotspot iframe size and video smart crop adjustment (#104)
Browse files Browse the repository at this point in the history
Co-authored-by: Anurag Gupta <[email protected]>
  • Loading branch information
anuraggupta228 and Anurag Gupta authored Sep 11, 2024
1 parent 99dffff commit e44bb92
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
24 changes: 17 additions & 7 deletions blocks/embed/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const videoConfig = {
controls: false,
};

const scPlayerHeight = '44rem';

// Event listener to handle video configuration messages
window.addEventListener("message", (event) => {
if (event.data.name === "video-config") {
Expand All @@ -31,20 +33,28 @@ const loadScript = (url, callback, type) => {
return script;
};

function isSmartCropVideo(url) {
return url.includes('SmartCropVideoViewer.html');
}

// const getDefaultEmbed = (url, hasMobileView) => `
// <div class="embed-default ${hasMobileView ? 'mobile-view' : ''}">
// <iframe src="${url.href}" style="border: 0; top: 0; left: 0; width: 100%; height: 100%; position: absolute;"
// allowfullscreen="" scrolling="no" allow="encrypted-media; autoplay; loop"
// title="Content from ${url.hostname}" loading="lazy">
// </iframe>
// </div>`;
const getDefaultEmbed = (url, hasMobileView) => `
<div class="embed-default ${hasMobileView ? 'mobile-view' : ''}">
<iframe src="${url.href}" style="border: 0; width: 70%; height: 70%; top:0, left:0; position: absolute;"
allowfullscreen="" scrolling="no" allow="encrypted-media; autoplay; loop"
title="Content from ${url.hostname}" loading="lazy">
</iframe>
</div>`;
const getDefaultEmbed = (url, hasMobileView) => {
const height = isSmartCropVideo(url.href) ? scPlayerHeight : '70%';
return `
<div class="embed-default ${hasMobileView ? 'mobile-view' : ''}">
<iframe src="${url.href}" style="border: 0; width: 70%; height: ${height}; top:0, left:0; position: absolute;"
allowfullscreen="" scrolling="no" allow="encrypted-media; autoplay; loop"
title="Content from ${url.hostname}" loading="lazy">
</iframe>
</div>
`;
};

const embedYoutube = (url, autoplay) => {
const usp = new URLSearchParams(url.search);
Expand Down
5 changes: 5 additions & 0 deletions blocks/hotspot/hotspot.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ main .embed .embed-default {
padding-bottom: 56.25%;
}

.hotspot-content iframe {
width: 37.5rem;
height: 18.75rem;
}




Expand Down
37 changes: 37 additions & 0 deletions blocks/hotspot/hotspot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
function attachEvents(block) {
// Hide all hotspots lying under the iframe when the iframe is hovered
block.querySelectorAll('iframe').forEach(frame => {
frame.addEventListener('mouseover', (e) => {
const frameRect = frame.getBoundingClientRect();
const hotspots = document.querySelectorAll('.hotspot');

document.querySelectorAll('.hotspot').forEach(hotspot => {
if (hotspot === e.target.closest('.hotspot')) {
return;
}

const hotspotRect = hotspot.getBoundingClientRect();

// Check if the hotspot is within the iframe's viewport
const isInViewport = (
hotspotRect.top >= frameRect.top &&
hotspotRect.left >= frameRect.left &&
hotspotRect.bottom <= frameRect.bottom &&
hotspotRect.right <= frameRect.right
);

if (isInViewport) {
hotspot.style.display = 'none';
}
});
});
frame.addEventListener('mouseout', () => {
document.querySelectorAll('.hotspot').forEach(hotspot => {
hotspot.style.display = 'block';
});
});
});
}

export default function decorate(block) {
[...block.children].forEach((row, r) => {
if (r > 0) {
Expand Down Expand Up @@ -52,4 +87,6 @@ export default function decorate(block) {
row.remove();
}
});

attachEvents(block);
}

0 comments on commit e44bb92

Please sign in to comment.