Skip to content

Commit

Permalink
TCI-1129: fix support for multiple card sections (#869)
Browse files Browse the repository at this point in the history
  • Loading branch information
melwong-jcc authored Jan 12, 2024
1 parent a68b35f commit db63446
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 53 deletions.
49 changes: 0 additions & 49 deletions source/_patterns/02-molecules/card/card.js

This file was deleted.

43 changes: 43 additions & 0 deletions source/_patterns/03-organisms/cards/cards.js
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);
};
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cards:
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://placeimg.com/350/250/nature"
src: "https://source.unsplash.com/random/350x250/?nature"
alt: "Cupidatat non proident, sunt in culpa qui"
link:
url: "#"
Expand All @@ -19,7 +19,7 @@ cards:
title: "Posuere et ornare"
body: "<p>In torquent consequat quam vulputate himenaeos semper ut aliquam at, iaculis ac platea laoreet ridiculus mattis sagittis volutpat hendrerit, vehicula orci dictum dictumst nunc scelerisque lacus auctor.</p>"
media:
src: "https://placeimg.com/350/250/animals"
src: "https://source.unsplash.com/random/350x250/?animals"
alt: "Cupidatat non proident, sunt in culpa qui"
link:
url: "#"
Expand All @@ -30,7 +30,7 @@ cards:
title: "Visual Hover"
body: "<p>The selected overlay color will appear 90% opaque on hover. Habitasse nec dui adipiscing massa magna mollis morbi netus malesuada, odio varius id eu integer felis tellus at feugiat.</p>"
media:
src: "https://placeimg.com/350/250/people"
src: "https://source.unsplash.com/random/350x250/?people"
alt: "Cupidatat non proident, sunt in culpa qui"
link:
url: "#"
Expand All @@ -40,7 +40,7 @@ cards:
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://placeimg.com/350/250/tech"
src: "https://source.unsplash.com/random/350x250/?tech"
alt: "Cupidatat non proident, sunt in culpa qui"
link:
url: "#"
Expand Down
25 changes: 25 additions & 0 deletions source/_patterns/03-organisms/cards/cards~media-two-75-25.yml
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"

0 comments on commit db63446

Please sign in to comment.