diff --git a/js/lazyload.js b/js/lazyload.js
index 73789e73..b4c1fcc5 100644
--- a/js/lazyload.js
+++ b/js/lazyload.js
@@ -68,7 +68,8 @@ function getCellLazyImages( cellElem ) {
}
// select lazy images in cell
var lazySelector = 'img[data-flickity-lazyload], ' +
- 'img[data-flickity-lazyload-src], img[data-flickity-lazyload-srcset]';
+ 'img[data-flickity-lazyload-src], img[data-flickity-lazyload-srcset], ' +
+ 'source[data-flickity-lazyload-srcset]';
var imgs = cellElem.querySelectorAll( lazySelector );
return utils.makeArray( imgs );
}
@@ -96,7 +97,9 @@ LazyLoader.prototype.load = function() {
this.img.getAttribute('data-flickity-lazyload-src');
var srcset = this.img.getAttribute('data-flickity-lazyload-srcset');
// set src & serset
- this.img.src = src;
+ if ( this.img.tagName.toLowerCase() === 'img' && src ) {
+ this.img.src = src;
+ }
if ( srcset ) {
this.img.setAttribute( 'srcset', srcset );
}
diff --git a/test/index.html b/test/index.html
index 8e6a9160..1579b649 100644
--- a/test/index.html
+++ b/test/index.html
@@ -55,6 +55,7 @@
+
@@ -239,6 +240,21 @@
lazyload srcset
+ lazyload picture source srcset
+
+
+
+
+
+
groupCells
diff --git a/test/unit/lazyload-picture-srcset.js b/test/unit/lazyload-picture-srcset.js
new file mode 100644
index 00000000..e13b64db
--- /dev/null
+++ b/test/unit/lazyload-picture-srcset.js
@@ -0,0 +1,30 @@
+QUnit.test( 'lazyload picture srcset', function( assert ) {
+ 'use strict';
+
+ var done = assert.async();
+
+ var gallery = document.querySelector('#lazyload-picture-srcset');
+ var flkty = new Flickity( gallery, {
+ lazyLoad: 1,
+ } );
+
+ var loadCount = 0;
+ flkty.on( 'lazyLoad', function( event, cellElem ) {
+ loadCount++;
+
+ assert.equal( event.type, 'load', 'event.type == load' );
+ assert.ok( event.target.complete, 'img ' + loadCount + ' is complete' );
+ assert.ok( cellElem, 'cellElement argument there' );
+ var sources = cellElem.querySelectorAll('source[srcset]');
+ assert.equal( sources.length, 2, 'All source elements of cell loaded' );
+ var lazyAttr = Array.from( sources ).some( function( el ) {
+ return el.getAttribute('data-flickity-lazyload-srcset');
+ } );
+ assert.ok( !lazyAttr, 'data-flickity-lazyload-srcset attribute removed' );
+
+ if ( loadCount == 2 ) {
+ done();
+ }
+ } );
+
+} );