11import { CLASS_LOADING } from '../../constants/classes' ;
22import {
33 EVENT_LAZYLOAD_LOADED ,
4- EVENT_MOUNTED ,
54 EVENT_MOVED ,
65 EVENT_REFRESH ,
76 EVENT_RESIZE ,
@@ -60,7 +59,7 @@ type LazyLoadEntry = [ HTMLImageElement, SlideComponent, HTMLSpanElement ];
6059export function LazyLoad ( Splide : Splide , Components : Components , options : Options ) : LazyLoadComponent {
6160 const { on, off, bind, emit } = EventInterface ( Splide ) ;
6261 const isSequential = options . lazyLoad === 'sequential' ;
63- const events = [ EVENT_MOUNTED , EVENT_REFRESH , EVENT_MOVED , EVENT_SCROLLED ] ;
62+ const events = [ EVENT_MOVED , EVENT_SCROLLED ] ;
6463
6564 /**
6665 * Stores data of images.
@@ -74,17 +73,31 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
7473 if ( options . lazyLoad ) {
7574 init ( ) ;
7675 on ( EVENT_REFRESH , init ) ;
77- isSequential || on ( events , check ) ;
7876 }
7977 }
8078
8179 /**
82- * Finds images to register entries .
83- * Note that spinner can be already available because of `refresh()` .
80+ * Initializes the component and start loading images .
81+ * Be aware that `refresh` also calls this method .
8482 */
8583 function init ( ) {
8684 empty ( entries ) ;
85+ register ( ) ;
86+
87+ if ( isSequential ) {
88+ loadNext ( ) ;
89+ } else {
90+ off ( events ) ;
91+ on ( events , check ) ;
92+ check ( ) ;
93+ }
94+ }
8795
96+ /**
97+ * Finds images and register them as entries with creating spinner elements.
98+ * Note that spinner can be already available because of `refresh()`.
99+ */
100+ function register ( ) : void {
88101 Components . Slides . forEach ( Slide => {
89102 queryAll < HTMLImageElement > ( Slide . slide , IMAGE_SELECTOR ) . forEach ( img => {
90103 const src = getAttribute ( img , SRC_DATA_ATTRIBUTE ) ;
@@ -100,8 +113,6 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
100113 }
101114 } ) ;
102115 } ) ;
103-
104- isSequential && loadNext ( ) ;
105116 }
106117
107118 /**
0 commit comments