-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
53 lines (47 loc) · 1.2 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
42
43
44
45
46
47
48
49
50
51
52
53
var NativeProgressEvent = global.ProgressEvent;
var useNative = !!NativeProgressEvent;
try {
(function () {
var p = new NativeProgressEvent('loaded');
useNative = 'loaded' === p.type;
p = null;
})();
} catch (e) {
useNative = false;
}
/**
* Cross-browser `ProgressEvent` constructor.
*
* https://developer.mozilla.org/en-US/docs/Web/API/ProgressEvent.ProgressEvent
*
* @public
*/
module.exports = useNative ? NativeProgressEvent :
// IE >= 9
'function' === typeof document.createEvent ? function ProgressEvent (type, props) {
var e = document.createEvent('Event');
e.initEvent(type, false, false);
if (props) {
e.lengthComputable = Boolean(props.lengthComputable);
e.loaded = Number(props.loaded) || 0;
e.total = Number(props.total) || 0;
} else {
e.lengthComputable = false;
e.loaded = e.total = 0;
}
return e;
} :
// IE <= 8
function ProgressEvent (type, props) {
var e = document.createEventObject();
e.type = type;
if (props) {
e.lengthComputable = Boolean(props.lengthComputable);
e.loaded = Number(props.loaded) || 0;
e.total = Number(props.total) || 0;
} else {
e.lengthComputable = false;
e.loaded = e.total = 0;
}
return e;
}