-
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: fix support for multiple card sections (#869)
- Loading branch information
1 parent
a68b35f
commit db63446
Showing
4 changed files
with
72 additions
and
53 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
/* | ||
* Function to display consistent image height for mixed card widths. | ||
*/ | ||
function setConsistentMediaHeight(cards) { | ||
cards.forEach(function(cardset) { | ||
const medias = Array.from(cardset.getElementsByClassName("usa-card__media")); | ||
|
||
if (medias.length > 0) { | ||
// Reset media height to default. | ||
medias.forEach(function(media) { | ||
let image = media.getElementsByTagName("img"); | ||
media.removeAttribute("style"); | ||
image[0].removeAttribute("style"); | ||
}); | ||
|
||
// Determine max height from smallest media found. | ||
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 mediaHeight = maxHeight / 16 + "rem"; | ||
let image = media.getElementsByTagName("img"); | ||
media.style.height = mediaHeight; | ||
image[0].setAttribute("style", "height: " + mediaHeight + ";"); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
document.addEventListener("DOMContentLoaded", function() { | ||
// Detect any mixed card widths. | ||
const cards = Array.from(document.querySelectorAll(".jcc-cards--2-60-40-cols, .jcc-cards--2-75-25-cols")); | ||
|
||
if (cards) { | ||
setConsistentMediaHeight(cards); | ||
window.onresize = function() { | ||
setConsistentMediaHeight(cards); | ||
}; | ||
} | ||
}); |
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
25 changes: 25 additions & 0 deletions
25
source/_patterns/03-organisms/cards/cards~media-two-75-25.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,25 @@ | ||
cards: | ||
heading: | ||
title: "Cards" | ||
lead: "<p>Ipsum velit bibendum class id sit justo, at fermentum suscipit rhoncus hac sociis blandit, ante tincidunt imperdiet himenaeos felis.</p>" | ||
num_cols: "2-75-25" | ||
items: | ||
- style: "media-top" | ||
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://source.unsplash.com/random/350x250/?people" | ||
alt: "green" | ||
link: | ||
url: "#" | ||
text: "Luctus nunc quam" | ||
- style: "media-top" | ||
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://source.unsplash.com/random/350x250/?face" | ||
alt: "green" | ||
link: | ||
url: "#" | ||
text: "Luctus nunc quam" | ||
|