-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (43 loc) · 1.29 KB
/
index.js
File metadata and controls
52 lines (43 loc) · 1.29 KB
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
function DeviceOrientation () {
this.value = null
var self = this
var supportOrientation = (typeof window.orientation == "number" && typeof window.onorientationchange == "object");
var updateOrientation = function () {
if (supportOrientation) {
updateOrientation = function () {
var orientation = window.orientation;
switch (orientation) {
case 90:
case -90:
orientation = "landscape";
break;
default:
orientation = "portrait";
}
self.value = orientation
self.onChange.call(null, orientation)
};
} else {
updateOrientation = function () {
var orientation = (window.innerWidth > window.innerHeight) ? "landscape" : "portrait";
if (orientation !== self.value) {
self.value = orientation
self.onChange.call(null, orientation)
}
};
}
updateOrientation();
};
var init = function () {
updateOrientation();
if (supportOrientation) {
window.addEventListener("orientationchange", updateOrientation, false);
} else {
window.setInterval(updateOrientation, 0);
}
};
init()
}
DeviceOrientation.prototype.onChange = function () {
}
module.exports = window.DeviceOrientation = DeviceOrientation