Merged in latest.

This commit is contained in:
filmaj
2010-08-25 22:32:31 -07:00
17 changed files with 570 additions and 1681 deletions
+49 -10
View File
@@ -6,7 +6,7 @@ if (typeof(DeviceInfo) != 'object')
* information about the state of PhoneGap.
* @class
*/
PhoneGap = {
var PhoneGap = {
queue: {
ready: true,
commands: [],
@@ -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
@@ -137,6 +136,19 @@ PhoneGap.addConstructor = function(func) {
});
};
/**
* Adds a plugin object to window.plugins
*/
PhoneGap.addPlugin = function(name, obj) {
if ( !window.plugins ) {
window.plugins = {};
}
if ( !window.plugins[name] ) {
window.plugins[name] = obj;
}
}
/**
* onDOMContentLoaded channel is fired when the DOM content
* of the page has been parsed.
@@ -152,9 +164,7 @@ 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.
try {
if (_nativeReady) { PhoneGap.onNativeReady.fire(); }
} catch (e) { }
if (typeof _nativeReady !== 'undefined') { PhoneGap.onNativeReady.fire(); }
/**
* onDeviceReady is fired only after both onDOMContentLoaded and
@@ -193,7 +203,21 @@ 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.subscribeOnce(handler);
} else {
PhoneGap._document_addEventListener.call(document, evt, handler);
}
};
PhoneGap.callbackId = 0;
PhoneGap.callbacks = {};
/**
* Execute a PhoneGap command in a queued fashion, to ensure commands do not
@@ -202,12 +226,27 @@ document.addEventListener = function(evt, handler, capture) {
* @param {String} command Command to be run in PhoneGap, e.g. "ClassName.method"
* @param {String[]} [args] Zero or more arguments to pass to the method
*/
PhoneGap.exec = function() {
PhoneGap.queue.commands.push(arguments);
if (PhoneGap.queue.timer == null)
PhoneGap.queue.timer = setInterval(PhoneGap.run_command, 10);
PhoneGap.exec = function(clazz, action, args) {
return CommandManager.exec(clazz, action, callbackId, JSON.stringify(args), false);
};
PhoneGap.execAsync = function(success, fail, clazz, action, args) {
var callbackId = clazz + PhoneGap.callbackId++;
PhoneGap.callbacks[callbackId] = {success:success, fail:fail};
return CommandManager.exec(clazz, action, callbackId, JSON.stringify(args), true);
};
PhoneGap.callbackSuccess = function(callbackId, args) {
PhoneGap.callbacks[callbackId].success(args);
delete PhoneGap.callbacks[callbackId];
};
PhoneGap.callbackError = function(callbackId, args) {
PhoneGap.callbacks[callbackId].fail(args);
delete PhoneGap.callbacks[callbackId];
};
/**
* Internal function used to dispatch the request to PhoneGap. It processes the
* command queue and executes the next command on the list. If one of the
@@ -324,7 +363,7 @@ PhoneGap.UUIDcreatePart = function(length) {
};
PhoneGap.close = function(context, func, params) {
if (null == params) {
if (typeof params === 'undefined') {
return function() {
return func.apply(context, arguments);
}