Skip to content

Instantly share code, notes, and snippets.

@elidupuis
Last active August 29, 2015 14:00
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 elidupuis/11268907 to your computer and use it in GitHub Desktop.
Save elidupuis/11268907 to your computer and use it in GitHub Desktop.
Combining Cordova deviceready and domready in a Component(1) app
{
"locals": [
"foobar"
],
"dependencies": {
"jb55/domready": "*"
},
"scripts": [
"index.js"
]
}
var domready = require('domready');
var foobar = require('foobar');
var isPhone = false;
// see http://stackoverflow.com/questions/12576062/jquery-document-ready-vs-phonegap-deviceready#answer-14109006
domready(function() {
// are we running in native app or in a browser?
if('file:' === document.location.protocol) {
isPhone = true;
}
if(isPhone) {
document.addEventListener("deviceready", onDeviceReady, false);
} else {
onDeviceReady();
}
});
function onDeviceReady () {
console.log('deviceready! get it on.')
foobar.init();
}
@elidupuis
Copy link
Author

Is there any difference between document.location.href and document.URL?

Also, it's probably simpler to set isphone to true if 'file:' === document.location.protocol; at least for Cordova apps...

And I'd prefer if isphone wasn't on the window object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment