forked from antimatter15/evm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compat.js
71 lines (63 loc) · 2.5 KB
/
compat.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* this code is from all around the web :)
* if u want to put some credits u are welcome!
*/
var compatibility = (function() {
var lastTime = 0,
isLittleEndian = true,
URL = window.URL || window.webkitURL,
requestAnimationFrame = function(callback, element) {
var requestAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
return requestAnimationFrame.call(window, callback, element);
},
cancelAnimationFrame = function(id) {
var cancelAnimationFrame = window.cancelAnimationFrame ||
function(id) {
clearTimeout(id);
};
return cancelAnimationFrame.call(window, id);
},
getUserMedia = function(options, success, error) {
var getUserMedia =
window.navigator.getUserMedia ||
window.navigator.mozGetUserMedia ||
window.navigator.webkitGetUserMedia ||
window.navigator.msGetUserMedia ||
function(options, success, error) {
error();
};
return getUserMedia.call(window.navigator, options, success, error);
},
detectEndian = function() {
var buf = new ArrayBuffer(8);
var data = new Uint32Array(buf);
data[0] = 0xff000000;
isLittleEndian = true;
if (buf[0] === 0xff) {
isLittleEndian = false;
}
return isLittleEndian;
};
return {
URL: URL,
requestAnimationFrame: requestAnimationFrame,
cancelAnimationFrame: cancelAnimationFrame,
getUserMedia: getUserMedia,
detectEndian: detectEndian,
isLittleEndian: isLittleEndian
};
})();