You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2016/12/13 23:48:41 UTC
[13/16] cordova-plugin-screen-orientation git commit: cleaned up js,
fixed whitespace
cleaned up js, fixed whitespace
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/commit/216b99f4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/tree/216b99f4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/diff/216b99f4
Branch: refs/heads/master
Commit: 216b99f432feaf2a9b278f72d8730bca292661da
Parents: b7e5477
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Dec 13 15:39:58 2016 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Dec 13 15:39:58 2016 -0800
----------------------------------------------------------------------
www/screenorientation.js | 186 +++++++++++++++++++-----------------------
1 file changed, 86 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/blob/216b99f4/www/screenorientation.js
----------------------------------------------------------------------
diff --git a/www/screenorientation.js b/www/screenorientation.js
index d574faa..d24a48c 100644
--- a/www/screenorientation.js
+++ b/www/screenorientation.js
@@ -1,4 +1,3 @@
-cordova.define("cordova-plugin-screen-orientation.screenorientation", function(require, exports, module) {
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -20,115 +19,102 @@ cordova.define("cordova-plugin-screen-orientation.screenorientation", function(r
*
*/
- var screenOrientation = {},
- Orientations = [
- 'portrait-primary',
- // The orientation is in the primary portrait mode.
- 'portrait-secondary',
- // The orientation is in the secondary portrait mode.
- 'landscape-primary',
- // The orientation is in the primary landscape mode.
- 'landscape-secondary',
- // The orientation is in the secondary landscape mode.
- 'portrait',
- // The orientation is either portrait-primary or portrait-secondary.
- 'landscape',
- // The orientation is either landscape-primary or landscape-secondary.
- 'any'
- // All orientations are supported (unlocked orientation)
- ];
+var screenOrientation = {},
+ Orientations = [
+ 'portrait-primary',
+ 'portrait-secondary',
+ 'landscape-primary',
+ 'landscape-secondary',
+ 'portrait', // either portrait-primary or portrait-secondary.
+ 'landscape', // either landscape-primary or landscape-secondary.
+ 'any' // All orientations are supported (unlocked orientation)
+ ];
- screenOrientation.Orientations = Orientations;
- screenOrientation.currOrientation = 'any';
- var orientationMask = 0;
- screenOrientation.setOrientation = function(orientation) {
- if(orientation == Orientations[0]){
- orientationMask = 1;
- }
- else if(orientation == Orientations[1]){
- orientationMask = 2;
- }
- else if(orientation == Orientations[2]){
- orientationMask = 4;
- }
- else if(orientation == Orientations[3]){
- orientationMask = 8;
- }
- else if(orientation == Orientations[4]){
- orientationMask = 3;
- }
- else if(orientation == Orientations[5]){
- orientationMask = 12;
- }
- else if(orientation == Orientations[6]){
- orientationMask = 15;
- }
+screenOrientation.Orientations = Orientations;
+screenOrientation.currOrientation = 'any';
+var orientationMask = 0;
+screenOrientation.setOrientation = function(orientation) {
+ if(orientation == Orientations[0]){
+ orientationMask = 1;
+ }
+ else if(orientation == Orientations[1]){
+ orientationMask = 2;
+ }
+ else if(orientation == Orientations[2]){
+ orientationMask = 4;
+ }
+ else if(orientation == Orientations[3]){
+ orientationMask = 8;
+ }
+ else if(orientation == Orientations[4]){
+ orientationMask = 3;
+ }
+ else if(orientation == Orientations[5]){
+ orientationMask = 12;
+ }
+ else if(orientation == Orientations[6]){
+ orientationMask = 15;
+ }
- cordova.exec(null, null, "CDVOrientation", "screenOrientation", [orientationMask, orientation]);
- //console.log('setOrientation not supported on device');
- };
+ cordova.exec(null, null, "CDVOrientation", "screenOrientation", [orientationMask, orientation]);
+ //console.log('setOrientation not supported on device');
+};
- function addScreenOrientationApi(screenObject) {
- if (screenObject.unlockOrientation || screenObject.lockOrientation) {
- return;
- }
+function addScreenOrientationApi(screenObject) {
+ if (screenObject.unlockOrientation || screenObject.lockOrientation) {
+ return;
+ }
- screenObject.lockOrientation = function(orientation) {
-
- var p = new Promise(function(resolve,reject){
- if (Orientations.indexOf(orientation) == -1) {
- var err = new Error();
- err.name = "NotSupportedError";
-
- reject(err);//"cannot change orientation");
-
- }
- else {
- screenOrientation.currOrientation = screenObject.orientation = orientation;
- screenOrientation.setOrientation(orientation);
- resolve("Orientation set"); // orientation change successful
- }
- });
- return p;
-
-
- };
+ screenObject.lockOrientation = function(orientation) {
- screenObject.unlockOrientation = function() {
- screenOrientation.currOrientation = screenObject.orientation = 'any';
- screenOrientation.setOrientation('any');
- };
- }
+ var p = new Promise(function(resolve,reject){
+ if (Orientations.indexOf(orientation) == -1) {
+ var err = new Error();
+ err.name = "NotSupportedError";
+ reject(err);//"cannot change orientation");
+ }
+ else {
+ screenOrientation.currOrientation = screenObject.orientation = orientation;
+ screenOrientation.setOrientation(orientation);
+ resolve("Orientation set"); // orientation change successful
+ }
+ });
+ return p;
+ };
- addScreenOrientationApi(screen);
- orientationChange();
+ screenObject.unlockOrientation = function() {
+ screenOrientation.currOrientation = screenObject.orientation = 'any';
+ screenOrientation.setOrientation('any');
+ };
+}
- function orientationChange() {
- var orientation;
+addScreenOrientationApi(screen);
+orientationChange();
- switch (window.orientation) {
- case 0:
- orientation = 'portrait-primary';
- break;
- case 90:
- orientation = 'landscape-primary';
- break;
- case 180:
- orientation = 'portrait-secondary';
- break;
- case -90:
- orientation = 'landscape-secondary';
- break;
- default:
- orientation = 'any';
- }
+function orientationChange() {
+ var orientation;
- screen.orientation = orientation;
- }
+ switch (window.orientation) {
+ case 0:
+ orientation = 'portrait-primary';
+ break;
+ case 90:
+ orientation = 'landscape-primary';
+ break;
+ case 180:
+ orientation = 'portrait-secondary';
+ break;
+ case -90:
+ orientation = 'landscape-secondary';
+ break;
+ default:
+ orientation = 'any';
+ }
- window.addEventListener("orientationchange", orientationChange, true);
+ screen.orientation = orientation;
+}
- module.exports = screenOrientation;
+window.addEventListener("orientationchange", orientationChange, true);
-});
+module.exports = screenOrientation;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org