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

Commit

Permalink
Adding support for toast.showWithOptions
Browse files Browse the repository at this point in the history
Version 2.4 of cordovaplugin-x-toast allows to provide styling for the toast messages.

  window.plugins.toast.showWithOptions({
    message: "hey there",
    duration: "short", // 2000 ms
    position: "bottom",
    styling: {
      opacity: 0.75, // 0.0 (transparent) to 1.0 (opaque). Default 0.8
      backgroundColor: '#FF0000', // make sure you use #RRGGBB. Default #333333
      textColor: '#FFFF00', // Ditto. Default #FFFFFF
      textSize: 20.5, // Default is approx. 13.
      cornerRadius: 16, // minimum is 0 (square). iOS default 20, Android default 100
      horizontalPadding: 20, // iOS default 16, Android default 50
      verticalPadding: 16 // iOS default 12, Android default 30
    }
  });

Also, the cordova plugin name is updated and some control code is added to prevent runtime errors if the plugin is not yet installed. 
Thank you!
  • Loading branch information
Jordi Moraleda authored Jun 18, 2016
1 parent e4d716e commit 99fd847
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/plugins/toast.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// install : cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
// install : cordova plugin add cordova-plugin-x-toast
// link : https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin

angular.module('ngCordova.plugins.toast', [])
Expand All @@ -8,6 +8,11 @@ angular.module('ngCordova.plugins.toast', [])
return {
showShortTop: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showShortTop(message, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -18,6 +23,11 @@ angular.module('ngCordova.plugins.toast', [])

showShortCenter: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showShortCenter(message, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -28,6 +38,11 @@ angular.module('ngCordova.plugins.toast', [])

showShortBottom: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showShortBottom(message, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -38,6 +53,11 @@ angular.module('ngCordova.plugins.toast', [])

showLongTop: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showLongTop(message, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -48,6 +68,11 @@ angular.module('ngCordova.plugins.toast', [])

showLongCenter: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showLongCenter(message, function (response) {
q.resolve(response);
}, function (error) {

This comment has been minimized.

Copy link
@Sherryberry31
Expand All @@ -58,6 +83,11 @@ angular.module('ngCordova.plugins.toast', [])

showLongBottom: function (message) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showLongBottom(message, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -66,8 +96,33 @@ angular.module('ngCordova.plugins.toast', [])
return q.promise;
},

showWithOptions: function (message, duration, position, styling) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.showWithOptions({
message: message,
duration: duration,
position: position,
styling: styling
}, function (response) {
q.resolve(response);
}, function (error) {
q.reject(error);
});
return q.promise;
},

show: function (message, duration, position) {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}

$window.plugins.toast.show(message, duration, position, function (response) {
q.resolve(response);
}, function (error) {
Expand All @@ -78,6 +133,10 @@ angular.module('ngCordova.plugins.toast', [])

hide: function () {
var q = $q.defer();
if(!$window.plugins || !$window.plugins.toast) {
console.error('The toast plugin is not installed');
return q.reject('The toast plugin is not installed');
}
try {
$window.plugins.toast.hide();
q.resolve();
Expand Down

0 comments on commit 99fd847

Please sign in to comment.