File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -205,6 +205,7 @@ function update_bookmark() // update bookmark list
205
205
{
206
206
var fragment = document . createDocumentFragment ( ) ;
207
207
list_elements ( fragment , bookmarks , bookmark_onclick ) ;
208
+ add_lazy_to_images ( fragment ) ; // set images to lazy loading
208
209
209
210
fragment . appendChild ( document . createElement ( "br" ) ) ;
210
211
@@ -353,6 +354,7 @@ function update_history(id = null, type = null) // update the history list
353
354
}
354
355
var fragment = document . createDocumentFragment ( ) ;
355
356
list_elements ( fragment , search_history . slice ( ) . reverse ( ) , history_onclick ) ;
357
+ add_lazy_to_images ( fragment ) ; // set images to lazy loading
356
358
fragment . appendChild ( document . createElement ( "br" ) ) ;
357
359
358
360
Original file line number Diff line number Diff line change 3
3
var beep_audio = new Audio ( "../GBFML/assets/audio/beep.ogg" ) ; // play GBF beep
4
4
var beep_enabled = true ;
5
5
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
+ {
7
8
try
8
9
{
9
10
const response = await fetch ( url ) ;
@@ -179,4 +180,15 @@ function capitalize(string)
179
180
if ( string . length == 0 )
180
181
return string ;
181
182
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
+ } ) ;
182
194
}
You can’t perform that action at this time.
0 commit comments