Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

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); */

Clone this wiki locally