Skip to content

Instantly share code, notes, and snippets.

@elegantcoder
Last active February 25, 2016 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elegantcoder/1de8ff7068bbc0ce1e28 to your computer and use it in GitHub Desktop.
Save elegantcoder/1de8ff7068bbc0ce1e28 to your computer and use it in GitHub Desktop.
/*cordova-deviceready-$q*/
'use strict';
angular.module('elcoCordova', [])
.factory('elcoCordova.onDeviceReady', [
'$q',
'$log',
function ($q, console) {
console.log('elcoCordova.onDeviceReady');
var deferred = $q.defer();
if (!window.cordova) {
setTimeout(function () {
deferred.resolve();
}, 100)
} else if (window.deviceReady) {
console.log('elcoCordova.onDeviceReady', 'window.deviceReady', window.deviceReady);
deferred.resolve();
} else {
console.log('wait for device ready');
document.addEventListener('deviceready', function () {
console.log('document, deviceready emit');
deferred.resolve();
}, false);
}
return deferred.promise;
}
]);
<script>
window.deviceReady = false;
window.onDeviceReady = function () {
console.log('DeviceReady');
StatusBar.overlaysWebView(false);
StatusBar.styleDefault();
window.deviceReady = true;
};
document.addEventListener("deviceready", window.onDeviceReady, false);
</script>
<script src="cordova.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment