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

Commit 99fd847

Browse files
author
Jordi Moraleda
authored
Adding support for toast.showWithOptions
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!
1 parent e4d716e commit 99fd847

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/plugins/toast.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// install : cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
1+
// install : cordova plugin add cordova-plugin-x-toast
22
// link : https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin
33

44
angular.module('ngCordova.plugins.toast', [])
@@ -8,6 +8,11 @@ angular.module('ngCordova.plugins.toast', [])
88
return {
99
showShortTop: function (message) {
1010
var q = $q.defer();
11+
if(!$window.plugins || !$window.plugins.toast) {
12+
console.error('The toast plugin is not installed');
13+
return q.reject('The toast plugin is not installed');
14+
}
15+
1116
$window.plugins.toast.showShortTop(message, function (response) {
1217
q.resolve(response);
1318
}, function (error) {
@@ -18,6 +23,11 @@ angular.module('ngCordova.plugins.toast', [])
1823

1924
showShortCenter: function (message) {
2025
var q = $q.defer();
26+
if(!$window.plugins || !$window.plugins.toast) {
27+
console.error('The toast plugin is not installed');
28+
return q.reject('The toast plugin is not installed');
29+
}
30+
2131
$window.plugins.toast.showShortCenter(message, function (response) {
2232
q.resolve(response);
2333
}, function (error) {
@@ -28,6 +38,11 @@ angular.module('ngCordova.plugins.toast', [])
2838

2939
showShortBottom: function (message) {
3040
var q = $q.defer();
41+
if(!$window.plugins || !$window.plugins.toast) {
42+
console.error('The toast plugin is not installed');
43+
return q.reject('The toast plugin is not installed');
44+
}
45+
3146
$window.plugins.toast.showShortBottom(message, function (response) {
3247
q.resolve(response);
3348
}, function (error) {
@@ -38,6 +53,11 @@ angular.module('ngCordova.plugins.toast', [])
3853

3954
showLongTop: function (message) {
4055
var q = $q.defer();
56+
if(!$window.plugins || !$window.plugins.toast) {
57+
console.error('The toast plugin is not installed');
58+
return q.reject('The toast plugin is not installed');
59+
}
60+
4161
$window.plugins.toast.showLongTop(message, function (response) {
4262
q.resolve(response);
4363
}, function (error) {
@@ -48,6 +68,11 @@ angular.module('ngCordova.plugins.toast', [])
4868

4969
showLongCenter: function (message) {
5070
var q = $q.defer();
71+
if(!$window.plugins || !$window.plugins.toast) {
72+
console.error('The toast plugin is not installed');
73+
return q.reject('The toast plugin is not installed');
74+
}
75+
5176
$window.plugins.toast.showLongCenter(message, function (response) {
5277
q.resolve(response);
5378
}, function (error) {
@@ -58,6 +83,11 @@ angular.module('ngCordova.plugins.toast', [])
5883

5984
showLongBottom: function (message) {
6085
var q = $q.defer();
86+
if(!$window.plugins || !$window.plugins.toast) {
87+
console.error('The toast plugin is not installed');
88+
return q.reject('The toast plugin is not installed');
89+
}
90+
6191
$window.plugins.toast.showLongBottom(message, function (response) {
6292
q.resolve(response);
6393
}, function (error) {
@@ -66,8 +96,33 @@ angular.module('ngCordova.plugins.toast', [])
6696
return q.promise;
6797
},
6898

99+
showWithOptions: function (message, duration, position, styling) {
100+
var q = $q.defer();
101+
if(!$window.plugins || !$window.plugins.toast) {
102+
console.error('The toast plugin is not installed');
103+
return q.reject('The toast plugin is not installed');
104+
}
105+
106+
$window.plugins.toast.showWithOptions({
107+
message: message,
108+
duration: duration,
109+
position: position,
110+
styling: styling
111+
}, function (response) {
112+
q.resolve(response);
113+
}, function (error) {
114+
q.reject(error);
115+
});
116+
return q.promise;
117+
},
118+
69119
show: function (message, duration, position) {
70120
var q = $q.defer();
121+
if(!$window.plugins || !$window.plugins.toast) {
122+
console.error('The toast plugin is not installed');
123+
return q.reject('The toast plugin is not installed');
124+
}
125+
71126
$window.plugins.toast.show(message, duration, position, function (response) {
72127
q.resolve(response);
73128
}, function (error) {
@@ -78,6 +133,10 @@ angular.module('ngCordova.plugins.toast', [])
78133

79134
hide: function () {
80135
var q = $q.defer();
136+
if(!$window.plugins || !$window.plugins.toast) {
137+
console.error('The toast plugin is not installed');
138+
return q.reject('The toast plugin is not installed');
139+
}
81140
try {
82141
$window.plugins.toast.hide();
83142
q.resolve();

0 commit comments

Comments
 (0)