#4 Upgrading the JS API to prepare for custom options (no additional options yet, this is a change to make that possible in the future)

This commit is contained in:
eddyverbruggen@gmail.com
2015-04-22 21:51:38 +02:00
parent 75819ee95e
commit 6d4c052a12
4 changed files with 93 additions and 21 deletions
+46 -1
View File
@@ -1,8 +1,53 @@
function Toast() {
}
Toast.prototype.optionsBuilder = function () {
// defaults
var message = null;
var duration = "short";
var position = "center";
return {
withMessage: function(m) {
message = m;
return this;
},
withDuration: function(d) {
duration = d;
return this;
},
withPosition: function(p) {
position = p;
return this;
},
build: function() {
return {
message: message,
duration: duration,
position: position
}
}
}
};
Toast.prototype.showWithOptions = function (options, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Toast", "show", [options]);
};
Toast.prototype.show = function (message, duration, position, successCallback, errorCallback) {
cordova.exec(successCallback, errorCallback, "Toast", "show", [message, duration, position]);
this.showWithOptions(
this.optionsBuilder()
.withMessage(message)
.withDuration(duration)
.withPosition(position)
.build(),
successCallback,
errorCallback);
};
Toast.prototype.showShortTop = function (message, successCallback, errorCallback) {