Skip to content

Instantly share code, notes, and snippets.

@shanebo
Created June 21, 2013 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shanebo/5834347 to your computer and use it in GitHub Desktop.
Save shanebo/5834347 to your computer and use it in GitHub Desktop.
A cleaner PhoneGap/Cordova cordova.exec api.
/*
A cleaner PhoneGap/Cordova cordova.exec API:
native(plugin.action, args, success, fail);
plugin.action = dot plugin/action separated string
args = anything (optional)
success = function (optional)
fail = function (optional)
This allows calls like:
var success = function(){
console.log('success');
};
var fail = function(){
console.log('fail');
};
native('Foo.bar', 'hello world', success, fail);
native('Foo.bar', success, fail);
native('Foo.bar');
*/
var native = function(pluginAction, args, success, fail){
var route = pluginAction.split('.');
if (typeof args === 'function') {
cordova.exec(args, success||null, route[0], route[1], []);
} else {
args = args === undefined ? [] : [args];
cordova.exec(success||null, fail||null, route[0], route[1], args);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment