1 | var exec = require('cordova/exec'),
|
2 | screenOrientation = {},
|
3 | iosOrientation = 'unlocked',
|
4 | orientationMap = {
|
5 | 'portrait': [0,180],
|
6 | 'portrait-primary': [0],
|
7 | 'portrait-secondary': [180],
|
8 | 'landscape': [-90,90],
|
9 | 'landscape-primary': [-90],
|
10 | 'landscape-secondary': [90],
|
11 | 'default': [-90,90,0]
|
12 | };
|
13 |
|
14 | screenOrientation.setOrientation = function(orientation) {
|
15 | iosOrientation = orientation;
|
16 |
|
17 | var success = function(res) {
|
18 | if (orientation === 'unlocked' && res.device) {
|
19 | iosOrientation = res.device;
|
20 | setTimeout(function() {
|
21 | iosOrientation = 'unlocked';
|
22 | },300);
|
23 | }
|
24 | };
|
25 |
|
26 | exec(success, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
27 | };
|
28 |
|
29 | module.exports = screenOrientation;
|
30 |
|
31 |
|
32 | window.shouldRotateToOrientation = function(orientation) {
|
33 | var map = orientationMap[iosOrientation] || orientationMap['default'];
|
34 | return map.indexOf(orientation) >= 0;
|
35 | };
|