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

Adding support for toast.showWithOptions #1273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
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