Make sure JavaScript PhoneGap code is initialized and deviceready is fired for a new HTML page loaded from link in initial index.html.

This commit is contained in:
Bryce Curtis
2010-08-24 13:19:22 -05:00
parent 9f1730ae47
commit 13679fe00d
2 changed files with 29 additions and 4 deletions
+11 -3
View File
@@ -110,7 +110,7 @@ PhoneGap.Channel.join = function(h, c) {
(!c[j].fired?c[j].subscribeOnce(f):i--);
}
if (!i) h();
}
};
/**
@@ -152,7 +152,9 @@ PhoneGap.onNativeReady = new PhoneGap.Channel();
// _nativeReady is global variable that the native side can set
// to signify that the native code is ready. It is a global since
// it may be called before any PhoneGap JS is ready.
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
try {
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
} catch (e) { }
/**
* onDeviceReady is fired only after both onDOMContentLoaded and
@@ -166,6 +168,11 @@ PhoneGap.onDeviceReady.subscribeOnce(function() {
PhoneGap.Channel.join(function() {
PhoneGap.onDeviceReady.fire();
// Fire the onresume event, since first one happens before JavaScript is loaded
var e = document.createEvent('Events');
e.initEvent('onresume');
document.dispatchEvent(e);
}, [ PhoneGap.onDOMContentLoaded, PhoneGap.onNativeReady ]);
@@ -326,4 +333,5 @@ PhoneGap.close = function(context, func, params) {
return func.apply(context, params);
}
}
}
};