mirror of https://github.com/tiangolo/fastapi.git
♻️ Refactor sponsor image handling (#14102)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
f0da082dd3
commit
8170860322
|
|
@ -102,7 +102,15 @@ a.announce-link:hover {
|
||||||
align-items: center;
|
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;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -112,7 +120,7 @@ a.announce-link:hover {
|
||||||
top: -10px;
|
top: -10px;
|
||||||
right: 0;
|
right: 0;
|
||||||
font-size: 0.5rem;
|
font-size: 0.5rem;
|
||||||
color: #999;
|
color: #e6e6e6;
|
||||||
background-color: #666;
|
background-color: #666;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
|
||||||
|
|
@ -135,28 +135,43 @@ async function showRandomAnnouncement(groupId, timeInterval) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSponsorOnImageError() {
|
function handleSponsorImages() {
|
||||||
const sponsorImages = document.querySelectorAll('.sponsor-image');
|
|
||||||
const announceRight = document.getElementById('announce-right');
|
const announceRight = document.getElementById('announce-right');
|
||||||
|
if(!announceRight) return;
|
||||||
|
|
||||||
function hideAnnounceRight() {
|
const sponsorImages = document.querySelectorAll('.sponsor-image');
|
||||||
if (announceRight) {
|
|
||||||
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 && 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() {
|
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…
Reference in New Issue