diff --git a/dist/jquery.waitforimages.js b/dist/jquery.waitforimages.js index e9457df..062489f 100644 --- a/dist/jquery.waitforimages.js +++ b/dist/jquery.waitforimages.js @@ -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. @@ -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; })(new Image()); // CSS properties which contain references to images. @@ -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; } image.src = img.src; }); diff --git a/dist/jquery.waitforimages.min.js b/dist/jquery.waitforimages.min.js index 1380ec4..aabb41b 100644 --- a/dist/jquery.waitforimages.min.js +++ b/dist/jquery.waitforimages.min.js @@ -1,2 +1,2 @@ -/*! waitForImages jQuery Plugin 2018-02-13 */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){var b="waitForImages",c=function(a){return a.srcset&&a.sizes}(new Image);a.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage","cursor"],hasImageAttributes:["srcset"]},a.expr.pseudos["has-src"]=function(b){return a(b).is('img[src][src!=""]')},a.expr.pseudos.uncached=function(b){return!!a(b).is(":has-src")&&!b.complete},a.fn.waitForImages=function(){var d,e,f,g=0,h=0,i=a.Deferred(),j=this,k=[],l=a.waitForImages.hasImageProperties||[],m=a.waitForImages.hasImageAttributes||[],n=/url\(\s*(['"]?)(.*?)\1\s*\)/g;if(a.isPlainObject(arguments[0])?(f=arguments[0].waitForAll,e=arguments[0].each,d=arguments[0].finished):1===arguments.length&&"boolean"===a.type(arguments[0])?f=arguments[0]:(d=arguments[0],e=arguments[1],f=arguments[2]),d=d||a.noop,e=e||a.noop,f=!!f,!a.isFunction(d)||!a.isFunction(e))throw new TypeError("An invalid callback was supplied.");return this.each(function(){var b=a(this);f?b.find("*").addBack().each(function(){var b=a(this);b.is("img:has-src")&&!b.is("[srcset]")&&k.push({src:b.attr("src"),element:b[0]}),a.each(l,function(a,c){var d,e=b.css(c);if(!e)return!0;for(;d=n.exec(e);)k.push({src:d[2],element:b[0]})}),a.each(m,function(a,c){var d=b.attr(c);return!d||void k.push({src:b.attr("src"),srcset:b.attr("srcset"),element:b[0]})})}):b.find("img:has-src").each(function(){k.push({src:this.src,element:this})})}),g=k.length,h=0,0===g&&(d.call(j),i.resolveWith(j)),a.each(k,function(f,k){var l=new Image,m="load."+b+" error."+b;a(l).one(m,function b(c){var f=[h,g,"load"==c.type];if(h++,e.apply(k.element,f),i.notifyWith(k.element,f),a(this).off(m,b),h==g)return d.call(j[0]),i.resolveWith(j[0]),!1}),c&&k.srcset&&(l.srcset=k.srcset,l.sizes=k.sizes),l.src=k.src}),i.promise()}}); \ No newline at end of file +/*! waitForImages jQuery Plugin 2018-02-17 */ +!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){var b="waitForImages",c=function(a){return void 0!==a.srcset&&void 0!==a.sizes}(new Image);a.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage","cursor"],hasImageAttributes:["srcset"]},a.expr.pseudos["has-src"]=function(b){return a(b).is('img[src][src!=""]')},a.expr.pseudos.uncached=function(b){return!!a(b).is(":has-src")&&!b.complete},a.fn.waitForImages=function(){var d,e,f,g=0,h=0,i=a.Deferred(),j=this,k=[],l=a.waitForImages.hasImageProperties||[],m=a.waitForImages.hasImageAttributes||[],n=/url\(\s*(['"]?)(.*?)\1\s*\)/g;if(a.isPlainObject(arguments[0])?(f=arguments[0].waitForAll,e=arguments[0].each,d=arguments[0].finished):1===arguments.length&&"boolean"===a.type(arguments[0])?f=arguments[0]:(d=arguments[0],e=arguments[1],f=arguments[2]),d=d||a.noop,e=e||a.noop,f=!!f,!a.isFunction(d)||!a.isFunction(e))throw new TypeError("An invalid callback was supplied.");return this.each(function(){var b=a(this);f?b.find("*").addBack().each(function(){var b=a(this);b.is("img:has-src")&&!b.is("[srcset]")&&k.push({src:b.attr("src"),element:b[0]}),a.each(l,function(a,c){var d,e=b.css(c);if(!e)return!0;for(;d=n.exec(e);)k.push({src:d[2],element:b[0]})}),a.each(m,function(a,c){var d=b.attr(c);return!d||void k.push({src:b.attr("src"),srcset:b.attr("srcset"),element:b[0]})})}):b.find("img:has-src").each(function(){k.push({src:this.src,element:this})})}),g=k.length,h=0,0===g&&(d.call(j),i.resolveWith(j)),a.each(k,function(f,k){var l=new Image,m="load."+b+" error."+b;a(l).one(m,function b(c){var f=[h,g,"load"==c.type];if(h++,e.apply(k.element,f),i.notifyWith(k.element,f),a(this).off(m,b),h==g)return d.call(j[0]),i.resolveWith(j[0]),!1}),c&&k.element.srcset&&(l.srcset=k.element.srcset,l.sizes=k.element.sizes),l.src=k.src}),i.promise()}}); \ No newline at end of file diff --git a/src/jquery.waitforimages.js b/src/jquery.waitforimages.js index 1652a86..bea53c0 100644 --- a/src/jquery.waitforimages.js +++ b/src/jquery.waitforimages.js @@ -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. @@ -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; });