]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻️ Refactor sponsor image handling (#14102)
authorAlejandra <90076947+alejsdev@users.noreply.github.com>
Mon, 22 Sep 2025 15:11:52 +0000 (17:11 +0200)
committerGitHub <noreply@github.com>
Mon, 22 Sep 2025 15:11:52 +0000 (17:11 +0200)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
docs/en/docs/css/custom.css
docs/en/docs/js/custom.js

index b192f6123a27399e3b44e379427434ca52d5d34b..a38df772f9eee335a8746c73ae2f5d36a262eb15 100644 (file)
@@ -102,7 +102,15 @@ a.announce-link:hover {
   align-items: center;
 }
 
-.announce-wrapper div.item {
+.announce-wrapper #announce-left div.item {
+  display: none;
+}
+
+.announce-wrapper #announce-right {
+  display: none;
+}
+
+.announce-wrapper #announce-right div.item {
   display: none;
 }
 
@@ -112,7 +120,7 @@ a.announce-link:hover {
   top: -10px;
   right: 0;
   font-size: 0.5rem;
-  color: #999;
+  color: #e6e6e6;
   background-color: #666;
   border-radius: 10px;
   padding: 0 10px;
index 425b7fce7fe38d703a5ac0e4c582849ce1280afa..48e95901d58e38ae54a542bbc87ab757af7324e4 100644 (file)
@@ -135,28 +135,43 @@ async function showRandomAnnouncement(groupId, timeInterval) {
     }
 }
 
-function hideSponsorOnImageError() {
-    const sponsorImages = document.querySelectorAll('.sponsor-image');
+function handleSponsorImages() {
     const announceRight = document.getElementById('announce-right');
+    if(!announceRight) return;
 
-    function hideAnnounceRight() {
-        if (announceRight) {
-            announceRight.style.display = 'none';
-        }
-    }
+    const sponsorImages = document.querySelectorAll('.sponsor-image');
 
-    sponsorImages.forEach(function(img) {
-        img.addEventListener('error', function() {
-            hideAnnounceRight();
+    const imagePromises = Array.from(sponsorImages).map(img => {
+        return new Promise((resolve, reject) => {
+            if (img.complete && img.naturalHeight !== 0) {
+                resolve();
+            } else {
+                img.addEventListener('load', () => {
+                    if (img.naturalHeight !== 0) {
+                        resolve();
+                    } else {
+                        reject();
+                    }
+                });
+                img.addEventListener('error', reject);
+            }
         });
     });
+
+    Promise.all(imagePromises)
+        .then(() => {
+            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()