20
20
const lazyAttr = 'data-flickity-lazyload' ;
21
21
const lazySrcAttr = `${ lazyAttr } -src` ;
22
22
const lazySrcsetAttr = `${ lazyAttr } -srcset` ;
23
- const imgSelector = `img[${ lazyAttr } ], img[${ lazySrcAttr } ], img[${ lazySrcsetAttr } ]` ;
23
+ const imgSelector = `img[${ lazyAttr } ], img[${ lazySrcAttr } ], ` +
24
+ `img[${ lazySrcsetAttr } ], source[${ lazySrcsetAttr } ]` ;
24
25
25
26
Flickity . create . lazyLoad = function ( ) {
26
27
this . on ( 'select' , this . lazyLoad ) ;
@@ -31,7 +32,7 @@ Flickity.create.lazyLoad = function() {
31
32
let proto = Flickity . prototype ;
32
33
33
34
proto . lazyLoad = function ( ) {
34
- let lazyLoad = this . options . lazyLoad ;
35
+ let { lazyLoad } = this . options ;
35
36
if ( ! lazyLoad ) return ;
36
37
37
38
// get adjacent cells, use lazyLoad option for adjacent count
@@ -108,7 +109,8 @@ LazyLoader.prototype.complete = function( event, className ) {
108
109
// unbind events
109
110
this . img . removeEventListener ( 'load' , this ) ;
110
111
this . img . removeEventListener ( 'error' , this ) ;
111
- this . img . classList . add ( className ) ;
112
+ let mediaElem = this . img . parentNode . matches ( 'picture' ) ? this . img . parentNode : this . img ;
113
+ mediaElem . classList . add ( className ) ;
112
114
113
115
this . onComplete ( this . img , event ) ;
114
116
} ;
0 commit comments