diff --git a/demo/app/www/js/controllers.js b/demo/app/www/js/controllers.js index 9e0ccbb0..76a24788 100644 --- a/demo/app/www/js/controllers.js +++ b/demo/app/www/js/controllers.js @@ -36,7 +36,9 @@ angular.module('starter.controllers', []) }) .controller('GeolocationCtrl', function($scope, $cordovaGeolocation) { - $cordovaGeolocation.watchPosition().then(function(resp) { + $cordovaGeolocation.watchPosition({ + frequency: 100 + }).promise.then(function(resp) { }, function(err) { }, function(position) { $scope.lat = position.coords.latitude; @@ -45,7 +47,7 @@ angular.module('starter.controllers', []) $scope.getLatLng = function() { if(!$scope.lat && !$scope.lng) { return '45.787, -89.052'; } - return $scope.lat.toFixed(3) + ', ' + $scope.lng.toFixed(3); + return $scope.lat.toFixed(7) + ', ' + $scope.lng.toFixed(7); } /* $scope.toggleTrack = function() { @@ -60,7 +62,9 @@ angular.module('starter.controllers', []) }) .controller('CompassCtrl', function($scope, $cordovaDeviceOrientation) { - $cordovaDeviceOrientation.watchHeading().then(function(resp) { + $cordovaDeviceOrientation.watchHeading({ + frequency: 100 + }).promise.then(function(resp) { }, function(err) { }, function(position) { $scope.compass = position.magneticHeading; @@ -160,13 +164,15 @@ angular.module('starter.controllers', []) } }) -.controller('AccelCtrl', function($scope, $cordovaAccelerometer) { +.controller('AccelCtrl', function($scope, $cordovaDeviceMotion) { console.log('Accel'); $scope.toggleTrack = function() { - $cordovaAccelerometer.watchAcceleration().then(function(resp) { + console.log('Accel tracking'); + $cordovaDeviceMotion.watchAcceleration({ + frequency: 100 + }).promise.then(function(resp) { }, function(err) { }, function(data) { - console.log('Data', data) $scope.x = data.x; $scope.y = data.y; $scope.z = data.z; diff --git a/demo/app/www/lib/ngCordova/ng-cordova.js b/demo/app/www/lib/ngCordova/ng-cordova.js index ca478c4f..721fe60e 100644 --- a/demo/app/www/lib/ngCordova/ng-cordova.js +++ b/demo/app/www/lib/ngCordova/ng-cordova.js @@ -286,14 +286,18 @@ angular.module('ngCordova.plugins.deviceMotion', []) watchAcceleration: function(options) { var q = $q.defer(); - navigator.accelerometer.watchAcceleration(function(result) { + var watchId = navigator.accelerometer.watchAcceleration(function(result) { // Do any magic you need + //q.resolve(watchID); q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { return navigator.accelerometer.clearWatch(watchID); @@ -306,16 +310,33 @@ angular.module('ngCordova.plugins.deviceOrientation', []) .factory('$cordovaDeviceOrientation', ['$q', function($q) { return { + getCurrentHeading: function() { + var q = $q.defer(); + + navigator.compass.getCurrentHeading(function(heading) { + q.resolve(heading); + }, function(err) { + q.reject(err); + }); + + return q.promise; + }, watchHeading: function(options) { var q = $q.defer(); - navigator.compass.watchHeading(function(result) { + var watchId = navigator.compass.watchHeading(function(result) { q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } + }, + clearWatch: function(watchID) { + navigator.compass.clearWatch(); } } }]); @@ -389,12 +410,17 @@ angular.module('ngCordova.plugins.file', []) ); }, - checkFile: function (dir, file) { + checkFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function checkFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, // File exists function () { q.resolve(); @@ -410,10 +436,16 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - createFile: function (dir, file, replaceBOOL) { + createFile: function (filePath, replaceBOOL) { + // Backward compatibility for previous function createFile(dir, file, replaceBOOL) + if (arguments.length == 3) { + filePath = '/' + filePath + '/' + arguments[1]; + replaceBOOL = arguments[2]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: true, exclusive: replaceBOOL}, + filesystem.root.getFile(filePath, {create: true, exclusive: replaceBOOL}, function (success) { }, @@ -424,12 +456,17 @@ angular.module('ngCordova.plugins.file', []) ); }, - removeFile: function (dir, file) { + removeFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function removeFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, function (fileEntry) { + filesystem.root.getFile(filePath, {create: false}, function (fileEntry) { fileEntry.remove(function () { q.resolve(); }); @@ -440,12 +477,17 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - writeFile: function (dir, file) { + writeFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function writeFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, function (fileEntry) { fileEntry.createWriter( function (fileWriter) { @@ -462,13 +504,18 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - readFile: function (dir, file) { + readFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function readFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, // success function (fileEntry) { fileEntry.file(function (file) { @@ -490,16 +537,35 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, + readFileMetadata: function (filePath) { + var q = $q.defer(); + + getFilesystem().then( + function (filesystem) { + filesystem.root.getFile(filePath, {create: false}, + // success + function (fileEntry) { + fileEntry.file(function (file) { + q.resolve(file); + }); + }, + // error + function (error) { + q.reject(error); + }); + } + ); + + return q.promise; + }, + downloadFile: function (source, filePath, trustAllHosts, options) { var q = $q.defer(); var fileTransfer = new FileTransfer(); var uri = encodeURI(source); fileTransfer.onprogress = function(progressEvent) { - if (progressEvent.lengthComputable) { - var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); - q.notify(perc); - } + q.notify(progressEvent); }; fileTransfer.download( @@ -522,10 +588,7 @@ angular.module('ngCordova.plugins.file', []) var uri = encodeURI(server); fileTransfer.onprogress = function(progressEvent) { - if (progressEvent.lengthComputable) { - var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); - q.notify(perc); - } + q.notify(progressEvent); }; fileTransfer.upload( @@ -557,6 +620,41 @@ angular.module('ngCordova.plugins.file', []) return q.promise; } }]); +angular.module('ngCordova.plugins.flashlight', []) + +.factory('$cordovaFlashlight', ['$q', function ($q) { + + return { + available: function () { + var q = $q.defer(); + window.plugins.flashlight.available(function (isAvailable) { + q.resolve(isAvailable); + }); + return q.promise; + }, + + switchOn: function () { + var q = $q.defer(); + window.plugins.flashlight.switchOn(function (response) { + q.resolve(response); + }, function (error) { + q.reject(error) + }); + return q.promise; + }, + + switchOff: function () { + var q = $q.defer(); + window.plugins.flashlight.switchOff(function (response) { + q.resolve(response); + }, function (error) { + q.reject(error) + }); + return q.promise; + } + } + } +]); angular.module('ngCordova.plugins.ga', []) .factory('$cordovaGA', ['$q', function ($q) { @@ -626,7 +724,7 @@ angular.module('ngCordova.plugins.geolocation', []) watchPosition: function(options) { var q = $q.defer(); - navigator.geolocation.watchPosition(function(result) { + var watchId = navigator.geolocation.watchPosition(function(result) { // Do any magic you need q.notify(result); @@ -634,7 +732,10 @@ angular.module('ngCordova.plugins.geolocation', []) q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { @@ -856,6 +957,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.pinDialog', 'ngCordova.plugins.localNotification', 'ngCordova.plugins.toast', + 'ngCordova.plugins.flashlight', 'ngCordova.plugins.capture', 'ngCordova.plugins.appAvailability', 'ngCordova.plugins.prefs' diff --git a/demo/app/www/lib/ngCordova/ng-cordova.min.js b/demo/app/www/lib/ngCordova/ng-cordova.min.js index fef96219..01e28cd4 100644 --- a/demo/app/www/lib/ngCordova/ng-cordova.min.js +++ b/demo/app/www/lib/ngCordova/ng-cordova.min.js @@ -1 +1 @@ -!function(){angular.module("ngCordova",["ngCordova.plugins"]),angular.module("ngCordova.plugins.appAvailability",[]).factory("$cordovaAppAvailability",["$q",function(n){return{check:function(e){var o=n.defer();return appAvailability.check(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise}}}]),angular.module("ngCordova.plugins.barcodeScanner",[]).factory("$cordovaBarcodeScanner",["$q",function(n){return{scan:function(){var e=n.defer();return cordova.plugins.barcodeScanner.scan(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},encode:function(e,o){var r=n.defer();return cordova.plugins.barcodeScanner.encode(e,o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.camera",[]).factory("$cordovaCamera",["$q",function(n){return{getPicture:function(e){var o=n.defer();return navigator.camera?(navigator.camera.getPicture(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},cleanup:function(){var e=n.defer();return navigator.camera.cleanup(function(){e.resolve(arguments)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.capture",[]).factory("$cordovaCapture",["$q",function(n){return{captureAudio:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureAudio(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureImage:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureImage(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureVideo:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureVideo(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)}}}]),angular.module("ngCordova.plugins.contacts",[]).factory("$cordovaContacts",["$q",function(n){return{save:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.save(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},remove:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.remove(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},clone:function(n){var e=navigator.contacts.create(n);return e.clone(n)},find:function(e){var o=n.defer(),r=e.fields||["id","displayName"];return delete e.fields,navigator.contacts.find(r,function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.device",[]).factory("$cordovaDevice",[function(){return{getDevice:function(){return device},getCordova:function(){return device.cordova},getModel:function(){return device.model},getName:function(){return device.name},getPlatform:function(){return device.platform},getUUID:function(){return device.uuid},getVersion:function(){return device.version}}}]),angular.module("ngCordova.plugins.deviceMotion",[]).factory("$cordovaDeviceMotion",["$q",function(n){return{getCurrentAcceleration:function(){var e=n.defer();return navigator.accelerometer.getCurrentAcceleration(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchAcceleration:function(e){var o=n.defer();return navigator.accelerometer.watchAcceleration(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise},clearWatch:function(n){return navigator.accelerometer.clearWatch(n)}}}]),angular.module("ngCordova.plugins.deviceOrientation",[]).factory("$cordovaDeviceOrientation",["$q",function(n){return{watchHeading:function(e){var o=n.defer();return navigator.compass.watchHeading(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.dialogs",[]).factory("$cordovaDialogs",[function(){return{alert:function(){return navigator.notification.alert.apply(navigator.notification,arguments)},confirm:function(){return navigator.notification.confirm.apply(navigator.notification,arguments)},prompt:function(){return navigator.notification.prompt.apply(navigator.notification,arguments)},beep:function(n){return navigator.notification.beep(n)}}}]),angular.module("ngCordova.plugins.file",[]).factory("$cordovaFile",["$q",function(n){function e(){var e=n.defer();return window.requestFileSystem(LocalFileSystem.PERSISTENT,1048576,function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}return{checkDir:function(o){var r=n.defer();return e().then(function(n){n.root.getDirectory(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createDir:function(n,o){e().then(function(e){e.root.getDirectory(n,{create:!0,exclusive:o})})},checkFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(){t.resolve()},function(){t.reject()})}),t.promise},createFile:function(n,o,r){e().then(function(e){e.root.getFile("/"+n+"/"+o,{create:!0,exclusive:r},function(){},function(){})})},removeFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.remove(function(){t.resolve()})})}),t.promise},writeFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.createWriter(function(n){t.resolve(n)},function(n){t.reject(n)})})}),t.promise},readFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.file(function(n){var e=new FileReader;e.onloadend=function(){t.resolve(this.result)},e.readAsText(n)})},function(n){t.reject(n)})}),t.promise},downloadFile:function(e,o,r,t){var i=n.defer(),a=new FileTransfer,c=encodeURI(e);return a.onprogress=function(n){if(n.lengthComputable){var e=Math.floor(n.loaded/n.total*100);i.notify(e)}},a.download(c,o,function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},uploadFile:function(e,o,r){var t=n.defer(),i=new FileTransfer,a=encodeURI(e);return i.onprogress=function(n){if(n.lengthComputable){var e=Math.floor(n.loaded/n.total*100);t.notify(e)}},i.upload(o,a,function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise}}}]),angular.module("ngCordova.plugins.ga",[]).factory("$cordovaGA",["$q",function(n){return{init:function(e,o){var r=n.defer();return o=o>=0?o:10,window.plugins.gaPlugin.init(function(n){r.resolve(n)},function(n){r.reject(n)},e,o),r.promise},trackEvent:function(e,o,r,t,i,a){var c=n.defer();return window.plugins.gaPlugin.trackEvent(function(n){c.resolve(n)},function(n){c.reject(n)},r,t,i,a),c.promise},trackPage:function(e,o,r){var t=n.defer();return window.plugins.gaPlugin.trackPage(function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise},setVariable:function(e,o,r,t){var i=n.defer();return window.plugins.gaPlugin.setVariable(function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},exit:function(){var e=n.defer();return window.plugins.gaPlugin.exit(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.geolocation",[]).factory("$cordovaGeolocation",["$q",function(n){return{getCurrentPosition:function(e){var o=n.defer();return navigator.geolocation.getCurrentPosition(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},watchPosition:function(e){var o=n.defer();return navigator.geolocation.watchPosition(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise},clearWatch:function(n){return navigator.geolocation.clearWatch(n)}}}]),angular.module("ngCordova.plugins.globalization",[]).factory("$cordovaGlobalization",["$q",function(n){return{getPreferredLanguage:function(){var e=n.defer();return navigator.globalization.getPreferredLanguage(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getLocaleName:function(){var e=n.defer();return navigator.globalization.getLocaleName(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getFirstDayOfWeek:function(){var e=n.defer();return navigator.globalization.getFirstDayOfWeek(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.keyboard",[]).factory("$cordovaKeyboard",[function(){return{hideAccessoryBar:function(n){return cordova.plugins.Keyboard.hideKeyboardAccessoryBar(n)},close:function(){return cordova.plugins.Keyboard.close()},disableScroll:function(n){return cordova.plugins.Keyboard.disableScroll(n)},isVisible:function(){return cordova.plugins.Keyboard.isVisible}}}]),angular.module("ngCordova.plugins.localNotification",[]).factory("$cordovaLocalNotification",["$q",function(n){return{add:function(e,o){var r=n.defer();return window.plugin.notification.local.add(e,function(n){r.resolve(n)},o),r.promise},cancel:function(e,o){var r=n.defer();return window.plugin.notification.local.cancel(e,function(n){r.resolve(n)},o),r.promise},cancelAll:function(e){var o=n.defer();return window.plugin.notification.local.cancelAll(function(n){o.resolve(n)},e),o.promise},isScheduled:function(e,o){var r=n.defer();return window.plugin.notification.local.isScheduled(e,function(n){r.resolve(n)},o),r.promise},getScheduledIds:function(e){var o=n.defer();return window.plugin.notification.local.getScheduledIds(function(n){o.resolve(n)},e),o.promise},isTriggered:function(e,o){var r=n.defer();return window.plugin.notification.local.isTriggered(e,function(n){r.resolve(n)},o),r.promise},getTriggeredIds:function(e){var o=n.defer();return window.plugin.notification.local.getTriggeredIds(function(n){o.resolve(n)},e),o.promise},getDefaults:function(){return window.plugin.notification.local.getDefaults()},setDefaults:function(n){window.plugin.notification.local.setDefaults(n)},onadd:function(){return window.plugin.notification.local.onadd},ontrigger:function(){return window.plugin.notification.local.ontrigger},onclick:function(){return window.plugin.notification.local.onclick},oncancel:function(){return window.plugin.notification.local.oncancel}}}]),angular.module("ngCordova.plugins",["ngCordova.plugins.deviceMotion","ngCordova.plugins.camera","ngCordova.plugins.geolocation","ngCordova.plugins.deviceOrientation","ngCordova.plugins.dialogs","ngCordova.plugins.vibration","ngCordova.plugins.network","ngCordova.plugins.device","ngCordova.plugins.barcodeScanner","ngCordova.plugins.splashscreen","ngCordova.plugins.keyboard","ngCordova.plugins.contacts","ngCordova.plugins.statusbar","ngCordova.plugins.file","ngCordova.plugins.socialSharing","ngCordova.plugins.globalization","ngCordova.plugins.sqlite","ngCordova.plugins.ga","ngCordova.plugins.push","ngCordova.plugins.spinnerDialog","ngCordova.plugins.pinDialog","ngCordova.plugins.localNotification","ngCordova.plugins.toast","ngCordova.plugins.capture","ngCordova.plugins.appAvailability","ngCordova.plugins.prefs"]),angular.module("ngCordova.plugins.network",[]).factory("$cordovaNetwork",[function(){return{getNetwork:function(){return navigator.connection.type},isOnline:function(){var n=navigator.connection.type;return n!==Connection.UNKNOWN&&n!==Connection.NONE},isOffline:function(){var n=navigator.connection.type;return n===Connection.UNKNOWN||n===Connection.NONE}}}]),angular.module("ngCordova.plugins.pinDialog",[]).factory("$cordovaPinDialog",[function(){return{prompt:function(){return window.plugins.pinDialog.prompt.apply(navigator.notification,arguments)}}}]),angular.module("ngCordova.plugins.prefs",[]).factory("$cordovaPreferences",["$window","$q",function(n,e){return{set:function(o,r){var t=e.defer();return n.applicationPreferences.set(o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise},get:function(o){var r=e.defer();return n.applicationPreferences.get(o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.push",[]).factory("$cordovaPush",["$q",function(n){return{register:function(e){var o=n.defer();return window.plugins.pushNotification.register(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},unregister:function(e){var o=n.defer();return window.plugins.pushNotification.unregister(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},setBadgeNumber:function(e){var o=n.defer();return window.plugins.pushNotification.setApplicationIconBadgeNumber(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.socialSharing",[]).factory("$cordovaSocialSharing",["$q",function(n){return{shareViaTwitter:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaTwitter(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaWhatsApp:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaWhatsApp(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaFacebook:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaFacebook(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaSMS:function(e,o){var r=n.defer();return window.plugins.socialsharing.shareViaSMS(e,o,function(){r.resolve(!0)},function(){r.reject(!1)}),r.promise},shareViaEmail:function(e){var o=n.defer();return window.plugins.socialsharing.shareViaEmail(e,number,function(){o.resolve(!0)},function(){o.reject(!1)}),o.promise},canShareVia:function(e,o,r,t){var i=n.defer();return window.plugins.socialsharing.canShareVia(e,o,r,t,function(n){i.resolve(n)},function(n){i.reject(n)}),i.promise}}}]),angular.module("ngCordova.plugins.spinnerDialog",[]).factory("$cordovaSpinnerDialog",[function(){return{show:function(n,e){return window.plugins.spinnerDialog.show(n,e)},hide:function(){return window.plugins.spinnerDialog.hide()}}}]),angular.module("ngCordova.plugins.splashscreen",[]).factory("$cordovaSplashscreen",[function(){return{hide:function(){return navigator.splashscreen.hide()},show:function(){return navigator.splashscreen.show()}}}]),angular.module("ngCordova.plugins.sqlite",[]).factory("$cordovaSQLite",["$q",function(n){return{openDB:function(n){return window.sqlitePlugin.openDatabase({name:n})},openDBBackground:function(n){return window.sqlitePlugin.openDatabase({name:n,bgType:1})},execute:function(e,o,r){return q=n.defer(),e.transaction(function(n){n.executeSql(o,r,function(n,e){q.resolve(e)},function(n,e){q.reject(e)})}),q.promise},nestedExecute:function(e,o,r,t,i){return q=n.defer(),e.transaction(function(n){n.executeSql(o,t,function(n,e){q.resolve(e),n.executeSql(r,i,function(n,e){q.resolve(e)})})},function(n,e){q.reject(e)}),q.promise}}}]),angular.module("ngCordova.plugins.statusbar",[]).factory("$cordovaStatusbar",[function(){return{overlaysWebView:function(){return StatusBar.overlaysWebView(!0)},style:function(n){switch(n){case 0:return StatusBar.styleDefault();case 1:return StatusBar.styleLightContent();case 2:return StatusBar.styleBlackTranslucent();case 3:return StatusBar.styleBlackOpaque();default:return StatusBar.styleDefault()}},styleColor:function(n){return StatusBar.backgroundColorByName(n)},styleHex:function(n){return StatusBar.backgroundColorByHexString(n)},hide:function(){return StatusBar.hide()},show:function(){return StatusBar.show()},isVisible:function(){return StatusBar.isVisible()}}}]),angular.module("ngCordova.plugins.toast",[]).factory("$cordovaToast",["$q",function(n){return{showShortTop:function(e){var o=n.defer();return window.plugins.toast.showShortTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortCenter:function(e){var o=n.defer();return window.plugins.toast.showShortCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortBottom:function(e){var o=n.defer();return window.plugins.toast.showShortBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongTop:function(e){var o=n.defer();return window.plugins.toast.showLongTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongCenter:function(e){var o=n.defer();return window.plugins.toast.showLongCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongBottom:function(e){var o=n.defer();return window.plugins.toast.showLongBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},show:function(e,o,r){var t=n.defer();return window.plugins.toast.show(e,o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise}}}]),angular.module("ngCordova.plugins.vibration",[]).factory("$cordovaVibration",[function(){return{vibrate:function(n){return navigator.notification.vibrate(n)},vibrateWithPattern:function(n,e){return navigator.notification.vibrateWithPattern(n,e)},cancelVibration:function(){return navigator.notification.cancelVibration()}}}])}(); \ No newline at end of file +!function(){angular.module("ngCordova",["ngCordova.plugins"]),angular.module("ngCordova.plugins.appAvailability",[]).factory("$cordovaAppAvailability",["$q",function(n){return{check:function(e){var o=n.defer();return appAvailability.check(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise}}}]),angular.module("ngCordova.plugins.barcodeScanner",[]).factory("$cordovaBarcodeScanner",["$q",function(n){return{scan:function(){var e=n.defer();return cordova.plugins.barcodeScanner.scan(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},encode:function(e,o){var r=n.defer();return cordova.plugins.barcodeScanner.encode(e,o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.camera",[]).factory("$cordovaCamera",["$q",function(n){return{getPicture:function(e){var o=n.defer();return navigator.camera?(navigator.camera.getPicture(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},cleanup:function(){var e=n.defer();return navigator.camera.cleanup(function(){e.resolve(arguments)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.capture",[]).factory("$cordovaCapture",["$q",function(n){return{captureAudio:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureAudio(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureImage:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureImage(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureVideo:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureVideo(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)}}}]),angular.module("ngCordova.plugins.contacts",[]).factory("$cordovaContacts",["$q",function(n){return{save:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.save(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},remove:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.remove(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},clone:function(n){var e=navigator.contacts.create(n);return e.clone(n)},find:function(e){var o=n.defer(),r=e.fields||["id","displayName"];return delete e.fields,navigator.contacts.find(r,function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.device",[]).factory("$cordovaDevice",[function(){return{getDevice:function(){return device},getCordova:function(){return device.cordova},getModel:function(){return device.model},getName:function(){return device.name},getPlatform:function(){return device.platform},getUUID:function(){return device.uuid},getVersion:function(){return device.version}}}]),angular.module("ngCordova.plugins.deviceMotion",[]).factory("$cordovaDeviceMotion",["$q",function(n){return{getCurrentAcceleration:function(){var e=n.defer();return navigator.accelerometer.getCurrentAcceleration(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchAcceleration:function(e){var o=n.defer(),r=navigator.accelerometer.watchAcceleration(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(n){return navigator.accelerometer.clearWatch(n)}}}]),angular.module("ngCordova.plugins.deviceOrientation",[]).factory("$cordovaDeviceOrientation",["$q",function(n){return{getCurrentHeading:function(){var e=n.defer();return navigator.compass.getCurrentHeading(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchHeading:function(e){var o=n.defer(),r=navigator.compass.watchHeading(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(){navigator.compass.clearWatch()}}}]),angular.module("ngCordova.plugins.dialogs",[]).factory("$cordovaDialogs",[function(){return{alert:function(){return navigator.notification.alert.apply(navigator.notification,arguments)},confirm:function(){return navigator.notification.confirm.apply(navigator.notification,arguments)},prompt:function(){return navigator.notification.prompt.apply(navigator.notification,arguments)},beep:function(n){return navigator.notification.beep(n)}}}]),angular.module("ngCordova.plugins.file",[]).factory("$cordovaFile",["$q",function(n){function e(){var e=n.defer();return window.requestFileSystem(LocalFileSystem.PERSISTENT,1048576,function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}return{checkDir:function(o){var r=n.defer();return e().then(function(n){n.root.getDirectory(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createDir:function(n,o){e().then(function(e){e.root.getDirectory(n,{create:!0,exclusive:o})})},checkFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createFile:function(n,o){3==arguments.length&&(n="/"+n+"/"+arguments[1],o=arguments[2]),e().then(function(e){e.root.getFile(n,{create:!0,exclusive:o},function(){},function(){})})},removeFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.remove(function(){r.resolve()})})}),r.promise},writeFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.createWriter(function(n){r.resolve(n)},function(n){r.reject(n)})})}),r.promise},readFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.file(function(n){var e=new FileReader;e.onloadend=function(){r.resolve(this.result)},e.readAsText(n)})},function(n){r.reject(n)})}),r.promise},readFileMetadata:function(o){var r=n.defer();return e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.file(function(n){r.resolve(n)})},function(n){r.reject(n)})}),r.promise},downloadFile:function(e,o,r,t){var i=n.defer(),a=new FileTransfer,u=encodeURI(e);return a.onprogress=function(n){i.notify(n)},a.download(u,o,function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},uploadFile:function(e,o,r){var t=n.defer(),i=new FileTransfer,a=encodeURI(e);return i.onprogress=function(n){t.notify(n)},i.upload(o,a,function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise}}}]),angular.module("ngCordova.plugins.flashlight",[]).factory("$cordovaFlashlight",["$q",function(n){return{available:function(){var e=n.defer();return window.plugins.flashlight.available(function(n){e.resolve(n)}),e.promise},switchOn:function(){var e=n.defer();return window.plugins.flashlight.switchOn(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},switchOff:function(){var e=n.defer();return window.plugins.flashlight.switchOff(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.ga",[]).factory("$cordovaGA",["$q",function(n){return{init:function(e,o){var r=n.defer();return o=o>=0?o:10,window.plugins.gaPlugin.init(function(n){r.resolve(n)},function(n){r.reject(n)},e,o),r.promise},trackEvent:function(e,o,r,t,i,a){var u=n.defer();return window.plugins.gaPlugin.trackEvent(function(n){u.resolve(n)},function(n){u.reject(n)},r,t,i,a),u.promise},trackPage:function(e,o,r){var t=n.defer();return window.plugins.gaPlugin.trackPage(function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise},setVariable:function(e,o,r,t){var i=n.defer();return window.plugins.gaPlugin.setVariable(function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},exit:function(){var e=n.defer();return window.plugins.gaPlugin.exit(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.geolocation",[]).factory("$cordovaGeolocation",["$q",function(n){return{getCurrentPosition:function(e){var o=n.defer();return navigator.geolocation.getCurrentPosition(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},watchPosition:function(e){var o=n.defer(),r=navigator.geolocation.watchPosition(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(n){return navigator.geolocation.clearWatch(n)}}}]),angular.module("ngCordova.plugins.globalization",[]).factory("$cordovaGlobalization",["$q",function(n){return{getPreferredLanguage:function(){var e=n.defer();return navigator.globalization.getPreferredLanguage(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getLocaleName:function(){var e=n.defer();return navigator.globalization.getLocaleName(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getFirstDayOfWeek:function(){var e=n.defer();return navigator.globalization.getFirstDayOfWeek(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.keyboard",[]).factory("$cordovaKeyboard",[function(){return{hideAccessoryBar:function(n){return cordova.plugins.Keyboard.hideKeyboardAccessoryBar(n)},close:function(){return cordova.plugins.Keyboard.close()},disableScroll:function(n){return cordova.plugins.Keyboard.disableScroll(n)},isVisible:function(){return cordova.plugins.Keyboard.isVisible}}}]),angular.module("ngCordova.plugins.localNotification",[]).factory("$cordovaLocalNotification",["$q",function(n){return{add:function(e,o){var r=n.defer();return window.plugin.notification.local.add(e,function(n){r.resolve(n)},o),r.promise},cancel:function(e,o){var r=n.defer();return window.plugin.notification.local.cancel(e,function(n){r.resolve(n)},o),r.promise},cancelAll:function(e){var o=n.defer();return window.plugin.notification.local.cancelAll(function(n){o.resolve(n)},e),o.promise},isScheduled:function(e,o){var r=n.defer();return window.plugin.notification.local.isScheduled(e,function(n){r.resolve(n)},o),r.promise},getScheduledIds:function(e){var o=n.defer();return window.plugin.notification.local.getScheduledIds(function(n){o.resolve(n)},e),o.promise},isTriggered:function(e,o){var r=n.defer();return window.plugin.notification.local.isTriggered(e,function(n){r.resolve(n)},o),r.promise},getTriggeredIds:function(e){var o=n.defer();return window.plugin.notification.local.getTriggeredIds(function(n){o.resolve(n)},e),o.promise},getDefaults:function(){return window.plugin.notification.local.getDefaults()},setDefaults:function(n){window.plugin.notification.local.setDefaults(n)},onadd:function(){return window.plugin.notification.local.onadd},ontrigger:function(){return window.plugin.notification.local.ontrigger},onclick:function(){return window.plugin.notification.local.onclick},oncancel:function(){return window.plugin.notification.local.oncancel}}}]),angular.module("ngCordova.plugins",["ngCordova.plugins.deviceMotion","ngCordova.plugins.camera","ngCordova.plugins.geolocation","ngCordova.plugins.deviceOrientation","ngCordova.plugins.dialogs","ngCordova.plugins.vibration","ngCordova.plugins.network","ngCordova.plugins.device","ngCordova.plugins.barcodeScanner","ngCordova.plugins.splashscreen","ngCordova.plugins.keyboard","ngCordova.plugins.contacts","ngCordova.plugins.statusbar","ngCordova.plugins.file","ngCordova.plugins.socialSharing","ngCordova.plugins.globalization","ngCordova.plugins.sqlite","ngCordova.plugins.ga","ngCordova.plugins.push","ngCordova.plugins.spinnerDialog","ngCordova.plugins.pinDialog","ngCordova.plugins.localNotification","ngCordova.plugins.toast","ngCordova.plugins.flashlight","ngCordova.plugins.capture","ngCordova.plugins.appAvailability","ngCordova.plugins.prefs"]),angular.module("ngCordova.plugins.network",[]).factory("$cordovaNetwork",[function(){return{getNetwork:function(){return navigator.connection.type},isOnline:function(){var n=navigator.connection.type;return n!==Connection.UNKNOWN&&n!==Connection.NONE},isOffline:function(){var n=navigator.connection.type;return n===Connection.UNKNOWN||n===Connection.NONE}}}]),angular.module("ngCordova.plugins.pinDialog",[]).factory("$cordovaPinDialog",[function(){return{prompt:function(){return window.plugins.pinDialog.prompt.apply(navigator.notification,arguments)}}}]),angular.module("ngCordova.plugins.prefs",[]).factory("$cordovaPreferences",["$window","$q",function(n,e){return{set:function(o,r){var t=e.defer();return n.applicationPreferences.set(o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise},get:function(o){var r=e.defer();return n.applicationPreferences.get(o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.push",[]).factory("$cordovaPush",["$q",function(n){return{register:function(e){var o=n.defer();return window.plugins.pushNotification.register(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},unregister:function(e){var o=n.defer();return window.plugins.pushNotification.unregister(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},setBadgeNumber:function(e){var o=n.defer();return window.plugins.pushNotification.setApplicationIconBadgeNumber(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.socialSharing",[]).factory("$cordovaSocialSharing",["$q",function(n){return{shareViaTwitter:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaTwitter(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaWhatsApp:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaWhatsApp(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaFacebook:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaFacebook(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaSMS:function(e,o){var r=n.defer();return window.plugins.socialsharing.shareViaSMS(e,o,function(){r.resolve(!0)},function(){r.reject(!1)}),r.promise},shareViaEmail:function(e){var o=n.defer();return window.plugins.socialsharing.shareViaEmail(e,number,function(){o.resolve(!0)},function(){o.reject(!1)}),o.promise},canShareVia:function(e,o,r,t){var i=n.defer();return window.plugins.socialsharing.canShareVia(e,o,r,t,function(n){i.resolve(n)},function(n){i.reject(n)}),i.promise}}}]),angular.module("ngCordova.plugins.spinnerDialog",[]).factory("$cordovaSpinnerDialog",[function(){return{show:function(n,e){return window.plugins.spinnerDialog.show(n,e)},hide:function(){return window.plugins.spinnerDialog.hide()}}}]),angular.module("ngCordova.plugins.splashscreen",[]).factory("$cordovaSplashscreen",[function(){return{hide:function(){return navigator.splashscreen.hide()},show:function(){return navigator.splashscreen.show()}}}]),angular.module("ngCordova.plugins.sqlite",[]).factory("$cordovaSQLite",["$q",function(n){return{openDB:function(n){return window.sqlitePlugin.openDatabase({name:n})},openDBBackground:function(n){return window.sqlitePlugin.openDatabase({name:n,bgType:1})},execute:function(e,o,r){return q=n.defer(),e.transaction(function(n){n.executeSql(o,r,function(n,e){q.resolve(e)},function(n,e){q.reject(e)})}),q.promise},nestedExecute:function(e,o,r,t,i){return q=n.defer(),e.transaction(function(n){n.executeSql(o,t,function(n,e){q.resolve(e),n.executeSql(r,i,function(n,e){q.resolve(e)})})},function(n,e){q.reject(e)}),q.promise}}}]),angular.module("ngCordova.plugins.statusbar",[]).factory("$cordovaStatusbar",[function(){return{overlaysWebView:function(){return StatusBar.overlaysWebView(!0)},style:function(n){switch(n){case 0:return StatusBar.styleDefault();case 1:return StatusBar.styleLightContent();case 2:return StatusBar.styleBlackTranslucent();case 3:return StatusBar.styleBlackOpaque();default:return StatusBar.styleDefault()}},styleColor:function(n){return StatusBar.backgroundColorByName(n)},styleHex:function(n){return StatusBar.backgroundColorByHexString(n)},hide:function(){return StatusBar.hide()},show:function(){return StatusBar.show()},isVisible:function(){return StatusBar.isVisible()}}}]),angular.module("ngCordova.plugins.toast",[]).factory("$cordovaToast",["$q",function(n){return{showShortTop:function(e){var o=n.defer();return window.plugins.toast.showShortTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortCenter:function(e){var o=n.defer();return window.plugins.toast.showShortCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortBottom:function(e){var o=n.defer();return window.plugins.toast.showShortBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongTop:function(e){var o=n.defer();return window.plugins.toast.showLongTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongCenter:function(e){var o=n.defer();return window.plugins.toast.showLongCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongBottom:function(e){var o=n.defer();return window.plugins.toast.showLongBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},show:function(e,o,r){var t=n.defer();return window.plugins.toast.show(e,o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise}}}]),angular.module("ngCordova.plugins.vibration",[]).factory("$cordovaVibration",[function(){return{vibrate:function(n){return navigator.notification.vibrate(n)},vibrateWithPattern:function(n,e){return navigator.notification.vibrateWithPattern(n,e)},cancelVibration:function(){return navigator.notification.cancelVibration()}}}])}(); \ No newline at end of file diff --git a/demo/app/www/templates/plugins/geolocation.html b/demo/app/www/templates/plugins/geolocation.html index 80db2ed2..91082382 100644 --- a/demo/app/www/templates/plugins/geolocation.html +++ b/demo/app/www/templates/plugins/geolocation.html @@ -4,7 +4,7 @@ #geo-val { vertical-align: middle; display: inline-block; - font-size: 35px; + font-size: 25px; color: #4a87ee; } #geo-box { diff --git a/dist/ng-cordova.js b/dist/ng-cordova.js index a80656f3..721fe60e 100644 --- a/dist/ng-cordova.js +++ b/dist/ng-cordova.js @@ -247,7 +247,7 @@ angular.module('ngCordova.plugins.device', []) return device.model; }, - // Warning: device.name is deprecated as of version 2.3.0. Use device.model instead. + // Waraning: device.name is deprecated as of version 2.3.0. Use device.model instead. getName: function () { return device.name; }, @@ -286,14 +286,18 @@ angular.module('ngCordova.plugins.deviceMotion', []) watchAcceleration: function(options) { var q = $q.defer(); - navigator.accelerometer.watchAcceleration(function(result) { + var watchId = navigator.accelerometer.watchAcceleration(function(result) { // Do any magic you need + //q.resolve(watchID); q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { return navigator.accelerometer.clearWatch(watchID); @@ -306,16 +310,33 @@ angular.module('ngCordova.plugins.deviceOrientation', []) .factory('$cordovaDeviceOrientation', ['$q', function($q) { return { + getCurrentHeading: function() { + var q = $q.defer(); + + navigator.compass.getCurrentHeading(function(heading) { + q.resolve(heading); + }, function(err) { + q.reject(err); + }); + + return q.promise; + }, watchHeading: function(options) { var q = $q.defer(); - navigator.compass.watchHeading(function(result) { + var watchId = navigator.compass.watchHeading(function(result) { q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } + }, + clearWatch: function(watchID) { + navigator.compass.clearWatch(); } } }]); @@ -389,12 +410,17 @@ angular.module('ngCordova.plugins.file', []) ); }, - checkFile: function (dir, file) { + checkFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function checkFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, // File exists function () { q.resolve(); @@ -410,10 +436,16 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - createFile: function (dir, file, replaceBOOL) { + createFile: function (filePath, replaceBOOL) { + // Backward compatibility for previous function createFile(dir, file, replaceBOOL) + if (arguments.length == 3) { + filePath = '/' + filePath + '/' + arguments[1]; + replaceBOOL = arguments[2]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: true, exclusive: replaceBOOL}, + filesystem.root.getFile(filePath, {create: true, exclusive: replaceBOOL}, function (success) { }, @@ -424,12 +456,17 @@ angular.module('ngCordova.plugins.file', []) ); }, - removeFile: function (dir, file) { + removeFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function removeFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, function (fileEntry) { + filesystem.root.getFile(filePath, {create: false}, function (fileEntry) { fileEntry.remove(function () { q.resolve(); }); @@ -440,12 +477,17 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - writeFile: function (dir, file) { + writeFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function writeFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, function (fileEntry) { fileEntry.createWriter( function (fileWriter) { @@ -462,13 +504,18 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, - readFile: function (dir, file) { + readFile: function (filePath) { var q = $q.defer(); + // Backward compatibility for previous function readFile(dir, file) + if (arguments.length == 2) { + filePath = '/' + filePath + '/' + arguments[1]; + } + getFilesystem().then( function (filesystem) { - filesystem.root.getFile('/' + dir + '/' + file, {create: false}, + filesystem.root.getFile(filePath, {create: false}, // success function (fileEntry) { fileEntry.file(function (file) { @@ -490,16 +537,35 @@ angular.module('ngCordova.plugins.file', []) return q.promise; }, + readFileMetadata: function (filePath) { + var q = $q.defer(); + + getFilesystem().then( + function (filesystem) { + filesystem.root.getFile(filePath, {create: false}, + // success + function (fileEntry) { + fileEntry.file(function (file) { + q.resolve(file); + }); + }, + // error + function (error) { + q.reject(error); + }); + } + ); + + return q.promise; + }, + downloadFile: function (source, filePath, trustAllHosts, options) { var q = $q.defer(); var fileTransfer = new FileTransfer(); var uri = encodeURI(source); fileTransfer.onprogress = function(progressEvent) { - if (progressEvent.lengthComputable) { - var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); - q.notify(perc); - } + q.notify(progressEvent); }; fileTransfer.download( @@ -522,10 +588,7 @@ angular.module('ngCordova.plugins.file', []) var uri = encodeURI(server); fileTransfer.onprogress = function(progressEvent) { - if (progressEvent.lengthComputable) { - var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); - q.notify(perc); - } + q.notify(progressEvent); }; fileTransfer.upload( @@ -557,6 +620,41 @@ angular.module('ngCordova.plugins.file', []) return q.promise; } }]); +angular.module('ngCordova.plugins.flashlight', []) + +.factory('$cordovaFlashlight', ['$q', function ($q) { + + return { + available: function () { + var q = $q.defer(); + window.plugins.flashlight.available(function (isAvailable) { + q.resolve(isAvailable); + }); + return q.promise; + }, + + switchOn: function () { + var q = $q.defer(); + window.plugins.flashlight.switchOn(function (response) { + q.resolve(response); + }, function (error) { + q.reject(error) + }); + return q.promise; + }, + + switchOff: function () { + var q = $q.defer(); + window.plugins.flashlight.switchOff(function (response) { + q.resolve(response); + }, function (error) { + q.reject(error) + }); + return q.promise; + } + } + } +]); angular.module('ngCordova.plugins.ga', []) .factory('$cordovaGA', ['$q', function ($q) { @@ -626,7 +724,7 @@ angular.module('ngCordova.plugins.geolocation', []) watchPosition: function(options) { var q = $q.defer(); - navigator.geolocation.watchPosition(function(result) { + var watchId = navigator.geolocation.watchPosition(function(result) { // Do any magic you need q.notify(result); @@ -634,7 +732,10 @@ angular.module('ngCordova.plugins.geolocation', []) q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { @@ -856,6 +957,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.pinDialog', 'ngCordova.plugins.localNotification', 'ngCordova.plugins.toast', + 'ngCordova.plugins.flashlight', 'ngCordova.plugins.capture', 'ngCordova.plugins.appAvailability', 'ngCordova.plugins.prefs' diff --git a/dist/ng-cordova.min.js b/dist/ng-cordova.min.js index fef96219..01e28cd4 100644 --- a/dist/ng-cordova.min.js +++ b/dist/ng-cordova.min.js @@ -1 +1 @@ -!function(){angular.module("ngCordova",["ngCordova.plugins"]),angular.module("ngCordova.plugins.appAvailability",[]).factory("$cordovaAppAvailability",["$q",function(n){return{check:function(e){var o=n.defer();return appAvailability.check(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise}}}]),angular.module("ngCordova.plugins.barcodeScanner",[]).factory("$cordovaBarcodeScanner",["$q",function(n){return{scan:function(){var e=n.defer();return cordova.plugins.barcodeScanner.scan(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},encode:function(e,o){var r=n.defer();return cordova.plugins.barcodeScanner.encode(e,o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.camera",[]).factory("$cordovaCamera",["$q",function(n){return{getPicture:function(e){var o=n.defer();return navigator.camera?(navigator.camera.getPicture(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},cleanup:function(){var e=n.defer();return navigator.camera.cleanup(function(){e.resolve(arguments)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.capture",[]).factory("$cordovaCapture",["$q",function(n){return{captureAudio:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureAudio(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureImage:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureImage(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureVideo:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureVideo(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)}}}]),angular.module("ngCordova.plugins.contacts",[]).factory("$cordovaContacts",["$q",function(n){return{save:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.save(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},remove:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.remove(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},clone:function(n){var e=navigator.contacts.create(n);return e.clone(n)},find:function(e){var o=n.defer(),r=e.fields||["id","displayName"];return delete e.fields,navigator.contacts.find(r,function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.device",[]).factory("$cordovaDevice",[function(){return{getDevice:function(){return device},getCordova:function(){return device.cordova},getModel:function(){return device.model},getName:function(){return device.name},getPlatform:function(){return device.platform},getUUID:function(){return device.uuid},getVersion:function(){return device.version}}}]),angular.module("ngCordova.plugins.deviceMotion",[]).factory("$cordovaDeviceMotion",["$q",function(n){return{getCurrentAcceleration:function(){var e=n.defer();return navigator.accelerometer.getCurrentAcceleration(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchAcceleration:function(e){var o=n.defer();return navigator.accelerometer.watchAcceleration(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise},clearWatch:function(n){return navigator.accelerometer.clearWatch(n)}}}]),angular.module("ngCordova.plugins.deviceOrientation",[]).factory("$cordovaDeviceOrientation",["$q",function(n){return{watchHeading:function(e){var o=n.defer();return navigator.compass.watchHeading(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.dialogs",[]).factory("$cordovaDialogs",[function(){return{alert:function(){return navigator.notification.alert.apply(navigator.notification,arguments)},confirm:function(){return navigator.notification.confirm.apply(navigator.notification,arguments)},prompt:function(){return navigator.notification.prompt.apply(navigator.notification,arguments)},beep:function(n){return navigator.notification.beep(n)}}}]),angular.module("ngCordova.plugins.file",[]).factory("$cordovaFile",["$q",function(n){function e(){var e=n.defer();return window.requestFileSystem(LocalFileSystem.PERSISTENT,1048576,function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}return{checkDir:function(o){var r=n.defer();return e().then(function(n){n.root.getDirectory(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createDir:function(n,o){e().then(function(e){e.root.getDirectory(n,{create:!0,exclusive:o})})},checkFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(){t.resolve()},function(){t.reject()})}),t.promise},createFile:function(n,o,r){e().then(function(e){e.root.getFile("/"+n+"/"+o,{create:!0,exclusive:r},function(){},function(){})})},removeFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.remove(function(){t.resolve()})})}),t.promise},writeFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.createWriter(function(n){t.resolve(n)},function(n){t.reject(n)})})}),t.promise},readFile:function(o,r){var t=n.defer();return e().then(function(n){n.root.getFile("/"+o+"/"+r,{create:!1},function(n){n.file(function(n){var e=new FileReader;e.onloadend=function(){t.resolve(this.result)},e.readAsText(n)})},function(n){t.reject(n)})}),t.promise},downloadFile:function(e,o,r,t){var i=n.defer(),a=new FileTransfer,c=encodeURI(e);return a.onprogress=function(n){if(n.lengthComputable){var e=Math.floor(n.loaded/n.total*100);i.notify(e)}},a.download(c,o,function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},uploadFile:function(e,o,r){var t=n.defer(),i=new FileTransfer,a=encodeURI(e);return i.onprogress=function(n){if(n.lengthComputable){var e=Math.floor(n.loaded/n.total*100);t.notify(e)}},i.upload(o,a,function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise}}}]),angular.module("ngCordova.plugins.ga",[]).factory("$cordovaGA",["$q",function(n){return{init:function(e,o){var r=n.defer();return o=o>=0?o:10,window.plugins.gaPlugin.init(function(n){r.resolve(n)},function(n){r.reject(n)},e,o),r.promise},trackEvent:function(e,o,r,t,i,a){var c=n.defer();return window.plugins.gaPlugin.trackEvent(function(n){c.resolve(n)},function(n){c.reject(n)},r,t,i,a),c.promise},trackPage:function(e,o,r){var t=n.defer();return window.plugins.gaPlugin.trackPage(function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise},setVariable:function(e,o,r,t){var i=n.defer();return window.plugins.gaPlugin.setVariable(function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},exit:function(){var e=n.defer();return window.plugins.gaPlugin.exit(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.geolocation",[]).factory("$cordovaGeolocation",["$q",function(n){return{getCurrentPosition:function(e){var o=n.defer();return navigator.geolocation.getCurrentPosition(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},watchPosition:function(e){var o=n.defer();return navigator.geolocation.watchPosition(function(n){o.notify(n)},function(n){o.reject(n)},e),o.promise},clearWatch:function(n){return navigator.geolocation.clearWatch(n)}}}]),angular.module("ngCordova.plugins.globalization",[]).factory("$cordovaGlobalization",["$q",function(n){return{getPreferredLanguage:function(){var e=n.defer();return navigator.globalization.getPreferredLanguage(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getLocaleName:function(){var e=n.defer();return navigator.globalization.getLocaleName(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getFirstDayOfWeek:function(){var e=n.defer();return navigator.globalization.getFirstDayOfWeek(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.keyboard",[]).factory("$cordovaKeyboard",[function(){return{hideAccessoryBar:function(n){return cordova.plugins.Keyboard.hideKeyboardAccessoryBar(n)},close:function(){return cordova.plugins.Keyboard.close()},disableScroll:function(n){return cordova.plugins.Keyboard.disableScroll(n)},isVisible:function(){return cordova.plugins.Keyboard.isVisible}}}]),angular.module("ngCordova.plugins.localNotification",[]).factory("$cordovaLocalNotification",["$q",function(n){return{add:function(e,o){var r=n.defer();return window.plugin.notification.local.add(e,function(n){r.resolve(n)},o),r.promise},cancel:function(e,o){var r=n.defer();return window.plugin.notification.local.cancel(e,function(n){r.resolve(n)},o),r.promise},cancelAll:function(e){var o=n.defer();return window.plugin.notification.local.cancelAll(function(n){o.resolve(n)},e),o.promise},isScheduled:function(e,o){var r=n.defer();return window.plugin.notification.local.isScheduled(e,function(n){r.resolve(n)},o),r.promise},getScheduledIds:function(e){var o=n.defer();return window.plugin.notification.local.getScheduledIds(function(n){o.resolve(n)},e),o.promise},isTriggered:function(e,o){var r=n.defer();return window.plugin.notification.local.isTriggered(e,function(n){r.resolve(n)},o),r.promise},getTriggeredIds:function(e){var o=n.defer();return window.plugin.notification.local.getTriggeredIds(function(n){o.resolve(n)},e),o.promise},getDefaults:function(){return window.plugin.notification.local.getDefaults()},setDefaults:function(n){window.plugin.notification.local.setDefaults(n)},onadd:function(){return window.plugin.notification.local.onadd},ontrigger:function(){return window.plugin.notification.local.ontrigger},onclick:function(){return window.plugin.notification.local.onclick},oncancel:function(){return window.plugin.notification.local.oncancel}}}]),angular.module("ngCordova.plugins",["ngCordova.plugins.deviceMotion","ngCordova.plugins.camera","ngCordova.plugins.geolocation","ngCordova.plugins.deviceOrientation","ngCordova.plugins.dialogs","ngCordova.plugins.vibration","ngCordova.plugins.network","ngCordova.plugins.device","ngCordova.plugins.barcodeScanner","ngCordova.plugins.splashscreen","ngCordova.plugins.keyboard","ngCordova.plugins.contacts","ngCordova.plugins.statusbar","ngCordova.plugins.file","ngCordova.plugins.socialSharing","ngCordova.plugins.globalization","ngCordova.plugins.sqlite","ngCordova.plugins.ga","ngCordova.plugins.push","ngCordova.plugins.spinnerDialog","ngCordova.plugins.pinDialog","ngCordova.plugins.localNotification","ngCordova.plugins.toast","ngCordova.plugins.capture","ngCordova.plugins.appAvailability","ngCordova.plugins.prefs"]),angular.module("ngCordova.plugins.network",[]).factory("$cordovaNetwork",[function(){return{getNetwork:function(){return navigator.connection.type},isOnline:function(){var n=navigator.connection.type;return n!==Connection.UNKNOWN&&n!==Connection.NONE},isOffline:function(){var n=navigator.connection.type;return n===Connection.UNKNOWN||n===Connection.NONE}}}]),angular.module("ngCordova.plugins.pinDialog",[]).factory("$cordovaPinDialog",[function(){return{prompt:function(){return window.plugins.pinDialog.prompt.apply(navigator.notification,arguments)}}}]),angular.module("ngCordova.plugins.prefs",[]).factory("$cordovaPreferences",["$window","$q",function(n,e){return{set:function(o,r){var t=e.defer();return n.applicationPreferences.set(o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise},get:function(o){var r=e.defer();return n.applicationPreferences.get(o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.push",[]).factory("$cordovaPush",["$q",function(n){return{register:function(e){var o=n.defer();return window.plugins.pushNotification.register(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},unregister:function(e){var o=n.defer();return window.plugins.pushNotification.unregister(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},setBadgeNumber:function(e){var o=n.defer();return window.plugins.pushNotification.setApplicationIconBadgeNumber(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.socialSharing",[]).factory("$cordovaSocialSharing",["$q",function(n){return{shareViaTwitter:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaTwitter(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaWhatsApp:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaWhatsApp(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaFacebook:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaFacebook(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaSMS:function(e,o){var r=n.defer();return window.plugins.socialsharing.shareViaSMS(e,o,function(){r.resolve(!0)},function(){r.reject(!1)}),r.promise},shareViaEmail:function(e){var o=n.defer();return window.plugins.socialsharing.shareViaEmail(e,number,function(){o.resolve(!0)},function(){o.reject(!1)}),o.promise},canShareVia:function(e,o,r,t){var i=n.defer();return window.plugins.socialsharing.canShareVia(e,o,r,t,function(n){i.resolve(n)},function(n){i.reject(n)}),i.promise}}}]),angular.module("ngCordova.plugins.spinnerDialog",[]).factory("$cordovaSpinnerDialog",[function(){return{show:function(n,e){return window.plugins.spinnerDialog.show(n,e)},hide:function(){return window.plugins.spinnerDialog.hide()}}}]),angular.module("ngCordova.plugins.splashscreen",[]).factory("$cordovaSplashscreen",[function(){return{hide:function(){return navigator.splashscreen.hide()},show:function(){return navigator.splashscreen.show()}}}]),angular.module("ngCordova.plugins.sqlite",[]).factory("$cordovaSQLite",["$q",function(n){return{openDB:function(n){return window.sqlitePlugin.openDatabase({name:n})},openDBBackground:function(n){return window.sqlitePlugin.openDatabase({name:n,bgType:1})},execute:function(e,o,r){return q=n.defer(),e.transaction(function(n){n.executeSql(o,r,function(n,e){q.resolve(e)},function(n,e){q.reject(e)})}),q.promise},nestedExecute:function(e,o,r,t,i){return q=n.defer(),e.transaction(function(n){n.executeSql(o,t,function(n,e){q.resolve(e),n.executeSql(r,i,function(n,e){q.resolve(e)})})},function(n,e){q.reject(e)}),q.promise}}}]),angular.module("ngCordova.plugins.statusbar",[]).factory("$cordovaStatusbar",[function(){return{overlaysWebView:function(){return StatusBar.overlaysWebView(!0)},style:function(n){switch(n){case 0:return StatusBar.styleDefault();case 1:return StatusBar.styleLightContent();case 2:return StatusBar.styleBlackTranslucent();case 3:return StatusBar.styleBlackOpaque();default:return StatusBar.styleDefault()}},styleColor:function(n){return StatusBar.backgroundColorByName(n)},styleHex:function(n){return StatusBar.backgroundColorByHexString(n)},hide:function(){return StatusBar.hide()},show:function(){return StatusBar.show()},isVisible:function(){return StatusBar.isVisible()}}}]),angular.module("ngCordova.plugins.toast",[]).factory("$cordovaToast",["$q",function(n){return{showShortTop:function(e){var o=n.defer();return window.plugins.toast.showShortTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortCenter:function(e){var o=n.defer();return window.plugins.toast.showShortCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortBottom:function(e){var o=n.defer();return window.plugins.toast.showShortBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongTop:function(e){var o=n.defer();return window.plugins.toast.showLongTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongCenter:function(e){var o=n.defer();return window.plugins.toast.showLongCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongBottom:function(e){var o=n.defer();return window.plugins.toast.showLongBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},show:function(e,o,r){var t=n.defer();return window.plugins.toast.show(e,o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise}}}]),angular.module("ngCordova.plugins.vibration",[]).factory("$cordovaVibration",[function(){return{vibrate:function(n){return navigator.notification.vibrate(n)},vibrateWithPattern:function(n,e){return navigator.notification.vibrateWithPattern(n,e)},cancelVibration:function(){return navigator.notification.cancelVibration()}}}])}(); \ No newline at end of file +!function(){angular.module("ngCordova",["ngCordova.plugins"]),angular.module("ngCordova.plugins.appAvailability",[]).factory("$cordovaAppAvailability",["$q",function(n){return{check:function(e){var o=n.defer();return appAvailability.check(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise}}}]),angular.module("ngCordova.plugins.barcodeScanner",[]).factory("$cordovaBarcodeScanner",["$q",function(n){return{scan:function(){var e=n.defer();return cordova.plugins.barcodeScanner.scan(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},encode:function(e,o){var r=n.defer();return cordova.plugins.barcodeScanner.encode(e,o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.camera",[]).factory("$cordovaCamera",["$q",function(n){return{getPicture:function(e){var o=n.defer();return navigator.camera?(navigator.camera.getPicture(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},cleanup:function(){var e=n.defer();return navigator.camera.cleanup(function(){e.resolve(arguments)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.capture",[]).factory("$cordovaCapture",["$q",function(n){return{captureAudio:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureAudio(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureImage:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureImage(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)},captureVideo:function(e){var o=n.defer();return navigator.device.capture?(navigator.device.capture.captureVideo(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise):(o.resolve(null),o.promise)}}}]),angular.module("ngCordova.plugins.contacts",[]).factory("$cordovaContacts",["$q",function(n){return{save:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.save(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},remove:function(e){var o=n.defer(),r=navigator.contacts.create(e);return r.remove(function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},clone:function(n){var e=navigator.contacts.create(n);return e.clone(n)},find:function(e){var o=n.defer(),r=e.fields||["id","displayName"];return delete e.fields,navigator.contacts.find(r,function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.device",[]).factory("$cordovaDevice",[function(){return{getDevice:function(){return device},getCordova:function(){return device.cordova},getModel:function(){return device.model},getName:function(){return device.name},getPlatform:function(){return device.platform},getUUID:function(){return device.uuid},getVersion:function(){return device.version}}}]),angular.module("ngCordova.plugins.deviceMotion",[]).factory("$cordovaDeviceMotion",["$q",function(n){return{getCurrentAcceleration:function(){var e=n.defer();return navigator.accelerometer.getCurrentAcceleration(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchAcceleration:function(e){var o=n.defer(),r=navigator.accelerometer.watchAcceleration(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(n){return navigator.accelerometer.clearWatch(n)}}}]),angular.module("ngCordova.plugins.deviceOrientation",[]).factory("$cordovaDeviceOrientation",["$q",function(n){return{getCurrentHeading:function(){var e=n.defer();return navigator.compass.getCurrentHeading(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},watchHeading:function(e){var o=n.defer(),r=navigator.compass.watchHeading(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(){navigator.compass.clearWatch()}}}]),angular.module("ngCordova.plugins.dialogs",[]).factory("$cordovaDialogs",[function(){return{alert:function(){return navigator.notification.alert.apply(navigator.notification,arguments)},confirm:function(){return navigator.notification.confirm.apply(navigator.notification,arguments)},prompt:function(){return navigator.notification.prompt.apply(navigator.notification,arguments)},beep:function(n){return navigator.notification.beep(n)}}}]),angular.module("ngCordova.plugins.file",[]).factory("$cordovaFile",["$q",function(n){function e(){var e=n.defer();return window.requestFileSystem(LocalFileSystem.PERSISTENT,1048576,function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}return{checkDir:function(o){var r=n.defer();return e().then(function(n){n.root.getDirectory(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createDir:function(n,o){e().then(function(e){e.root.getDirectory(n,{create:!0,exclusive:o})})},checkFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(){r.resolve()},function(){r.reject()})}),r.promise},createFile:function(n,o){3==arguments.length&&(n="/"+n+"/"+arguments[1],o=arguments[2]),e().then(function(e){e.root.getFile(n,{create:!0,exclusive:o},function(){},function(){})})},removeFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.remove(function(){r.resolve()})})}),r.promise},writeFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.createWriter(function(n){r.resolve(n)},function(n){r.reject(n)})})}),r.promise},readFile:function(o){var r=n.defer();return 2==arguments.length&&(o="/"+o+"/"+arguments[1]),e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.file(function(n){var e=new FileReader;e.onloadend=function(){r.resolve(this.result)},e.readAsText(n)})},function(n){r.reject(n)})}),r.promise},readFileMetadata:function(o){var r=n.defer();return e().then(function(n){n.root.getFile(o,{create:!1},function(n){n.file(function(n){r.resolve(n)})},function(n){r.reject(n)})}),r.promise},downloadFile:function(e,o,r,t){var i=n.defer(),a=new FileTransfer,u=encodeURI(e);return a.onprogress=function(n){i.notify(n)},a.download(u,o,function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},uploadFile:function(e,o,r){var t=n.defer(),i=new FileTransfer,a=encodeURI(e);return i.onprogress=function(n){t.notify(n)},i.upload(o,a,function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise}}}]),angular.module("ngCordova.plugins.flashlight",[]).factory("$cordovaFlashlight",["$q",function(n){return{available:function(){var e=n.defer();return window.plugins.flashlight.available(function(n){e.resolve(n)}),e.promise},switchOn:function(){var e=n.defer();return window.plugins.flashlight.switchOn(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},switchOff:function(){var e=n.defer();return window.plugins.flashlight.switchOff(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.ga",[]).factory("$cordovaGA",["$q",function(n){return{init:function(e,o){var r=n.defer();return o=o>=0?o:10,window.plugins.gaPlugin.init(function(n){r.resolve(n)},function(n){r.reject(n)},e,o),r.promise},trackEvent:function(e,o,r,t,i,a){var u=n.defer();return window.plugins.gaPlugin.trackEvent(function(n){u.resolve(n)},function(n){u.reject(n)},r,t,i,a),u.promise},trackPage:function(e,o,r){var t=n.defer();return window.plugins.gaPlugin.trackPage(function(n){t.resolve(n)},function(n){t.reject(n)},r),t.promise},setVariable:function(e,o,r,t){var i=n.defer();return window.plugins.gaPlugin.setVariable(function(n){i.resolve(n)},function(n){i.reject(n)},r,t),i.promise},exit:function(){var e=n.defer();return window.plugins.gaPlugin.exit(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.geolocation",[]).factory("$cordovaGeolocation",["$q",function(n){return{getCurrentPosition:function(e){var o=n.defer();return navigator.geolocation.getCurrentPosition(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},watchPosition:function(e){var o=n.defer(),r=navigator.geolocation.watchPosition(function(n){o.notify(n)},function(n){o.reject(n)},e);return{watchId:r,promise:o.promise}},clearWatch:function(n){return navigator.geolocation.clearWatch(n)}}}]),angular.module("ngCordova.plugins.globalization",[]).factory("$cordovaGlobalization",["$q",function(n){return{getPreferredLanguage:function(){var e=n.defer();return navigator.globalization.getPreferredLanguage(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getLocaleName:function(){var e=n.defer();return navigator.globalization.getLocaleName(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise},getFirstDayOfWeek:function(){var e=n.defer();return navigator.globalization.getFirstDayOfWeek(function(n){e.resolve(n)},function(n){e.reject(n)}),e.promise}}}]),angular.module("ngCordova.plugins.keyboard",[]).factory("$cordovaKeyboard",[function(){return{hideAccessoryBar:function(n){return cordova.plugins.Keyboard.hideKeyboardAccessoryBar(n)},close:function(){return cordova.plugins.Keyboard.close()},disableScroll:function(n){return cordova.plugins.Keyboard.disableScroll(n)},isVisible:function(){return cordova.plugins.Keyboard.isVisible}}}]),angular.module("ngCordova.plugins.localNotification",[]).factory("$cordovaLocalNotification",["$q",function(n){return{add:function(e,o){var r=n.defer();return window.plugin.notification.local.add(e,function(n){r.resolve(n)},o),r.promise},cancel:function(e,o){var r=n.defer();return window.plugin.notification.local.cancel(e,function(n){r.resolve(n)},o),r.promise},cancelAll:function(e){var o=n.defer();return window.plugin.notification.local.cancelAll(function(n){o.resolve(n)},e),o.promise},isScheduled:function(e,o){var r=n.defer();return window.plugin.notification.local.isScheduled(e,function(n){r.resolve(n)},o),r.promise},getScheduledIds:function(e){var o=n.defer();return window.plugin.notification.local.getScheduledIds(function(n){o.resolve(n)},e),o.promise},isTriggered:function(e,o){var r=n.defer();return window.plugin.notification.local.isTriggered(e,function(n){r.resolve(n)},o),r.promise},getTriggeredIds:function(e){var o=n.defer();return window.plugin.notification.local.getTriggeredIds(function(n){o.resolve(n)},e),o.promise},getDefaults:function(){return window.plugin.notification.local.getDefaults()},setDefaults:function(n){window.plugin.notification.local.setDefaults(n)},onadd:function(){return window.plugin.notification.local.onadd},ontrigger:function(){return window.plugin.notification.local.ontrigger},onclick:function(){return window.plugin.notification.local.onclick},oncancel:function(){return window.plugin.notification.local.oncancel}}}]),angular.module("ngCordova.plugins",["ngCordova.plugins.deviceMotion","ngCordova.plugins.camera","ngCordova.plugins.geolocation","ngCordova.plugins.deviceOrientation","ngCordova.plugins.dialogs","ngCordova.plugins.vibration","ngCordova.plugins.network","ngCordova.plugins.device","ngCordova.plugins.barcodeScanner","ngCordova.plugins.splashscreen","ngCordova.plugins.keyboard","ngCordova.plugins.contacts","ngCordova.plugins.statusbar","ngCordova.plugins.file","ngCordova.plugins.socialSharing","ngCordova.plugins.globalization","ngCordova.plugins.sqlite","ngCordova.plugins.ga","ngCordova.plugins.push","ngCordova.plugins.spinnerDialog","ngCordova.plugins.pinDialog","ngCordova.plugins.localNotification","ngCordova.plugins.toast","ngCordova.plugins.flashlight","ngCordova.plugins.capture","ngCordova.plugins.appAvailability","ngCordova.plugins.prefs"]),angular.module("ngCordova.plugins.network",[]).factory("$cordovaNetwork",[function(){return{getNetwork:function(){return navigator.connection.type},isOnline:function(){var n=navigator.connection.type;return n!==Connection.UNKNOWN&&n!==Connection.NONE},isOffline:function(){var n=navigator.connection.type;return n===Connection.UNKNOWN||n===Connection.NONE}}}]),angular.module("ngCordova.plugins.pinDialog",[]).factory("$cordovaPinDialog",[function(){return{prompt:function(){return window.plugins.pinDialog.prompt.apply(navigator.notification,arguments)}}}]),angular.module("ngCordova.plugins.prefs",[]).factory("$cordovaPreferences",["$window","$q",function(n,e){return{set:function(o,r){var t=e.defer();return n.applicationPreferences.set(o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise},get:function(o){var r=e.defer();return n.applicationPreferences.get(o,function(n){r.resolve(n)},function(n){r.reject(n)}),r.promise}}}]),angular.module("ngCordova.plugins.push",[]).factory("$cordovaPush",["$q",function(n){return{register:function(e){var o=n.defer();return window.plugins.pushNotification.register(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},unregister:function(e){var o=n.defer();return window.plugins.pushNotification.unregister(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise},setBadgeNumber:function(e){var o=n.defer();return window.plugins.pushNotification.setApplicationIconBadgeNumber(function(n){o.resolve(n)},function(n){o.reject(n)},e),o.promise}}}]),angular.module("ngCordova.plugins.socialSharing",[]).factory("$cordovaSocialSharing",["$q",function(n){return{shareViaTwitter:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaTwitter(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaWhatsApp:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaWhatsApp(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaFacebook:function(e,o,r){var t=n.defer();return window.plugins.socialsharing.shareViaFacebook(e,o,r,function(){t.resolve(!0)},function(){t.reject(!1)}),t.promise},shareViaSMS:function(e,o){var r=n.defer();return window.plugins.socialsharing.shareViaSMS(e,o,function(){r.resolve(!0)},function(){r.reject(!1)}),r.promise},shareViaEmail:function(e){var o=n.defer();return window.plugins.socialsharing.shareViaEmail(e,number,function(){o.resolve(!0)},function(){o.reject(!1)}),o.promise},canShareVia:function(e,o,r,t){var i=n.defer();return window.plugins.socialsharing.canShareVia(e,o,r,t,function(n){i.resolve(n)},function(n){i.reject(n)}),i.promise}}}]),angular.module("ngCordova.plugins.spinnerDialog",[]).factory("$cordovaSpinnerDialog",[function(){return{show:function(n,e){return window.plugins.spinnerDialog.show(n,e)},hide:function(){return window.plugins.spinnerDialog.hide()}}}]),angular.module("ngCordova.plugins.splashscreen",[]).factory("$cordovaSplashscreen",[function(){return{hide:function(){return navigator.splashscreen.hide()},show:function(){return navigator.splashscreen.show()}}}]),angular.module("ngCordova.plugins.sqlite",[]).factory("$cordovaSQLite",["$q",function(n){return{openDB:function(n){return window.sqlitePlugin.openDatabase({name:n})},openDBBackground:function(n){return window.sqlitePlugin.openDatabase({name:n,bgType:1})},execute:function(e,o,r){return q=n.defer(),e.transaction(function(n){n.executeSql(o,r,function(n,e){q.resolve(e)},function(n,e){q.reject(e)})}),q.promise},nestedExecute:function(e,o,r,t,i){return q=n.defer(),e.transaction(function(n){n.executeSql(o,t,function(n,e){q.resolve(e),n.executeSql(r,i,function(n,e){q.resolve(e)})})},function(n,e){q.reject(e)}),q.promise}}}]),angular.module("ngCordova.plugins.statusbar",[]).factory("$cordovaStatusbar",[function(){return{overlaysWebView:function(){return StatusBar.overlaysWebView(!0)},style:function(n){switch(n){case 0:return StatusBar.styleDefault();case 1:return StatusBar.styleLightContent();case 2:return StatusBar.styleBlackTranslucent();case 3:return StatusBar.styleBlackOpaque();default:return StatusBar.styleDefault()}},styleColor:function(n){return StatusBar.backgroundColorByName(n)},styleHex:function(n){return StatusBar.backgroundColorByHexString(n)},hide:function(){return StatusBar.hide()},show:function(){return StatusBar.show()},isVisible:function(){return StatusBar.isVisible()}}}]),angular.module("ngCordova.plugins.toast",[]).factory("$cordovaToast",["$q",function(n){return{showShortTop:function(e){var o=n.defer();return window.plugins.toast.showShortTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortCenter:function(e){var o=n.defer();return window.plugins.toast.showShortCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showShortBottom:function(e){var o=n.defer();return window.plugins.toast.showShortBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongTop:function(e){var o=n.defer();return window.plugins.toast.showLongTop(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongCenter:function(e){var o=n.defer();return window.plugins.toast.showLongCenter(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},showLongBottom:function(e){var o=n.defer();return window.plugins.toast.showLongBottom(e,function(n){o.resolve(n)},function(n){o.reject(n)}),o.promise},show:function(e,o,r){var t=n.defer();return window.plugins.toast.show(e,o,r,function(n){t.resolve(n)},function(n){t.reject(n)}),t.promise}}}]),angular.module("ngCordova.plugins.vibration",[]).factory("$cordovaVibration",[function(){return{vibrate:function(n){return navigator.notification.vibrate(n)},vibrateWithPattern:function(n,e){return navigator.notification.vibrateWithPattern(n,e)},cancelVibration:function(){return navigator.notification.cancelVibration()}}}])}(); \ No newline at end of file diff --git a/src/plugins/deviceMotion.js b/src/plugins/deviceMotion.js index fbfc89a4..4d03fc59 100644 --- a/src/plugins/deviceMotion.js +++ b/src/plugins/deviceMotion.js @@ -18,15 +18,18 @@ angular.module('ngCordova.plugins.deviceMotion', []) watchAcceleration: function(options) { var q = $q.defer(); - var watchID = navigator.accelerometer.watchAcceleration(function(result) { + var watchId = navigator.accelerometer.watchAcceleration(function(result) { // Do any magic you need - q.resolve(watchID); + //q.resolve(watchID); q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { return navigator.accelerometer.clearWatch(watchID); diff --git a/src/plugins/deviceOrientation.js b/src/plugins/deviceOrientation.js index 73760804..4b46b1fc 100644 --- a/src/plugins/deviceOrientation.js +++ b/src/plugins/deviceOrientation.js @@ -17,14 +17,16 @@ angular.module('ngCordova.plugins.deviceOrientation', []) watchHeading: function(options) { var q = $q.defer(); - var watchID = navigator.compass.watchHeading(function(result) { - q.resolve(watchID); + var watchId = navigator.compass.watchHeading(function(result) { q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) { navigator.compass.clearWatch(); diff --git a/src/plugins/geolocation.js b/src/plugins/geolocation.js index a5e26155..dac6bd0b 100644 --- a/src/plugins/geolocation.js +++ b/src/plugins/geolocation.js @@ -20,14 +20,16 @@ angular.module('ngCordova.plugins.geolocation', []) var watchId = navigator.geolocation.watchPosition(function(result) { // Do any magic you need - q.resolve(watchID); q.notify(result); }, function(err) { q.reject(err); }, options); - return q.promise; + return { + watchId: watchId, + promise: q.promise + } }, clearWatch: function(watchID) {