Add toast plugin

This commit is contained in:
Yemel Jardi 2014-08-13 13:33:56 -03:00
commit 7d27ff70cb
5 changed files with 173 additions and 1 deletions

View file

@ -0,0 +1,59 @@
cordova.define("nl.x-services.plugins.toast.tests", function(require, exports, module) { exports.defineAutoTests = function() {
var fail = function (done) {
expect(true).toBe(false);
done();
},
succeed = function (done) {
expect(true).toBe(true);
done();
};
describe('Plugin availability', function () {
it("window.plugins.toast should exist", function() {
expect(window.plugins.toast).toBeDefined();
});
});
describe('API functions', function () {
it("should define show", function() {
expect(window.plugins.toast.show).toBeDefined();
});
it("should define showShortTop", function() {
expect(window.plugins.toast.showShortTop).toBeDefined();
});
it("should define showShortCenter", function() {
expect(window.plugins.toast.showShortCenter).toBeDefined();
});
it("should define showShortBottom", function() {
expect(window.plugins.toast.showShortBottom).toBeDefined();
});
it("should define showLongTop", function() {
expect(window.plugins.toast.showLongTop).toBeDefined();
});
it("should define showLongCenter", function() {
expect(window.plugins.toast.showLongCenter).toBeDefined();
});
it("should define showLongBottom", function() {
expect(window.plugins.toast.showLongBottom).toBeDefined();
});
});
describe('Invalid usage', function () {
it("should fail due to an invalid position", function(done) {
window.plugins.toast.show('hi', 'short', 'nowhere', fail.bind(null, done), succeed.bind(null, done));
});
it("should fail due to an invalid duration", function(done) {
window.plugins.toast.show('hi', 'medium', 'top', fail.bind(null, done), succeed.bind(null, done));
});
});
};
});

View file

@ -0,0 +1,42 @@
cordova.define("nl.x-services.plugins.toast.Toast", function(require, exports, module) { function Toast() {
}
Toast.prototype.show = function (message, duration, position, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Toast", "show", [message, duration, position]);
};
Toast.prototype.showShortTop = function (message, successCallback, errorCallback) {
this.show(message, "short", "top", successCallback, errorCallback);
};
Toast.prototype.showShortCenter = function (message, successCallback, errorCallback) {
this.show(message, "short", "center", successCallback, errorCallback);
};
Toast.prototype.showShortBottom = function (message, successCallback, errorCallback) {
this.show(message, "short", "bottom", successCallback, errorCallback);
};
Toast.prototype.showLongTop = function (message, successCallback, errorCallback) {
this.show(message, "long", "top", successCallback, errorCallback);
};
Toast.prototype.showLongCenter = function (message, successCallback, errorCallback) {
this.show(message, "long", "center", successCallback, errorCallback);
};
Toast.prototype.showLongBottom = function (message, successCallback, errorCallback) {
this.show(message, "long", "bottom", successCallback, errorCallback);
};
Toast.install = function () {
if (!window.plugins) {
window.plugins = {};
}
window.plugins.toast = new Toast();
return window.plugins.toast;
};
cordova.addConstructor(Toast.install);
});