Created
June 21, 2013 21:11
-
-
Save shanebo/5834347 to your computer and use it in GitHub Desktop.
A cleaner PhoneGap/Cordova cordova.exec api.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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