-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TCI-1129: cleaner & more dynamic top/left-card image support (#867)
- Loading branch information
1 parent
090a9e7
commit e6c5d8c
Showing
8 changed files
with
118 additions
and
99 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
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,25 @@ | ||
/* | ||
* Consistent image height for mixed card widths. | ||
*/ | ||
const cards = Array.from(document.querySelectorAll('.jcc-cards--2-60-40-cols, .jcc-cards--2-75-25-cols')); | ||
|
||
cards.forEach(function (cardset) { | ||
// If media containers exist. | ||
let medias = Array.from(cardset.getElementsByClassName('usa-card__media')); | ||
|
||
if (medias.length > 0) { | ||
// Determine max height from smallest image. | ||
let maxHeight = medias[0].offsetHeight; | ||
medias.forEach(function(media) { | ||
maxHeight = Math.min(maxHeight, media.offsetHeight); | ||
}) | ||
|
||
// Adjust all container and image heights to max allowed. | ||
medias.forEach(function (media) { | ||
let image = media.getElementsByTagName('img'); | ||
let imageHeight = maxHeight/16 + 'rem'; | ||
image[0].setAttribute('style', 'height: ' + imageHeight + ';'); | ||
media.style.height = imageHeight; | ||
}); | ||
} | ||
}); |
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
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
source/_patterns/02-molecules/card/card~media-image-left.yml
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,10 @@ | ||
card: | ||
style: "media-left" | ||
title: "Posuere et ornare" | ||
body: "<p>Tellus justo ornare, ipsum pulvinar praesent viverra luctus sociosqu eu, dolor blandit cum vel tempus volutpat.</p>" | ||
media: | ||
src: "https://newsroom.courts.ca.gov/sites/default/files/newsroom/2020-08/supreme%20court%20mural%20%28SF%29.jpg" | ||
alt: "Image media test" | ||
link: | ||
url: "#" | ||
text: "Luctus nunc quam" |
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
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
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