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

Fixes Article Slider Bugs + Style Refinements #581

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions css/block/ucb-article-slider-block.css
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,9 @@
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
color: #cfb87c;
}

article-slider-block .ucb-loading-data{
width: 100%;
display: flex;
justify-content: center;
}
47 changes: 5 additions & 42 deletions js/ucb-article-slider-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class ArticleSliderBlockElement extends HTMLElement {
// finds the focial point version of the thumbnail
altFilterData.map((item)=>{
// checks if consumer is working, else default to standard image instead of focal image
if(item.links.focal_image_square != undefined){
altObj[item.id] = item.links.focal_image_square.href
if(item.links.focal_image_wide != undefined){
altObj[item.id] = item.links.focal_image_wide.href
} else {
altObj[item.id] = item.attributes.uri.url
}
Expand Down Expand Up @@ -103,40 +103,7 @@ class ArticleSliderBlockElement extends HTMLElement {
// If there's no categories or tags that are in the exclusions, proceed
if (doesIncludeCat.length == 0 && doesIncludeTag.length == 0) {
// okay to render
let bodyAndImageId = item.relationships.field_ucb_article_content.data.length ? item.relationships.field_ucb_article_content.data[0].id : "";
let body = item.attributes.field_ucb_article_summary ? item.attributes.field_ucb_article_summary : "";
body = body.trim();
let imageSrc = "";

if (!body.length && bodyAndImageId != "") {
this.getArticleParagraph(bodyAndImageId)
.then((response) => response.json())
.then((data) => {
// Remove any html tags within the article
let htmlStrip = data.data.attributes.field_article_text.processed.replace(
/<\/?[^>]+(>|$)/g,
""
)
// Remove any line breaks if media is embedded in the body
let lineBreakStrip = htmlStrip.replace(/(\r\n|\n|\r)/gm, "");
// take only the first 100 words ~ 500 chars
let trimmedString = lineBreakStrip.substr(0, 250);
// if in the middle of the string, take the whole word
if(trimmedString.length > 100){
trimmedString = trimmedString.substr(
0,
Math.min(
trimmedString.length,
trimmedString.lastIndexOf(" ")
)
)
body = `${trimmedString}...`;
}
// set the contentBody of Article Summary card to the minified body instead
body = `${trimmedString}`;
document.getElementById(`body-${bodyAndImageId}`).innerText = body;
})
}

// if no thumbnail, show no image
if (!item.relationships.field_ucb_article_thumbnail.data) {
Expand All @@ -146,10 +113,7 @@ class ArticleSliderBlockElement extends HTMLElement {
let thumbId = item.relationships.field_ucb_article_thumbnail.data.id;
imageSrc = altObj[idObj[thumbId]];
}

//Date - make human readable
const options = { year: 'numeric', month: 'short', day: 'numeric' };
let date = new Date(item.attributes.created).toLocaleDateString('en-us', options);

let title = item.attributes.title;
let link = item.attributes.path.alias;

Expand All @@ -158,8 +122,6 @@ class ArticleSliderBlockElement extends HTMLElement {
title,
link,
image: imageSrc,
date,
body,
}
// Adds the article object to the final array of articles chosen
finalArticles.push(article)
Expand All @@ -185,8 +147,9 @@ class ArticleSliderBlockElement extends HTMLElement {
}

// Case for Too many articles
if(finalArticles.length > count){
if(finalArticles.length >= count || (finalArticles.length >= count && NEXTJSONURL)){
finalArticles.length = count
this.renderDisplay(finalArticles)
}

// Have articles and want to proceed
Expand Down