Add more readability

This commit is contained in:
Moritz 2015-12-08 18:14:57 +01:00
parent bbde995383
commit 479c32b67c

View File

@ -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. 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)__ ```js
lock the device orientation // lock the device orientation
.lockOrientation('portrait')
__unlockOrientation()__ // unlock the orientation
unlock the orientation .unlockOrientation()
__orientation__ // current orientation
current orientation (ORIENTATION_STRING) .orientation
```
## Install ## Install
cordova < 4 _cordova < 4_
```bash
cordova plugin add net.yoik.cordova.plugins.screenorientation cordova plugin add net.yoik.cordova.plugins.screenorientation
```
_cordova > 4_
cordova > 4 ```bash
cordova plugin add cordova-plugin-screen-orientation cordova plugin add cordova-plugin-screen-orientation
```
## Supported Orientations ## Supported Orientations
__portrait-primary__ #### portrait-primary
The orientation is in the primary portrait mode. > The orientation is in the primary portrait mode.
__portrait-secondary__ #### portrait-secondary
The orientation is in the secondary portrait mode. > The orientation is in the secondary portrait mode.
__landscape-primary__ #### landscape-primary
The orientation is in the primary landscape mode. > The orientation is in the primary landscape mode.
__landscape-secondary__ #### landscape-secondary
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 (sensor). > The orientation is either portrait-primary or portrait-secondary (sensor).
__landscape__ #### landscape
The orientation is either landscape-primary or landscape-secondary (sensor). > The orientation is either landscape-primary or landscape-secondary (sensor).
## Usage ## Usage
// set to either landscape ```js
screen.lockOrientation('landscape'); // set to either landscape
screen.lockOrientation('landscape');
// allow user rotate // allow user rotate
screen.unlockOrientation(); screen.unlockOrientation();
// access current orientation // access current orientation
console.log('Orientation is ' + screen.orientation); console.log('Orientation is ' + screen.orientation);
```
## Events ## Events
Both android and iOS will fire the orientationchange event on the window object. 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 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. 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 iOS and BB10 do not currently support events on the _screen_ object so custom event
handling will need to be added (Suggestions welcome!). handling will need to be added (Suggestions welcome!).
### Example usage ### Example usage
window.addEventListener("orientationchange", function(){ ```js
console.log('Orientation changed to ' + screen.orientation); window.addEventListener("orientationchange", function(){
}); console.log(screen.orientation); // e.g. portrait
});
```
## Android Notes ## Android Notes