generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19fd547
commit 9b358f5
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* stylelint-disable selector-class-pattern */ | ||
.section .v2-hero-wrapper { | ||
padding: 0; | ||
margin: 0; | ||
width: 100%; | ||
max-width: 100%; | ||
} | ||
|
||
.v2-hero__container, .v2-hero__container img { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const blockName = 'v2-hero'; | ||
|
||
export default function decorate(block) { | ||
const pictures = block.querySelectorAll('picture'); | ||
const imgParent = pictures[0].parentElement; | ||
const newPicture = document.createElement('picture'); | ||
const mediaQueries = ['(max-width: 749px)', '(min-width: 750px)']; | ||
const MQ = window.matchMedia('(min-width: 750px)'); | ||
const img = document.createElement('img'); | ||
|
||
imgParent.classList.add(`${blockName}__container`); | ||
|
||
mediaQueries.forEach((mediaQuery, index) => { | ||
const source = document.createElement('source'); | ||
source.media = mediaQuery; | ||
source.srcset = pictures[index].querySelector('img').src; | ||
newPicture.appendChild(source); | ||
if (MQ.matches) { | ||
img.src = pictures[index].querySelector('img').src; | ||
img.alt = pictures[index].querySelector('img').alt; | ||
} | ||
}); | ||
newPicture.appendChild(img); | ||
|
||
// Remove the old pictures | ||
pictures.forEach((picture) => picture.remove()); | ||
|
||
imgParent.appendChild(newPicture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters