Last active
September 12, 2018 17:15
-
-
Save htulipe/44d899e56e2526a82e46 to your computer and use it in GitHub Desktop.
Wait for Phonegap's deviceready event before initializing an Ember application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import isOnCordova from '../utils/is-on-cordova'; | |
export function initialize(container, application) { | |
application.deferReadiness(); | |
document.addEventListener('deviceready', function() { | |
application.advanceReadiness(); | |
}, false); | |
if(!isOnCordova()){ | |
document.dispatchEvent(new Event('deviceready')); | |
} | |
} | |
export default { | |
name: 'cordova-device-ready', | |
initialize: initialize | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function isOnCordova() { | |
return !!window.cordova; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, thank you for this!
Two little things: L3 doesn't need
container
as an argument in the initialize function and in L15 can be justinitialize
This is using ember 2.6