From 479c32b67cd0dc820412cad3a0eaf77b2e8ba69c Mon Sep 17 00:00:00 2001 From: Moritz Date: Tue, 8 Dec 2015 18:14:57 +0100 Subject: [PATCH] Add more readability --- README.md | 72 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 510d8bd..10dcf7c 100644 --- a/README.md +++ b/README.md @@ -2,73 +2,81 @@ Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of [Screen Orientation API](http://www.w3.org/TR/screen-orientation/) so the api does not currently match the current spec. -The plugin adds the following to the screen object: +The plugin adds the following to the screen object (`window.screen`): -__lockOrientation(ORIENTATION_STRING)__ -lock the device orientation +```js +// lock the device orientation +.lockOrientation('portrait') -__unlockOrientation()__ -unlock the orientation +// unlock the orientation +.unlockOrientation() -__orientation__ -current orientation (ORIENTATION_STRING) +// current orientation +.orientation +``` ## Install -cordova < 4 +_cordova < 4_ +```bash cordova plugin add net.yoik.cordova.plugins.screenorientation +``` +_cordova > 4_ -cordova > 4 - +```bash cordova plugin add cordova-plugin-screen-orientation +``` ## Supported Orientations -__portrait-primary__ -The orientation is in the primary portrait mode. +#### portrait-primary +> The orientation is in the primary portrait mode. -__portrait-secondary__ -The orientation is in the secondary portrait mode. +#### portrait-secondary +> The orientation is in the secondary portrait mode. -__landscape-primary__ -The orientation is in the primary landscape mode. +#### landscape-primary +> The orientation is in the primary landscape mode. -__landscape-secondary__ -The orientation is in the secondary landscape mode. +#### landscape-secondary +> The orientation is in the secondary landscape mode. -__portrait__ -The orientation is either portrait-primary or portrait-secondary (sensor). +#### portrait +> The orientation is either portrait-primary or portrait-secondary (sensor). -__landscape__ -The orientation is either landscape-primary or landscape-secondary (sensor). +#### landscape +> The orientation is either landscape-primary or landscape-secondary (sensor). ## Usage - // set to either landscape - screen.lockOrientation('landscape'); +```js +// set to either landscape +screen.lockOrientation('landscape'); - // allow user rotate - screen.unlockOrientation(); +// allow user rotate +screen.unlockOrientation(); - // access current orientation - console.log('Orientation is ' + screen.orientation); +// access current orientation +console.log('Orientation is ' + screen.orientation); +``` ## Events Both android and iOS will fire the orientationchange event on the window object. For this version of the plugin use the window object if you require notification. - For this plugin to follow the full API events should be fired on the screen object. iOS and BB10 do not currently support events on the _screen_ object so custom event handling will need to be added (Suggestions welcome!). ### Example usage - window.addEventListener("orientationchange", function(){ - console.log('Orientation changed to ' + screen.orientation); - }); +```js +window.addEventListener("orientationchange", function(){ + console.log(screen.orientation); // e.g. portrait +}); +``` ## Android Notes