added onNativeReady and onDOMContentLoaded events

This commit is contained in:
Dave Johnson 2010-07-22 13:05:41 -07:00
parent 3365dba870
commit 742910f369
3 changed files with 20 additions and 1695 deletions

File diff suppressed because it is too large Load Diff

View File

@ -112,7 +112,6 @@ PhoneGap.Channel.join = function(h, c) {
if (!i) h();
};
/**
* Boolean flag indicating if the PhoneGap API is available and initialized.
*/ // TODO: Remove this, it is unused here ... -jm
@ -193,6 +192,20 @@ document.addEventListener = function(evt, handler, capture) {
}
};
// Intercept calls to document.addEventListener and watch for deviceready
PhoneGap._document_addEventListener = document.addEventListener;
document.addEventListener = function(evt, handler, capture) {
if (evt.toLowerCase() == 'deviceready') {
PhoneGap.onDeviceReady.sob(handler);
} else {
PhoneGap._document_addEventListener.call(document, evt, handler);
}
};
/**
* Execute a PhoneGap command in a queued fashion, to ensure commands do not
* execute with any race conditions, and only run when PhoneGap is ready to
@ -331,5 +344,4 @@ PhoneGap.close = function(context, func, params) {
return func.apply(context, params);
}
}
};
};

View File

@ -134,6 +134,11 @@ public class DroidGap extends Activity {
root.addView(appView);
// Try firing the onNativeReady event in JS. If it fails because the JS is
// not loaded yet then just set a flag so that the onNativeReady can be fired
// from the JS side when the JS gets to that code.
appView.loadUrl("javascript:try{PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
setContentView(root);
}