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

Adaptive Banner for homepage #1155

Merged
merged 3 commits into from
Jul 1, 2024
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
43 changes: 39 additions & 4 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,34 @@ <h6><a class="btn-white-black"
req.send(null);
} // function "getDataFromUrl" ends here

// Update banner title for homepage from the blobserver
function updateBanner(data) {
try {
// Get the current language
const lang = document.documentElement.lang;

// Find the active title for the 'portal' target
const title = data.banner_titles.find(title => title.target === 'pathogens-portal' && title.active);
if (title && title[lang]) {
const titleElement = document.querySelector('h2#home-banner');
titleElement.textContent = title[lang];
} else {
console.warn('No title found for the language.');
}
} catch (error) {
console.error('An error occurred while updating banner titles:', error);
} finally {
// Show the hidden banner regardless of whether titles were fetched successfully
const banner1 = document.getElementById("home-banner");
if (banner1) {
banner1.classList.remove("d-none");
} else {
console.warn('Banner element with ID "home-banner" not found.');
}
}
}; // function updateBanner ends here

// Add the events fetched from blobserver
function addEvents(data) {
var dataArray = data.items, eventList = [];
// Not interested if the deadline has already passed
Expand Down Expand Up @@ -302,11 +330,18 @@ <h4 class="mb-1">Events</h4>
};
} // function "addEvents" ends here

// Call the function to fetch, parse and display events
// Call the function to update banner, if any mentioned in blob server
getDataFromUrl(
decodeURIComponent("https%3A%2F%2Fblobserver.dc.scilifelab.se%2Fblob%2Fpathogens_portal_events.json"),
addEvents
);
decodeURIComponent("https%3A%2F%2Fblobserver.dc.scilifelab.se%2Fblob%2Ffreya-banner.json"),
updateBanner
)
// For english site, Call the function to fetch, parse and display events
if (document.documentElement.lang === "en") {
getDataFromUrl(
decodeURIComponent("https%3A%2F%2Fblobserver.dc.scilifelab.se%2Fblob%2Fpathogens_portal_events.json"),
addEvents
);
};

// Add latest tag to very recent news when content is loaded
document.querySelectorAll("#news-items-container .small").forEach(
Expand Down
3 changes: 2 additions & 1 deletion layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
style="background-image: linear-gradient(to bottom, rgba(55, 174, 148, 0.52), rgba(55, 174, 148, 0.73)),
url('{{ if .Params.header_illustration }}{{ .Params.header_illustration }}{{ else }}/img/csm_coronavirus_mc.jpg{{ end }}');">
<div class="container">
<h2>{{ if .IsHome }}
<h2 {{ if .IsHome }}class="d-none" id="home-banner"{{ end }}>
{{ if .IsHome }}
{{ (index $.Site.Params.lang_strings .Site.Language.Lang).home_title }}
{{ else if eq .Parent.Section "highlights_topics" }}
{{ with .Site.GetPage "/highlights" }}
Expand Down
Loading