Browse Source

Refactor handleSponsorImages

pull/14102/head
Alejandra 2 days ago
parent
commit
57914c1faf
  1. 33
      docs/en/docs/js/custom.js

33
docs/en/docs/js/custom.js

@ -135,28 +135,41 @@ async function showRandomAnnouncement(groupId, timeInterval) {
} }
} }
function hideSponsorOnImageError() { function handleSponsorImages() {
const sponsorImages = document.querySelectorAll('.sponsor-image'); const sponsorImages = document.querySelectorAll('.sponsor-image');
const announceRight = document.getElementById('announce-right'); const announceRight = document.getElementById('announce-right');
function hideAnnounceRight() { if (announceRight) {
if (announceRight) { announceRight.style.display = 'none';
announceRight.style.display = 'none';
}
} }
sponsorImages.forEach(function(img) { const imagePromises = Array.from(sponsorImages).map(img => {
img.addEventListener('error', function() { return new Promise((resolve, reject) => {
hideAnnounceRight(); if (img.complete) {
resolve();
} else {
img.addEventListener('load', resolve);
img.addEventListener('error', reject);
}
}); });
}); });
Promise.all(imagePromises)
.then(() => {
if (announceRight) {
announceRight.style.display = 'block';
showRandomAnnouncement('announce-right', 10000);
}
})
.catch(() => {
// do nothing
});
} }
async function main() { async function main() {
setupTermynal(); setupTermynal();
showRandomAnnouncement('announce-left', 5000) showRandomAnnouncement('announce-left', 5000)
showRandomAnnouncement('announce-right', 10000) handleSponsorImages();
hideSponsorOnImageError();
} }
document$.subscribe(() => { document$.subscribe(() => {
main() main()

Loading…
Cancel
Save