From c96cea832adb73c8ec8aa7e1d69395f482b86d63 Mon Sep 17 00:00:00 2001 From: Henning Kulander Date: Fri, 30 Jan 2015 23:15:47 +0100 Subject: [PATCH 1/2] Added support for retina images using srcset in img tag. - Used by adding srcset string when pushing images to gallery. --- src/galleria.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/galleria.js b/src/galleria.js index a29a51c1..fdafbdfc 100644 --- a/src/galleria.js +++ b/src/galleria.js @@ -4905,6 +4905,12 @@ this.prependChild( 'info', 'myElement' ); self._layers[index].innerHTML = self.getData().layer || ''; + // Set srcset in img tag for responsive retina images. + if (data.srcset) { + $( image.image ).attr( 'srcset', data.srcset ); + $( image.image ).attr( 'sizes', image.width+"px" ); + } + self.trigger($.extend(evObj, { type: Galleria.LOADFINISH })); @@ -5151,6 +5157,12 @@ this.prependChild( 'info', 'myElement' ); complete: function( next ) { + // Set srcset in img tag for responsive retina images. + if (data.srcset) { + $( next.image ).attr( 'srcset', data.srcset ); + $( next.image ).attr( 'sizes', next.width+"px" ); + } + // toggle low quality for IE if ( 'image' in active ) { Utils.toggleQuality( active.image, false ); From 799216bdf0275184c943e1ed99451ae5d2ab87ad Mon Sep 17 00:00:00 2001 From: Henning Kulander Date: Fri, 30 Jan 2015 23:59:16 +0100 Subject: [PATCH 2/2] Use full viewport width as default width if we don't yet know the width of the image. --- src/galleria.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/galleria.js b/src/galleria.js index fdafbdfc..dd35d84a 100644 --- a/src/galleria.js +++ b/src/galleria.js @@ -4908,7 +4908,12 @@ this.prependChild( 'info', 'myElement' ); // Set srcset in img tag for responsive retina images. if (data.srcset) { $( image.image ).attr( 'srcset', data.srcset ); - $( image.image ).attr( 'sizes', image.width+"px" ); + if (image.width) { + $( image.image ).attr( 'sizes', image.width+"px" ); + } else { + // We don't know the size of the image yet, but it can't be wider than the viewport + $( image.image ).attr( 'sizes', "100wv" ); + } } self.trigger($.extend(evObj, {