mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
added comments and formatted code
This commit is contained in:
parent
90f5f2531a
commit
84b013f17c
@ -32,33 +32,35 @@ cordova.define("cordova-plugin-screen-orientation.screenorientation", function(r
|
|||||||
// The orientation is in the secondary landscape mode.
|
// The orientation is in the secondary landscape mode.
|
||||||
'portrait',
|
'portrait',
|
||||||
// The orientation is either portrait-primary or portrait-secondary.
|
// The orientation is either portrait-primary or portrait-secondary.
|
||||||
'landscape'
|
'landscape',
|
||||||
// The orientation is either landscape-primary or landscape-secondary.
|
// The orientation is either landscape-primary or landscape-secondary.
|
||||||
|
'any'
|
||||||
|
// All orientations are supported
|
||||||
];
|
];
|
||||||
|
|
||||||
screenOrientation.Orientations = Orientations;
|
screenOrientation.Orientations = Orientations;
|
||||||
screenOrientation.currOrientation = 'any';
|
screenOrientation.currOrientation = 'any';
|
||||||
var orientationMask = 0;
|
var orientationMask = 0;
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
screenOrientation.setOrientation = function(orientation) {
|
||||||
if(orientation == 'portrait-primary'){
|
if(orientation == Orientations[0]){
|
||||||
orientationMask = 1;
|
orientationMask = 1;
|
||||||
}
|
}
|
||||||
else if(orientation == 'portrait-secondary'){
|
else if(orientation == Orientations[1]){
|
||||||
orientationMask = 2;
|
orientationMask = 2;
|
||||||
}
|
}
|
||||||
else if(orientation == 'landscape-primary'){
|
else if(orientation == Orientations[2]){
|
||||||
orientationMask = 4;
|
orientationMask = 4;
|
||||||
}
|
}
|
||||||
else if(orientation == 'landscape-secondary'){
|
else if(orientation == Orientations[3]){
|
||||||
orientationMask = 8;
|
orientationMask = 8;
|
||||||
}
|
}
|
||||||
else if(orientation == 'portrait'){
|
else if(orientation == Orientations[4]){
|
||||||
orientationMask = 3;
|
orientationMask = 3;
|
||||||
}
|
}
|
||||||
else if(orientation == 'landscape'){
|
else if(orientation == Orientations[5]){
|
||||||
orientationMask = 12;
|
orientationMask = 12;
|
||||||
}
|
}
|
||||||
else if(orientation == 'any'){
|
else if(orientation == Orientations[6]){
|
||||||
orientationMask = 15;
|
orientationMask = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,29 +75,24 @@ cordova.define("cordova-plugin-screen-orientation.screenorientation", function(r
|
|||||||
}
|
}
|
||||||
|
|
||||||
screenObject.lockOrientation = function(orientation) {
|
screenObject.lockOrientation = function(orientation) {
|
||||||
|
|
||||||
var p = new Promise(function(resolve,reject){
|
var p = new Promise(function(resolve,reject){
|
||||||
if (Orientations.indexOf(orientation) == -1) {
|
if (Orientations.indexOf(orientation) == -1) {
|
||||||
// console.log('INVALID ORIENTATION', orientation);
|
|
||||||
var err = new Error();
|
var err = new Error();
|
||||||
err.name = "NotSupportedError";
|
err.name = "NotSupportedError";
|
||||||
|
|
||||||
reject(err);//"cannot change orientation");
|
reject(err);//"cannot change orientation");
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
screenOrientation.currOrientation = screenObject.orientation = orientation;
|
screenOrientation.currOrientation = screenObject.orientation = orientation;
|
||||||
screenOrientation.setOrientation(orientation);
|
screenOrientation.setOrientation(orientation);
|
||||||
resolve("Orientation changed"); // orientation change successful
|
resolve("Orientation set"); // orientation change successful
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
screenObject.unlockOrientation = function() {
|
screenObject.unlockOrientation = function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user