Merge pull request #64 from elitan/master

README events example added and orientation naming bug in orientationChange()
This commit is contained in:
Grant Benvenuti 2015-08-10 09:33:36 +10:00
commit 1195b40612
2 changed files with 10 additions and 2 deletions

View File

@ -64,6 +64,12 @@ For this plugin to follow the full API events should be fired on the screen obje
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
window.addEventListener("orientationchange", function(){
console.log('Orientation changed to ' + screen.orientation);
});
## Android Notes ## Android Notes
The __screen.orientation__ property will not update when the phone is [rotated 180 degrees](http://www.quirksmode.org/dom/events/orientationchange.html). The __screen.orientation__ property will not update when the phone is [rotated 180 degrees](http://www.quirksmode.org/dom/events/orientationchange.html).

View File

@ -56,11 +56,13 @@ function addScreenOrientationApi(obj) {
return; return;
} }
screenOrientation.currOrientation = orientation; screenOrientation.currOrientation = orientation;
screen.orientation = screenOrientation.currOrientation;
screenOrientation.setOrientation(orientation); screenOrientation.setOrientation(orientation);
}; };
obj.unlockOrientation = function() { obj.unlockOrientation = function() {
screenOrientation.currOrientation = 'unlocked'; screenOrientation.currOrientation = 'unlocked';
screen.orientation = screenOrientation.currOrientation;
screenOrientation.setOrientation('unlocked'); screenOrientation.setOrientation('unlocked');
}; };
} }
@ -76,13 +78,13 @@ function orientationChange() {
orientation = 'portrait-primary'; orientation = 'portrait-primary';
break; break;
case 90: case 90:
orientation = 'landscape-secondary'; orientation = 'landscape-primary';
break; break;
case 180: case 180:
orientation = 'portrait-secondary'; orientation = 'portrait-secondary';
break; break;
case -90: case -90:
orientation = 'landscape-primary'; orientation = 'landscape-secondary';
break; break;
default: default:
orientation = 'unknown'; orientation = 'unknown';