added comments and formatted code

This commit is contained in:
maverickmishra 2016-10-17 11:12:53 -07:00
parent 90f5f2531a
commit 84b013f17c

View File

@ -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;
} }
@ -76,7 +78,6 @@ cordova.define("cordova-plugin-screen-orientation.screenorientation", function(r
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";
@ -86,12 +87,8 @@ cordova.define("cordova-plugin-screen-orientation.screenorientation", function(r
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;