mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-20 23:56:20 +08:00
added onNativeReady and onDOMContentLoaded events
This commit is contained in:
parent
3365dba870
commit
742910f369
1692
example/phonegap.js
1692
example/phonegap.js
File diff suppressed because it is too large
Load Diff
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user