Created
November 20, 2014 07:12
-
-
Save rikschennink/bdc522f78f6a3cf3b3a8 to your computer and use it in GitHub Desktop.
Cordova Plugin API Defintion
This file contains hidden or 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
(function(cordova){ | |
'use strict'; | |
var exports = {},method; | |
// Plugin Definition | |
var plugin = { | |
name:'<PluginName>', | |
api:{ | |
'<methodName>':function(success,failure,options){ | |
return { | |
success:success, | |
failure:failure, | |
params:[ | |
options.foo, | |
options.bar, | |
options.baz | |
] | |
}; | |
} | |
} | |
}; | |
// Generates Cordova Plugin API | |
for (method in plugin.api) { | |
if (!plugin.api.hasOwnProperty(method)){continue;} | |
exports[method] = (function(name,setup){ | |
return function() { | |
var config = setup ? setup.apply(this,arguments) || {} : {}; | |
cordova.exec( | |
config.success || null, | |
config.failure || null, | |
plugin.name, | |
name, | |
config.params || [] | |
); | |
}; | |
}(method,plugin.api[method])); | |
} | |
// expose | |
if (!window.plugins) {window.plugins = {};} | |
window.plugins[plugin.name.charAt(0).toLowerCase() + plugin.name.slice(1)] = exports; | |
}(window.cordova)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment