Skip to content

Commit

Permalink
Fix srcset support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cardinal90 committed Feb 16, 2018
1 parent 5d0c0a5 commit c2c2e06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions dist/jquery.waitforimages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! waitForImages jQuery Plugin - v2.4.0 - 2018-02-13
* https://github.com/alexanderdickson/waitForImages
* Copyright (c) 2018 Alex Dickson; Licensed MIT */
/*! waitForImages jQuery Plugin - v2.4.0 - 2018-02-17
* https://github.com/alexanderdickson/waitForImages
* Copyright (c) 2018 Alex Dickson; Licensed MIT */
;(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
Expand All @@ -18,7 +18,7 @@

// Is srcset supported by this browser?
var hasSrcset = (function(img) {
return img.srcset && img.sizes;
return img.srcset !== undefined && img.sizes !== undefined;

This comment has been minimized.

Copy link
@Cardinal90

Cardinal90 Feb 16, 2018

Author

If srcset is supported, img.srcset and img.sizes return empty strings resulting in falsey value.

})(new Image());

// CSS properties which contain references to images.
Expand Down Expand Up @@ -216,9 +216,9 @@

});

if (hasSrcset && img.srcset) {
image.srcset = img.srcset;
image.sizes = img.sizes;
if (hasSrcset && img.element.srcset) {
image.srcset = img.element.srcset;
image.sizes = img.element.sizes;

This comment has been minimized.

Copy link
@Cardinal90

Cardinal90 Feb 16, 2018

Author

There is no srcset on img, when waitForAll is false on line 109. Also no sizes in any case. I wrote the condition this way rather than adding those attributes onto img.

}
image.src = img.src;
});
Expand Down
4 changes: 2 additions & 2 deletions dist/jquery.waitforimages.min.js

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

8 changes: 4 additions & 4 deletions src/jquery.waitforimages.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Is srcset supported by this browser?
var hasSrcset = (function(img) {
return img.srcset && img.sizes;
return img.srcset !== undefined && img.sizes !== undefined;
})(new Image());

// CSS properties which contain references to images.
Expand Down Expand Up @@ -213,9 +213,9 @@

});

if (hasSrcset && img.srcset) {
image.srcset = img.srcset;
image.sizes = img.sizes;
if (hasSrcset && img.element.srcset) {
image.srcset = img.element.srcset;
image.sizes = img.element.sizes;
}
image.src = img.src;
});
Expand Down

0 comments on commit c2c2e06

Please sign in to comment.