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

Add hotspot block that can support text, image and video #107

Merged
merged 6 commits into from
Oct 3, 2024

Conversation

RitwikSrivastava
Copy link

@RitwikSrivastava RitwikSrivastava commented Sep 24, 2024

This change adds a Hotspot block.
On an image, the user can place various hotspot at different positions that is configurable via top and left attribute in the doc.
The hotspot content supports text, image and video too which can be further extended as per the requirement. And all this while maintaining 100 LHS .

Fix #

Test URLs:

LHS is 100
pagespeed - https://pagespeed.web.dev/analysis/https-hotspotblock--franklin-assets-selector--hlxsites-hlx-live-hotspot-block-hotspot/imgjlh7yjk?form_factor=desktop

Copy link

aem-code-sync bot commented Sep 24, 2024

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

Copy link

aem-code-sync bot commented Sep 24, 2024

Page Scores Audits Google
📱 /hotspot-block/hotspot PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ /hotspot-block/hotspot PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

.block.hotspot > div.hotspot .hotspot-content video {
width: 400px;
height: auto;
max-width: unset !important
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid !important

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed




.section.hotspot-container > .section-container {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mean that hotspot section would be styled differently and likely result in the style leaking over to other blocks in the same section. To avoid that, hotspot would need to be in its own section without anything else. Can we avoid this? One option would be to wrap the hostspot block in another div and apply these styles there to it without impacting container section styles.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorporated.

}


main .embed .embed-default {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have styles for embed in hotspot block?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required, hence removed

}


.section.hotspot-container > .section-container > div:first-of-type {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see prior comment on similar lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorporated.

}

@media (width >= 62rem) {
.section.hotspot-container > .section-container {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid influencing section styles at block level.

margin: auto;
}

.section.hotspot-container > .section-container h1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid influencing section styles at block level.

[...block.children].forEach((row, r) => {
if (r > 0) {
const content = [...row.children][0].textContent.trim();
const isImage = content.endsWith('.jpg') || content.endsWith('.png') || content.endsWith('.gif') || content.endsWith('.jpeg');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any image URL can be incorporated as per the requirement. We can use also use regex as per requirement which is upto customisation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but I am wondering if there's no way of telling the image by just looking at the URL. One option could be to express it as a variant of the block. For e.g. Hotspot(image) , Hotspot(video) etc. and based on that, decide the tag to inject.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will work but then wouldn't it limit the block to either have a specific type of hotspot content (either image or vide )and not a mix of contents.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yes, I will make the changes for fixed hotspot content.

if (r > 0) {
const content = [...row.children][0].textContent.trim();
const isImage = content.endsWith('.jpg') || content.endsWith('.png') || content.endsWith('.gif') || content.endsWith('.jpeg');
const isVideo = content.endsWith('.mp4') || content.endsWith('.webm') || content.endsWith('play') || content.endsWith('content/'); // Adjust condition as needed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any video URL can be incorporated as per the requirement. We can use also use regex as per requirement which is upto customisation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, bit I think there may be cases where just looking at the url may not tell. Maybe need a similar approach like here

const contentContainer = document.createElement('div');
contentContainer.classList.add('hotspot-content');

if (isImage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of explicitly adding markup for image, video etc, you could load a fragment and the fragment can contain anything. It'd be more generic. It may be a bit slow though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is optional btw, and for now we can just support fixed hotspot content.

opacity: 1;
}

main .embed-default {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hostspot block should not influence embed-default styles. no?

const contentContainer = document.createElement('div');
contentContainer.classList.add('hotspot-content');

if (isImage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is optional btw, and for now we can just support fixed hotspot content.

@RitwikSrivastava
Copy link
Author

@sdmcraft Review comments incorporated. Also fixed hotspot variant added.

@RitwikSrivastava RitwikSrivastava merged commit a069fba into main Oct 3, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants