forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Defining Your Cordova Plugin As A Cordova Module
shazron edited this page Sep 4, 2012
·
2 revisions
cordova.define("cordova/plugin/myplugin", function(require, exports, module) {
var exec = require('cordova/exec');
var MyPlugin = function() {};
MyPlugin.prototype.foo = function(successCallback,failureCallback) {
exec(successCallback, failureCallback, 'MyPlugin', 'foo', []);
}
MyPlugin.prototype.bar = function(successCallback,failureCallback) {
exec(successCallback, failureCallback, 'MyPlugin', 'bar', []);
}
MyPlugin.prototype.baz = function(successCallback,failureCallback) {
exec(successCallback, failureCallback, 'MyPlugin', 'baz', []);
}
var myplugin = new MyPlugin();
module.exports = myplugin;
});
/* //usage:
var mp = cordova.require("cordova/plugin/myplugin");
var win = function() { alert('win!'); }
var fail = function() { alert('fail!'); }
mp.foo(win, fail);
mp.bar(win, fail);
mp.baz(win, fail);
*/