Add error checking for PhoneGap.addPlugin().

This commit is contained in:
Bryce Curtis 2010-11-11 21:58:07 -06:00
parent 4f1bc1401f
commit 1428ac5ed5

View File

@ -167,16 +167,23 @@ PhoneGap.addConstructor = function(func) {
}; };
/** /**
* Adds a plugin object to window.plugins * Adds a plugin object to window.plugins.
* The plugin is accessed using window.plugins.<name>
*
* @param name The plugin name
* @param obj The plugin object
*/ */
PhoneGap.addPlugin = function(name, obj) { PhoneGap.addPlugin = function(name, obj) {
if ( !window.plugins ) { if (!window.plugins) {
window.plugins = {}; window.plugins = {};
} }
if ( !window.plugins[name] ) { if (!window.plugins[name]) {
window.plugins[name] = obj; window.plugins[name] = obj;
} }
else {
console.log("Error: Plugin "+name+" already exists.");
}
} }
/** /**
@ -737,4 +744,4 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) {
} }
el.src = jsfile; el.src = jsfile;
id.appendChild(el); id.appendChild(el);
} };