-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathSweetAlert.js
102 lines (92 loc) · 3.34 KB
/
SweetAlert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
@fileOverview
@toc
*/
(function (root, factory) {
"use strict";
/*global define*/
if (typeof define === 'function' && define.amd) {
define(['angular', 'sweetalert'], factory); // AMD
} else if (typeof module === 'object' && module.exports) {
module.exports = factory(require('angular'), require('sweetalert')); // Node
} else {
factory(root.angular, root.swal); // Browser
}
}(this, function (angular, swal) {
"use strict";
angular.module('oitozero.ngSweetAlert', [])
.factory('SweetAlert', ['$rootScope', 'SweetAlertConfig', function ($rootScope, SweetAlertConfig) {
//public methods
var self = {
swal: function (arg1, arg2, arg3) {
//merge with default config
var arg1 = angular.extend(SweetAlertConfig, arg1);
$rootScope.$evalAsync(function () {
if (typeof(arg2) === 'function') {
swal(arg1, function (isConfirm) {
$rootScope.$evalAsync(function () {
arg2(isConfirm);
});
}, arg3);
} else {
swal(arg1, arg2, arg3);
}
});
},
success: function (title, message) {
$rootScope.$evalAsync(function () {
swal(title, message, 'success');
});
},
error: function (title, message) {
$rootScope.$evalAsync(function () {
swal(title, message, 'error');
});
},
warning: function (title, message) {
$rootScope.$evalAsync(function () {
swal(title, message, 'warning');
});
},
info: function (title, message) {
$rootScope.$evalAsync(function () {
swal(title, message, 'info');
});
},
showInputError: function (message) {
$rootScope.$evalAsync(function () {
swal.showInputError(message);
});
},
close: function () {
$rootScope.$evalAsync(function () {
swal.close();
});
}
};
return self;
}]).constant('SweetAlertConfig', {
title: '',
text: '',
type: null,
allowOutsideClick: false,
showConfirmButton: true,
showCancelButton: false,
closeOnConfirm: true,
closeOnCancel: true,
confirmButtonText: 'OK',
confirmButtonColor: '#8CD4F5',
cancelButtonText: 'Cancel',
imageUrl: null,
imageSize: null,
timer: null,
customClass: '',
html: false,
animation: true,
allowEscapeKey: true,
inputType: 'text',
inputPlaceholder: '',
inputValue: '',
showLoaderOnConfirm: false
});
}));