sweetalert.js
4.42 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
$(document).ready(function () {
$('#basic').on('click', function () {
Swal.fire('Hello! This is a Basic Message.')
});
$('#basic-title').on('click', function () {
Swal.fire(
'The Internet?',
'That thing is still around?',
'question'
)
});
$('#success').on('click', function () {
Swal.fire({
icon: 'success',
title: 'Your work has been saved',
showConfirmButton: false,
})
});
$('#info').on('click', function () {
Swal.fire({
icon: 'info',
title: 'Good Job!',
showConfirmButton: false,
})
});
$('#warning').on('click', function () {
Swal.fire({
icon: 'warning',
title: 'Changes are not saved',
showConfirmButton: false,
})
});
$('#danger').on('click', function () {
Swal.fire({
icon: 'error',
title: 'OOps!!',
text: 'Something went Wrong',
showConfirmButton: false,
})
});
$('#confirmation').on('click', function () {
Swal.fire({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
Swal.fire("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
} else {
Swal.fire("Your imaginary file is safe!");
}
});
});
$('#custom-buttons').on('click', function () {
Swal.fire("A wild Pikachu appeared! What do you want to do?", {
buttons: {
cancel: "Run away!",
catch: {
text: "Throw Pokéball!",
value: "catch",
},
defeat: true,
},
})
.then((value) => {
switch (value) {
case "defeat":
Swal.fire("Pikachu fainted! You gained 500 XP!");
break;
case "catch":
Swal.fire("Gotcha!", "Pikachu was caught!", "success");
break;
default:
Swal.fire("Got away safely!");
}
});
});
$('#ajax-request').on('click', function () {
Swal.fire({
text: 'Search for a movie. e.g. "La La Land".',
content: "input",
button: {
text: "Search!",
closeModal: false,
},
})
.then(name => {
if (!name) throw null;
return fetch(`https://itunes.apple.com/search?term=${name}&entity=movie`);
})
.then(results => {
return results.json();
})
.then(json => {
const movie = json.results[0];
if (!movie) {
return Swal.fire("No movie was found!");
}
const name = movie.trackName;
const imageURL = movie.artworkUrl100;
Swal.fire({
title: "Top result:",
text: name,
icon: imageURL,
});
})
.catch(err => {
if (err) {
Swal.fire("Oh noes!", "The AJAX request failed!", "error");
} else {
Swal.fire.stopLoading();
Swal.fire.close();
}
});
});
$('#form-input').on('click', function () {
Swal.fire("Write something here:", {
content: "input",
})
.then((value) => {
Swal.fire(`You typed: ${value}`);
});
});
});