monitor-dashboard/src/assets/theme-assets/js/custom/jquery.waitforimages.min.js

1 line
1.8 KiB
JavaScript
Executable File

!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):e(jQuery)}(function(m){var e,p="waitForImages",g=(e=new Image).srcset&&e.sizes;m.waitForImages={hasImageProperties:["backgroundImage","listStyleImage","borderImage","borderCornerImage","cursor"],hasImageAttributes:["srcset"]},m.expr[":"]["has-src"]=function(e){return m(e).is('img[src][src!=""]')},m.expr[":"].uncached=function(e){return!!m(e).is(":has-src")&&!e.complete},m.fn.waitForImages=function(){var n,a,c,r,o=0,u=m.Deferred(),h=this,f=[],s=m.waitForImages.hasImageProperties||[],t=m.waitForImages.hasImageAttributes||[],l=/url\(\s*(['"]?)(.*?)\1\s*\)/g;if(m.isPlainObject(arguments[0])?(r=arguments[0].waitForAll,c=arguments[0].each,a=arguments[0].finished):r=1===arguments.length&&"boolean"===m.type(arguments[0])?arguments[0]:(a=arguments[0],c=arguments[1],arguments[2]),a=a||m.noop,c=c||m.noop,r=!!r,!m.isFunction(a)||!m.isFunction(c))throw new TypeError("An invalid callback was supplied.");return this.each(function(){var e=m(this);r?e.find("*").addBack().each(function(){var i=m(this);i.is("img:has-src")&&!i.is("[srcset]")&&f.push({src:i.attr("src"),element:i[0]}),m.each(s,function(e,r){var s,t=i.css(r);if(!t)return!0;for(;s=l.exec(t);)f.push({src:s[2],element:i[0]})}),m.each(t,function(e,r){if(!i.attr(r))return!0;f.push({src:i.attr("src"),srcset:i.attr("srcset"),element:i[0]})})}):e.find("img:has-src").each(function(){f.push({src:this.src,element:this})})}),n=f.length,(o=0)===n&&(a.call(h),u.resolveWith(h)),m.each(f,function(e,t){var r=new Image,i="load."+p+" error."+p;m(r).one(i,function e(r){var s=[o,n,"load"==r.type];if(o++,c.apply(t.element,s),u.notifyWith(t.element,s),m(this).off(i,e),o==n)return a.call(h[0]),u.resolveWith(h[0]),!1}),g&&t.srcset&&(r.srcset=t.srcset,r.sizes=t.sizes),r.src=t.src}),u.promise()}});