Skip to content

Commit

Permalink
modified: common/footer.html
Browse files Browse the repository at this point in the history
	modified:   error/404/content.js
	modified:   home-css/content.js
  • Loading branch information
ThakshilaDamsak committed Sep 13, 2023
1 parent 784e87c commit 1ba0289
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion common/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</script>

<div id="site-info" class="hidden">
<p>v20.7 | <a href="https://github.com/ThakshilaDamsak/ThakshilaDamsak.github.io" target="_blank">GitHub Repository</a></p>
<p>v20.8 | <a href="https://github.com/ThakshilaDamsak/ThakshilaDamsak.github.io" target="_blank">GitHub Repository</a></p>
</div>

<script>
Expand Down
15 changes: 11 additions & 4 deletions error/404/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ const imageElements = Array.from(imageContainer.getElementsByTagName('img'));
// Create an array of promises for each image element
const imagePromises = imageElements.map(image => {
// Return a new promise that resolves when the image loads
return new Promise(resolve => {
return new Promise((resolve, reject) => {
image.addEventListener('load', resolve);
image.addEventListener('error', reject); // add an error handler
})
.catch(error => {
// Handle the error
console.error(error);
alert('Something went wrong. Please try again.');
// You can also try to reload the image here, or skip it and resolve anyway
});
});

// Wait for all the promises to resolve
Promise.all(imagePromises).then(() => {
// All the images have loaded
console.log('All images loaded');
// All the images have loaded or failed gracefully
console.log('All images handled');

// Fetch the content of the content HTML file
fetch('/error/404/content.html')
Expand All @@ -32,4 +39,4 @@ Promise.all(imagePromises).then(() => {
document.body.appendChild(newScript);
});
});
});
});
15 changes: 11 additions & 4 deletions home-css/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ const imageElements = Array.from(imageContainer.getElementsByTagName('img'));
// Create an array of promises for each image element
const imagePromises = imageElements.map(image => {
// Return a new promise that resolves when the image loads
return new Promise(resolve => {
return new Promise((resolve, reject) => {
image.addEventListener('load', resolve);
image.addEventListener('error', reject); // add an error handler
})
.catch(error => {
// Handle the error
console.error(error);
alert('Something went wrong. Please try again.');
// You can also try to reload the image here, or skip it and resolve anyway
});
});

// Wait for all the promises to resolve
Promise.all(imagePromises).then(() => {
// All the images have loaded
console.log('All images loaded');
// All the images have loaded or failed gracefully
console.log('All images handled');

// Fetch the content of the content HTML file
fetch('/home-css/content.html')
Expand All @@ -32,4 +39,4 @@ Promise.all(imagePromises).then(() => {
document.body.appendChild(newScript);
});
});
});
});

0 comments on commit 1ba0289

Please sign in to comment.