-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.dynload.js
More file actions
44 lines (38 loc) · 905 Bytes
/
jquery.dynload.js
File metadata and controls
44 lines (38 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
dynload
version : 0.1
Author: hackerone (https://github.com/hackerone)
Copyright (C) 2013 hackerone
Licensed under the MIT license (MIT)
checks if the specified container and images (if any) inside it are is loaded.
*/
(function($, window){
$.fn.dynload = function(callback){
var images = $('img', this);
var totalImages = images.length;
var counter = 0;
$.fn.dynLoad.defaults = {
loadCompleteCallback: callback,
}
var opts = $.extend({}, $.fn.dynLoad.defaults, callback);
var imgLoaded = function(){
counter++;
if(counter == totalImages){
callback();
}
}
if(totalImages == 0)callback();
else{
images.each(function(i,e){
var w = $(this).width();
if(w){
imgLoaded();
}else{
$(this).load(function(){
imgLoaded();
});
}
});
}
}
})(jQuery, window);