Added promises to plugin

This commit is contained in:
maverickmishra 2016-09-20 10:36:36 -07:00
parent f881c95e9a
commit 90f5f2531a

View File

@ -1,3 +1,4 @@
cordova.define("cordova-plugin-screen-orientation.screenorientation", function(require, exports, module) {
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
@ -72,12 +73,29 @@
}
screenObject.lockOrientation = function(orientation) {
var p = new Promise(function(resolve,reject){
if (Orientations.indexOf(orientation) == -1) {
console.log('INVALID ORIENTATION', orientation);
return;
// console.log('INVALID ORIENTATION', orientation);
var err = new Error();
err.name = "NotSupportedError";
reject(err);//"cannot change orientation");
}
else {
screenOrientation.currOrientation = screenObject.orientation = orientation;
screenOrientation.setOrientation(orientation);
resolve("Orientation changed"); // orientation change successful
}
});
return p;
};
screenObject.unlockOrientation = function() {
@ -115,3 +133,5 @@
window.addEventListener("orientationchange", orientationChange, true);
module.exports = screenOrientation;
});