From 7c86844895fcf9f10e88733b5b9ea7b885d1919d Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Tue, 2 Sep 2014 18:30:58 +1000 Subject: [PATCH] Cleaned up messy switch/if block in iOS js file. --- www/screenorientation.ios.js | 38 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index eb6d6da..c155aa1 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -9,29 +9,17 @@ module.exports = screenOrientation; // ios orientation callback/hook window.shouldRotateToOrientation = function(orientation) { - var currOrientation = cordova.plugins.screenorientation.currOrientation; - switch (currOrientation) { - case 'portrait': - if (orientation === 0 || orientation === 180) return true; - break; - case 'portrait-primary': - if (orientation === 0) return true; - break; - case 'portrait-secondary': - if (orientation === 180) return true; - break; - case 'landscape': - if (orientation === -90 || orientation === 90) return true; - break; - case 'landscape-primary': - if (orientation === -90) return true; - break; - case 'landscape-secondary': - if (orientation === 90) return true; - break; - default: - if (orientation === -90 || orientation === 90 || orientation === 0) return true; - break; - } - return false; + var currOrientation = cordova.plugins.screenorientation.currOrientation, + orientationMap = { + 'portrait': [0,180], + 'portrait-primary': [0], + 'portrait-secondary': [180], + 'landscape': [-90,90], + 'landscape-primary': [-90], + 'landscape-secondary': [90], + 'default': [-90,90,0] + }, + map = orientationMap[currOrientation] || orientationMap['default']; + + return map.indexOf(orientation) >= 0; };