Skip to content

Commit

Permalink
improve automatic sizes calculation if lqip pattern is used (see #43)
Browse files Browse the repository at this point in the history
  • Loading branch information
aFarkas committed Jan 28, 2015
1 parent 70b4ed6 commit d836257
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lazysizes.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,21 @@
};

var unveilElement = function (elem, force){
var sources, i, len, sourceSrcset, sizes, src, srcset, parent, isPicture, event, firesLoad, customMedia;
var sources, i, len, sourceSrcset, src, srcset, parent, isPicture, event, firesLoad, customMedia;

var curSrc = elem.currentSrc || elem.src;
var isImg = regImg.test(elem.nodeName);

if(!supportNativeLQIP && !isCompleted && isImg && curSrc && !elem.complete){return;}
//allow using sizes="auto", but don't use. it's invalid. Use data-sizes="auto" or a valid value for sizes instead (i.e.: sizes="80vw")
var sizes = elem.getAttribute(lazySizesConfig.sizesAttr) || elem.getAttribute('sizes');
var isAuto = sizes == 'auto';

if(!(event = triggerEvent(elem, 'lazybeforeunveil', {force: !!force})).defaultPrevented){
if( (isAuto || (!supportNativeLQIP && !isCompleted)) && isImg && curSrc && !elem.complete){return;}

//allow using sizes="auto", but don't use. it's invalid. Use data-sizes="auto" or a valid value for sizes instead (i.e.: sizes="80vw")
sizes = elem.getAttribute(lazySizesConfig.sizesAttr) || elem.getAttribute('sizes');
if(!(event = triggerEvent(elem, 'lazybeforeunveil', {force: !!force})).defaultPrevented){

if(sizes){
if(sizes == 'auto'){
if(isAuto){
autoSizer.updateElem(elem, true);
} else {
elem.setAttribute('sizes', sizes);
Expand Down
2 changes: 1 addition & 1 deletion lazysizes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d836257

Please sign in to comment.