-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
41 lines (33 loc) · 1.02 KB
/
index.js
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
/*
* Modified version of http://github.com/desandro/imagesloaded v2.1.1
* MIT License. by Paul Irish et al.
*/
var BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=='
function loaded(image, callback) {
var src
, old
, onload
if (!image.nodeName) return callback(new Error('First argument must be an image element'))
if (image.nodeName.toLowerCase() !== 'img') return callback(new Error('Element supplied is not an image'))
if (image.src && image.complete && image.naturalWidth !== undefined) return callback(null, true)
old = !image.addEventListener
function loaded() {
if (old) {
image.detachEvent('onload', loaded)
} else {
image.removeEventListener('load', loaded, false)
}
callback(null, false)
}
if (old) {
image.attachEvent('onload', loaded)
} else {
image.addEventListener('load', loaded, false)
}
if (image.readyState || image.complete) {
src = image.src
image.src = BLANK
image.src = src
}
}
module.exports = loaded