From 57914c1faf3d1e5feb5552c7d4670d851cd646d7 Mon Sep 17 00:00:00 2001 From: Alejandra Date: Sun, 21 Sep 2025 17:14:49 +0200 Subject: [PATCH] Refactor handleSponsorImages --- docs/en/docs/js/custom.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/en/docs/js/custom.js b/docs/en/docs/js/custom.js index 425b7fce7..014bcfaff 100644 --- a/docs/en/docs/js/custom.js +++ b/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 announceRight = document.getElementById('announce-right'); - function hideAnnounceRight() { - if (announceRight) { - announceRight.style.display = 'none'; - } + if (announceRight) { + announceRight.style.display = 'none'; } - sponsorImages.forEach(function(img) { - img.addEventListener('error', function() { - hideAnnounceRight(); + const imagePromises = Array.from(sponsorImages).map(img => { + return new Promise((resolve, reject) => { + 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() { setupTermynal(); showRandomAnnouncement('announce-left', 5000) - showRandomAnnouncement('announce-right', 10000) - hideSponsorOnImageError(); + handleSponsorImages(); } document$.subscribe(() => { main()