Skip to content

Commit b0490de

Browse files
committed
Set history and bookmark to lazy loading by default
1 parent 41c50fc commit b0490de

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

js/page.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ function update_bookmark() // update bookmark list
205205
{
206206
var fragment = document.createDocumentFragment();
207207
list_elements(fragment, bookmarks, bookmark_onclick);
208+
add_lazy_to_images(fragment); // set images to lazy loading
208209

209210
fragment.appendChild(document.createElement("br"));
210211

@@ -353,6 +354,7 @@ function update_history(id = null, type = null) // update the history list
353354
}
354355
var fragment = document.createDocumentFragment();
355356
list_elements(fragment, search_history.slice().reverse(), history_onclick);
357+
add_lazy_to_images(fragment); // set images to lazy loading
356358
fragment.appendChild(document.createElement("br"));
357359

358360

js/util.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
var beep_audio = new Audio("../GBFML/assets/audio/beep.ogg"); // play GBF beep
44
var beep_enabled = true;
55

6-
async function fetchJSON(url) { // generic function to request a JSON file.
6+
async function fetchJSON(url) // generic function to request a JSON file.
7+
{
78
try
89
{
910
const response = await fetch(url);
@@ -179,4 +180,15 @@ function capitalize(string)
179180
if(string.length == 0)
180181
return string;
181182
return string.charAt(0).toUpperCase() + string.slice(1);
183+
}
184+
185+
// add lazy loading to all images found in the element children
186+
function add_lazy_to_images(node)
187+
{
188+
// finds all descendant elements
189+
const images = node.querySelectorAll('img');
190+
191+
images.forEach(img => {
192+
img.loading = 'lazy';
193+
});
182194
}

0 commit comments

Comments
 (0)