sweetalert2.js
46.5 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
/*!
* sweetalert2 v6.4.4
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Sweetalert2 = factory());
}(this, (function () { 'use strict';
var defaultParams = {
title: '',
titleText: '',
text: '',
html: '',
type: null,
customClass: '',
target: 'body',
animation: true,
allowOutsideClick: true,
allowEscapeKey: true,
allowEnterKey: true,
showConfirmButton: true,
showCancelButton: false,
preConfirm: null,
confirmButtonText: 'OK',
confirmButtonColor: '#3085d6',
confirmButtonClass: null,
cancelButtonText: 'Cancel',
cancelButtonColor: '#aaa',
cancelButtonClass: null,
buttonsStyling: true,
reverseButtons: false,
focusCancel: false,
showCloseButton: false,
showLoaderOnConfirm: false,
imageUrl: null,
imageWidth: null,
imageHeight: null,
imageClass: null,
timer: null,
width: 500,
padding: 20,
background: '#fff',
input: null,
inputPlaceholder: '',
inputValue: '',
inputOptions: {},
inputAutoTrim: true,
inputClass: null,
inputAttributes: {},
inputValidator: null,
progressSteps: [],
currentProgressStep: null,
progressStepsDistance: '40px',
onOpen: null,
onClose: null
};
var swalPrefix = 'swal2-';
var prefix = function prefix(items) {
var result = {};
for (var i in items) {
result[items[i]] = swalPrefix + items[i];
}
return result;
};
var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'spacer', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']);
var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
/*
* Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
*/
var colorLuminance = function colorLuminance(hex, lum) {
// Validate hex string
hex = String(hex).replace(/[^0-9a-f]/gi, '');
if (hex.length < 6) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
lum = lum || 0;
// Convert to decimal and change luminosity
var rgb = '#';
for (var i = 0; i < 3; i++) {
var c = parseInt(hex.substr(i * 2, 2), 16);
c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16);
rgb += ('00' + c).substr(c.length);
}
return rgb;
};
/* global MouseEvent */
// Remember state in cases where opening and handling a modal will fiddle with it.
var states = {
previousWindowKeyDown: null,
previousActiveElement: null,
previousBodyPadding: null
};
/*
* Add modal + overlay to DOM
*/
var init = function init(params) {
if (typeof document === 'undefined') {
console.error('SweetAlert2 requires document to initialize');
return;
}
var container = document.createElement('div');
container.className = swalClasses.container;
container.innerHTML = sweetHTML;
var targetElement = document.querySelector(params.target);
if (!targetElement) {
console.warn('SweetAlert2: Can\'t find the target "' + params.target + '"');
targetElement = document.body;
}
targetElement.appendChild(container);
var modal = getModal();
var input = getChildByClass(modal, swalClasses.input);
var file = getChildByClass(modal, swalClasses.file);
var range = modal.querySelector('.' + swalClasses.range + ' input');
var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output');
var select = getChildByClass(modal, swalClasses.select);
var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input');
var textarea = getChildByClass(modal, swalClasses.textarea);
input.oninput = function () {
sweetAlert.resetValidationError();
};
input.onkeydown = function (event) {
setTimeout(function () {
if (event.keyCode === 13 && params.allowEnterKey) {
event.stopPropagation();
sweetAlert.clickConfirm();
}
}, 0);
};
file.onchange = function () {
sweetAlert.resetValidationError();
};
range.oninput = function () {
sweetAlert.resetValidationError();
rangeOutput.value = range.value;
};
range.onchange = function () {
sweetAlert.resetValidationError();
range.previousSibling.value = range.value;
};
select.onchange = function () {
sweetAlert.resetValidationError();
};
checkbox.onchange = function () {
sweetAlert.resetValidationError();
};
textarea.oninput = function () {
sweetAlert.resetValidationError();
};
return modal;
};
/*
* Manipulate DOM
*/
var sweetHTML = ('\n <div role="dialog" aria-labelledby="modalTitleId" aria-describedby="modalContentId" class="' + swalClasses.modal + '" tabIndex="-1" >\n <ul class="' + swalClasses.progresssteps + '"></ul>\n <div class="' + swalClasses.icon + ' ' + iconTypes.error + '">\n <span class="x-mark"><span class="line left"></span><span class="line right"></span></span>\n </div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.question + '">?</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.warning + '">!</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.info + '">i</div>\n <div class="' + swalClasses.icon + ' ' + iconTypes.success + '">\n <span class="line tip"></span> <span class="line long"></span>\n <div class="placeholder"></div> <div class="fix"></div>\n </div>\n <img class="' + swalClasses.image + '">\n <h2 class="' + swalClasses.title + '" id="modalTitleId"></h2>\n <div id="modalContentId" class="' + swalClasses.content + '"></div>\n <input class="' + swalClasses.input + '">\n <input type="file" class="' + swalClasses.file + '">\n <div class="' + swalClasses.range + '">\n <output></output>\n <input type="range">\n </div>\n <select class="' + swalClasses.select + '"></select>\n <div class="' + swalClasses.radio + '"></div>\n <label for="' + swalClasses.checkbox + '" class="' + swalClasses.checkbox + '">\n <input type="checkbox">\n </label>\n <textarea class="' + swalClasses.textarea + '"></textarea>\n <div class="' + swalClasses.validationerror + '"></div>\n <hr class="' + swalClasses.spacer + '">\n <button type="button" role="button" tabIndex="0" class="' + swalClasses.confirm + '">OK</button>\n <button type="button" role="button" tabIndex="0" class="' + swalClasses.cancel + '">Cancel</button>\n <span class="' + swalClasses.close + '">×</span>\n </div>\n').replace(/(^|\n)\s*/g, '');
var getContainer = function getContainer() {
return document.body.querySelector('.' + swalClasses.container);
};
var getModal = function getModal() {
return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null;
};
var getIcons = function getIcons() {
var modal = getModal();
return modal.querySelectorAll('.' + swalClasses.icon);
};
var elementByClass = function elementByClass(className) {
return getContainer() ? getContainer().querySelector('.' + className) : null;
};
var getTitle = function getTitle() {
return elementByClass(swalClasses.title);
};
var getContent = function getContent() {
return elementByClass(swalClasses.content);
};
var getImage = function getImage() {
return elementByClass(swalClasses.image);
};
var getSpacer = function getSpacer() {
return elementByClass(swalClasses.spacer);
};
var getProgressSteps = function getProgressSteps() {
return elementByClass(swalClasses.progresssteps);
};
var getValidationError = function getValidationError() {
return elementByClass(swalClasses.validationerror);
};
var getConfirmButton = function getConfirmButton() {
return elementByClass(swalClasses.confirm);
};
var getCancelButton = function getCancelButton() {
return elementByClass(swalClasses.cancel);
};
var getCloseButton = function getCloseButton() {
return elementByClass(swalClasses.close);
};
var getFocusableElements = function getFocusableElements(focusCancel) {
var buttons = [getConfirmButton(), getCancelButton()];
if (focusCancel) {
buttons.reverse();
}
return buttons.concat(Array.prototype.slice.call(getModal().querySelectorAll('button:not([class^=' + swalPrefix + ']), input:not([type=hidden]), textarea, select')));
};
var hasClass = function hasClass(elem, className) {
if (elem.classList) {
return elem.classList.contains(className);
}
return false;
};
var focusInput = function focusInput(input) {
input.focus();
// place cursor at end of text in text input
if (input.type !== 'file') {
// http://stackoverflow.com/a/2345915/1331425
var val = input.value;
input.value = '';
input.value = val;
}
};
var addClass = function addClass(elem, className) {
if (!elem || !className) {
return;
}
var classes = className.split(/\s+/).filter(Boolean);
classes.forEach(function (className) {
elem.classList.add(className);
});
};
var removeClass = function removeClass(elem, className) {
if (!elem || !className) {
return;
}
var classes = className.split(/\s+/).filter(Boolean);
classes.forEach(function (className) {
elem.classList.remove(className);
});
};
var getChildByClass = function getChildByClass(elem, className) {
for (var i = 0; i < elem.childNodes.length; i++) {
if (hasClass(elem.childNodes[i], className)) {
return elem.childNodes[i];
}
}
};
var show = function show(elem, display) {
if (!display) {
display = 'block';
}
elem.style.opacity = '';
elem.style.display = display;
};
var hide = function hide(elem) {
elem.style.opacity = '';
elem.style.display = 'none';
};
var empty = function empty(elem) {
while (elem.firstChild) {
elem.removeChild(elem.firstChild);
}
};
// borrowed from jqeury $(elem).is(':visible') implementation
var isVisible = function isVisible(elem) {
return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length;
};
var removeStyleProperty = function removeStyleProperty(elem, property) {
if (elem.style.removeProperty) {
elem.style.removeProperty(property);
} else {
elem.style.removeAttribute(property);
}
};
var fireClick = function fireClick(node) {
if (!isVisible(node)) {
return false;
}
// Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/
// Then fixed for today's Chrome browser.
if (typeof MouseEvent === 'function') {
// Up-to-date approach
var mevt = new MouseEvent('click', {
view: window,
bubbles: false,
cancelable: true
});
node.dispatchEvent(mevt);
} else if (document.createEvent) {
// Fallback
var evt = document.createEvent('MouseEvents');
evt.initEvent('click', false, false);
node.dispatchEvent(evt);
} else if (document.createEventObject) {
node.fireEvent('onclick');
} else if (typeof node.onclick === 'function') {
node.onclick();
}
};
var animationEndEvent = function () {
var testEl = document.createElement('div');
var transEndEventNames = {
'WebkitAnimation': 'webkitAnimationEnd',
'OAnimation': 'oAnimationEnd oanimationend',
'msAnimation': 'MSAnimationEnd',
'animation': 'animationend'
};
for (var i in transEndEventNames) {
if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) {
return transEndEventNames[i];
}
}
return false;
}();
// Reset previous window keydown handler and focued element
var resetPrevState = function resetPrevState() {
window.onkeydown = states.previousWindowKeyDown;
if (states.previousActiveElement && states.previousActiveElement.focus) {
var x = window.scrollX;
var y = window.scrollY;
states.previousActiveElement.focus();
if (x && y) {
// IE has no scrollX/scrollY support
window.scrollTo(x, y);
}
}
};
// Measure width of scrollbar
// https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286
var measureScrollbar = function measureScrollbar() {
var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
if (supportsTouch) {
return 0;
}
var scrollDiv = document.createElement('div');
scrollDiv.style.width = '50px';
scrollDiv.style.height = '50px';
scrollDiv.style.overflow = 'scroll';
document.body.appendChild(scrollDiv);
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;
};
// JavaScript Debounce Function
// Simplivied version of https://davidwalsh.name/javascript-debounce-function
var debounce = function debounce(func, wait) {
var timeout = void 0;
return function () {
var later = function later() {
timeout = null;
func();
};
clearTimeout(timeout);
timeout = setTimeout(later, wait);
};
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var modalParams = _extends({}, defaultParams);
var queue = [];
var swal2Observer = void 0;
/*
* Set type, text and actions on modal
*/
var setParameters = function setParameters(params) {
var modal = getModal() || init(params);
for (var param in params) {
if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') {
console.warn('SweetAlert2: Unknown parameter "' + param + '"');
}
}
// set modal width and margin-left
modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width;
modal.style.padding = params.padding + 'px';
modal.style.background = params.background;
var title = getTitle();
var content = getContent();
var confirmButton = getConfirmButton();
var cancelButton = getCancelButton();
var closeButton = getCloseButton();
// Title
if (params.titleText) {
title.innerText = params.titleText;
} else {
title.innerHTML = params.title.split('\n').join('<br>');
}
// Content
if (params.text || params.html) {
if (_typeof(params.html) === 'object') {
content.innerHTML = '';
if (0 in params.html) {
for (var i = 0; i in params.html; i++) {
content.appendChild(params.html[i].cloneNode(true));
}
} else {
content.appendChild(params.html.cloneNode(true));
}
} else if (params.html) {
content.innerHTML = params.html;
} else if (params.text) {
content.textContent = params.text;
}
show(content);
} else {
hide(content);
}
// Close button
if (params.showCloseButton) {
show(closeButton);
} else {
hide(closeButton);
}
// Custom Class
modal.className = swalClasses.modal;
if (params.customClass) {
addClass(modal, params.customClass);
}
// Progress steps
var progressStepsContainer = getProgressSteps();
var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10);
if (params.progressSteps.length) {
show(progressStepsContainer);
empty(progressStepsContainer);
if (currentProgressStep >= params.progressSteps.length) {
console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
}
params.progressSteps.forEach(function (step, index) {
var circle = document.createElement('li');
addClass(circle, swalClasses.progresscircle);
circle.innerHTML = step;
if (index === currentProgressStep) {
addClass(circle, swalClasses.activeprogressstep);
}
progressStepsContainer.appendChild(circle);
if (index !== params.progressSteps.length - 1) {
var line = document.createElement('li');
addClass(line, swalClasses.progressline);
line.style.width = params.progressStepsDistance;
progressStepsContainer.appendChild(line);
}
});
} else {
hide(progressStepsContainer);
}
// Icon
var icons = getIcons();
for (var _i = 0; _i < icons.length; _i++) {
hide(icons[_i]);
}
if (params.type) {
var validType = false;
for (var iconType in iconTypes) {
if (params.type === iconType) {
validType = true;
break;
}
}
if (!validType) {
console.error('SweetAlert2: Unknown alert type: ' + params.type);
return false;
}
var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]);
show(icon);
// Animate icon
switch (params.type) {
case 'success':
addClass(icon, 'animate');
addClass(icon.querySelector('.tip'), 'animate-success-tip');
addClass(icon.querySelector('.long'), 'animate-success-long');
break;
case 'error':
addClass(icon, 'animate-error-icon');
addClass(icon.querySelector('.x-mark'), 'animate-x-mark');
break;
case 'warning':
addClass(icon, 'pulse-warning');
break;
default:
break;
}
}
// Custom image
var image = getImage();
if (params.imageUrl) {
image.setAttribute('src', params.imageUrl);
show(image);
if (params.imageWidth) {
image.setAttribute('width', params.imageWidth);
} else {
image.removeAttribute('width');
}
if (params.imageHeight) {
image.setAttribute('height', params.imageHeight);
} else {
image.removeAttribute('height');
}
image.className = swalClasses.image;
if (params.imageClass) {
addClass(image, params.imageClass);
}
} else {
hide(image);
}
// Cancel button
if (params.showCancelButton) {
cancelButton.style.display = 'inline-block';
} else {
hide(cancelButton);
}
// Confirm button
if (params.showConfirmButton) {
removeStyleProperty(confirmButton, 'display');
} else {
hide(confirmButton);
}
// Buttons spacer
var spacer = getSpacer();
if (!params.showConfirmButton && !params.showCancelButton) {
hide(spacer);
} else {
show(spacer);
}
// Edit text on cancel and confirm buttons
confirmButton.innerHTML = params.confirmButtonText;
cancelButton.innerHTML = params.cancelButtonText;
// Set buttons to selected background colors
if (params.buttonsStyling) {
confirmButton.style.backgroundColor = params.confirmButtonColor;
cancelButton.style.backgroundColor = params.cancelButtonColor;
}
// Add buttons custom classes
confirmButton.className = swalClasses.confirm;
addClass(confirmButton, params.confirmButtonClass);
cancelButton.className = swalClasses.cancel;
addClass(cancelButton, params.cancelButtonClass);
// Buttons styling
if (params.buttonsStyling) {
addClass(confirmButton, swalClasses.styled);
addClass(cancelButton, swalClasses.styled);
} else {
removeClass(confirmButton, swalClasses.styled);
removeClass(cancelButton, swalClasses.styled);
confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
}
// CSS animation
if (params.animation === true) {
removeClass(modal, swalClasses.noanimation);
} else {
addClass(modal, swalClasses.noanimation);
}
};
/*
* Animations
*/
var openModal = function openModal(animation, onComplete) {
var container = getContainer();
var modal = getModal();
if (animation) {
addClass(modal, swalClasses.show);
addClass(container, swalClasses.fade);
removeClass(modal, swalClasses.hide);
} else {
removeClass(modal, swalClasses.fade);
}
show(modal);
// scrolling is 'hidden' until animation is done, after that 'auto'
container.style.overflowY = 'hidden';
if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
container.style.overflowY = 'auto';
});
} else {
container.style.overflowY = 'auto';
}
addClass(document.documentElement, swalClasses.shown);
addClass(document.body, swalClasses.shown);
addClass(container, swalClasses.shown);
fixScrollbar();
iOSfix();
states.previousActiveElement = document.activeElement;
if (onComplete !== null && typeof onComplete === 'function') {
setTimeout(function () {
onComplete(modal);
});
}
};
var fixScrollbar = function fixScrollbar() {
// for queues, do not do this more than once
if (states.previousBodyPadding !== null) {
return;
}
// if the body has overflow
if (document.body.scrollHeight > window.innerHeight) {
// add padding so the content doesn't shift after removal of scrollbar
states.previousBodyPadding = document.body.style.paddingRight;
document.body.style.paddingRight = measureScrollbar() + 'px';
}
};
var undoScrollbar = function undoScrollbar() {
if (states.previousBodyPadding !== null) {
document.body.style.paddingRight = states.previousBodyPadding;
states.previousBodyPadding = null;
}
};
// Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425
var iOSfix = function iOSfix() {
var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
var offset = document.body.scrollTop;
document.body.style.top = offset * -1 + 'px';
addClass(document.body, swalClasses.iosfix);
}
};
var undoIOSfix = function undoIOSfix() {
if (hasClass(document.body, swalClasses.iosfix)) {
var offset = parseInt(document.body.style.top, 10);
removeClass(document.body, swalClasses.iosfix);
document.body.style.top = '';
document.body.scrollTop = offset * -1;
}
};
// SweetAlert entry point
var sweetAlert = function sweetAlert() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args[0] === undefined) {
console.error('SweetAlert2 expects at least 1 attribute!');
return false;
}
var params = _extends({}, modalParams);
switch (_typeof(args[0])) {
case 'string':
params.title = args[0];
params.html = args[1];
params.type = args[2];
break;
case 'object':
_extends(params, args[0]);
params.extraParams = args[0].extraParams;
if (params.input === 'email' && params.inputValidator === null) {
params.inputValidator = function (email) {
return new Promise(function (resolve, reject) {
var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (emailRegex.test(email)) {
resolve();
} else {
reject('Invalid email address');
}
});
};
}
if (params.input === 'url' && params.inputValidator === null) {
params.inputValidator = function (url) {
return new Promise(function (resolve, reject) {
var urlRegex = /^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
if (urlRegex.test(url)) {
resolve();
} else {
reject('Invalid URL');
}
});
};
}
break;
default:
console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0]));
return false;
}
setParameters(params);
var container = getContainer();
var modal = getModal();
return new Promise(function (resolve, reject) {
// Close on timer
if (params.timer) {
modal.timeout = setTimeout(function () {
sweetAlert.closeModal(params.onClose);
reject('timer');
}, params.timer);
}
// Get input element by specified type or, if type isn't specified, by params.input
var getInput = function getInput(inputType) {
inputType = inputType || params.input;
if (!inputType) {
return null;
}
switch (inputType) {
case 'select':
case 'textarea':
case 'file':
return getChildByClass(modal, swalClasses[inputType]);
case 'checkbox':
return modal.querySelector('.' + swalClasses.checkbox + ' input');
case 'radio':
return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child');
case 'range':
return modal.querySelector('.' + swalClasses.range + ' input');
default:
return getChildByClass(modal, swalClasses.input);
}
};
// Get the value of the modal input
var getInputValue = function getInputValue() {
var input = getInput();
if (!input) {
return null;
}
switch (params.input) {
case 'checkbox':
return input.checked ? 1 : 0;
case 'radio':
return input.checked ? input.value : null;
case 'file':
return input.files.length ? input.files[0] : null;
default:
return params.inputAutoTrim ? input.value.trim() : input.value;
}
};
// input autofocus
if (params.input) {
setTimeout(function () {
var input = getInput();
if (input) {
focusInput(input);
}
}, 0);
}
var confirm = function confirm(value) {
if (params.showLoaderOnConfirm) {
sweetAlert.showLoading();
}
if (params.preConfirm) {
params.preConfirm(value, params.extraParams).then(function (preConfirmValue) {
sweetAlert.closeModal(params.onClose);
resolve(preConfirmValue || value);
}, function (error) {
sweetAlert.hideLoading();
if (error) {
sweetAlert.showValidationError(error);
}
});
} else {
sweetAlert.closeModal(params.onClose);
resolve(value);
}
};
// Mouse interactions
var onButtonEvent = function onButtonEvent(event) {
var e = event || window.event;
var target = e.target || e.srcElement;
var confirmButton = getConfirmButton();
var cancelButton = getCancelButton();
var targetedConfirm = confirmButton === target || confirmButton.contains(target);
var targetedCancel = cancelButton === target || cancelButton.contains(target);
switch (e.type) {
case 'mouseover':
case 'mouseup':
if (params.buttonsStyling) {
if (targetedConfirm) {
confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1);
} else if (targetedCancel) {
cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1);
}
}
break;
case 'mouseout':
if (params.buttonsStyling) {
if (targetedConfirm) {
confirmButton.style.backgroundColor = params.confirmButtonColor;
} else if (targetedCancel) {
cancelButton.style.backgroundColor = params.cancelButtonColor;
}
}
break;
case 'mousedown':
if (params.buttonsStyling) {
if (targetedConfirm) {
confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2);
} else if (targetedCancel) {
cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2);
}
}
break;
case 'click':
// Clicked 'confirm'
if (targetedConfirm && sweetAlert.isVisible()) {
sweetAlert.disableButtons();
if (params.input) {
var inputValue = getInputValue();
if (params.inputValidator) {
sweetAlert.disableInput();
params.inputValidator(inputValue, params.extraParams).then(function () {
sweetAlert.enableButtons();
sweetAlert.enableInput();
confirm(inputValue);
}, function (error) {
sweetAlert.enableButtons();
sweetAlert.enableInput();
if (error) {
sweetAlert.showValidationError(error);
}
});
} else {
confirm(inputValue);
}
} else {
confirm(true);
}
// Clicked 'cancel'
} else if (targetedCancel && sweetAlert.isVisible()) {
sweetAlert.disableButtons();
sweetAlert.closeModal(params.onClose);
reject('cancel');
}
break;
default:
}
};
var buttons = modal.querySelectorAll('button');
for (var i = 0; i < buttons.length; i++) {
buttons[i].onclick = onButtonEvent;
buttons[i].onmouseover = onButtonEvent;
buttons[i].onmouseout = onButtonEvent;
buttons[i].onmousedown = onButtonEvent;
}
// Closing modal by close button
getCloseButton().onclick = function () {
sweetAlert.closeModal(params.onClose);
reject('close');
};
// Closing modal by overlay click
container.onclick = function (e) {
if (e.target !== container) {
return;
}
if (params.allowOutsideClick) {
sweetAlert.closeModal(params.onClose);
reject('overlay');
}
};
var confirmButton = getConfirmButton();
var cancelButton = getCancelButton();
// Reverse buttons (Confirm on the right side)
if (params.reverseButtons) {
confirmButton.parentNode.insertBefore(cancelButton, confirmButton);
} else {
confirmButton.parentNode.insertBefore(confirmButton, cancelButton);
}
// Focus handling
var setFocus = function setFocus(index, increment) {
var focusableElements = getFocusableElements(params.focusCancel);
// search for visible elements and select the next possible match
for (var _i2 = 0; _i2 < focusableElements.length; _i2++) {
index = index + increment;
// rollover to first item
if (index === focusableElements.length) {
index = 0;
// go to last item
} else if (index === -1) {
index = focusableElements.length - 1;
}
// determine if element is visible
var el = focusableElements[index];
if (isVisible(el)) {
return el.focus();
}
}
};
var handleKeyDown = function handleKeyDown(event) {
var e = event || window.event;
var keyCode = e.keyCode || e.which;
if ([9, 13, 32, 27].indexOf(keyCode) === -1) {
// Don't do work on keys we don't care about.
return;
}
var targetElement = e.target || e.srcElement;
var focusableElements = getFocusableElements(params.focusCancel);
var btnIndex = -1; // Find the button - note, this is a nodelist, not an array.
for (var _i3 = 0; _i3 < focusableElements.length; _i3++) {
if (targetElement === focusableElements[_i3]) {
btnIndex = _i3;
break;
}
}
// TAB
if (keyCode === 9) {
if (!e.shiftKey) {
// Cycle to the next button
setFocus(btnIndex, 1);
} else {
// Cycle to the prev button
setFocus(btnIndex, -1);
}
e.stopPropagation();
e.preventDefault();
// ENTER/SPACE
} else if (keyCode === 13 || keyCode === 32) {
if (btnIndex === -1 && params.allowEnterKey) {
// ENTER/SPACE clicked outside of a button.
if (params.focusCancel) {
fireClick(cancelButton, e);
} else {
fireClick(confirmButton, e);
}
}
// ESC
} else if (keyCode === 27 && params.allowEscapeKey === true) {
sweetAlert.closeModal(params.onClose);
reject('esc');
}
};
states.previousWindowKeyDown = window.onkeydown;
window.onkeydown = handleKeyDown;
// Loading state
if (params.buttonsStyling) {
confirmButton.style.borderLeftColor = params.confirmButtonColor;
confirmButton.style.borderRightColor = params.confirmButtonColor;
}
/**
* Show spinner instead of Confirm button and disable Cancel button
*/
sweetAlert.showLoading = sweetAlert.enableLoading = function () {
show(getSpacer());
show(confirmButton, 'inline-block');
addClass(confirmButton, swalClasses.loading);
addClass(modal, swalClasses.loading);
confirmButton.disabled = true;
cancelButton.disabled = true;
};
/**
* Show spinner instead of Confirm button and disable Cancel button
*/
sweetAlert.hideLoading = sweetAlert.disableLoading = function () {
if (!params.showConfirmButton) {
hide(confirmButton);
if (!params.showCancelButton) {
hide(getSpacer());
}
}
removeClass(confirmButton, swalClasses.loading);
removeClass(modal, swalClasses.loading);
confirmButton.disabled = false;
cancelButton.disabled = false;
};
sweetAlert.getTitle = function () {
return getTitle();
};
sweetAlert.getContent = function () {
return getContent();
};
sweetAlert.getInput = function () {
return getInput();
};
sweetAlert.getImage = function () {
return getImage();
};
sweetAlert.getConfirmButton = function () {
return getConfirmButton();
};
sweetAlert.getCancelButton = function () {
return getCancelButton();
};
sweetAlert.enableButtons = function () {
confirmButton.disabled = false;
cancelButton.disabled = false;
};
sweetAlert.disableButtons = function () {
confirmButton.disabled = true;
cancelButton.disabled = true;
};
sweetAlert.enableConfirmButton = function () {
confirmButton.disabled = false;
};
sweetAlert.disableConfirmButton = function () {
confirmButton.disabled = true;
};
sweetAlert.enableInput = function () {
var input = getInput();
if (!input) {
return false;
}
if (input.type === 'radio') {
var radiosContainer = input.parentNode.parentNode;
var radios = radiosContainer.querySelectorAll('input');
for (var _i4 = 0; _i4 < radios.length; _i4++) {
radios[_i4].disabled = false;
}
} else {
input.disabled = false;
}
};
sweetAlert.disableInput = function () {
var input = getInput();
if (!input) {
return false;
}
if (input && input.type === 'radio') {
var radiosContainer = input.parentNode.parentNode;
var radios = radiosContainer.querySelectorAll('input');
for (var _i5 = 0; _i5 < radios.length; _i5++) {
radios[_i5].disabled = true;
}
} else {
input.disabled = true;
}
};
// Set modal min-height to disable scrolling inside the modal
sweetAlert.recalculateHeight = debounce(function () {
var modal = getModal();
if (!modal) {
return;
}
var prevState = modal.style.display;
modal.style.minHeight = '';
show(modal);
modal.style.minHeight = modal.scrollHeight + 1 + 'px';
modal.style.display = prevState;
}, 50);
// Show block with validation error
sweetAlert.showValidationError = function (error) {
var validationError = getValidationError();
validationError.innerHTML = error;
show(validationError);
var input = getInput();
if (input) {
focusInput(input);
addClass(input, swalClasses.inputerror);
}
};
// Hide block with validation error
sweetAlert.resetValidationError = function () {
var validationError = getValidationError();
hide(validationError);
sweetAlert.recalculateHeight();
var input = getInput();
if (input) {
removeClass(input, swalClasses.inputerror);
}
};
sweetAlert.getProgressSteps = function () {
return params.progressSteps;
};
sweetAlert.setProgressSteps = function (progressSteps) {
params.progressSteps = progressSteps;
setParameters(params);
};
sweetAlert.showProgressSteps = function () {
show(getProgressSteps());
};
sweetAlert.hideProgressSteps = function () {
hide(getProgressSteps());
};
sweetAlert.enableButtons();
sweetAlert.hideLoading();
sweetAlert.resetValidationError();
// inputs
var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
var input = void 0;
for (var _i6 = 0; _i6 < inputTypes.length; _i6++) {
var inputClass = swalClasses[inputTypes[_i6]];
var inputContainer = getChildByClass(modal, inputClass);
input = getInput(inputTypes[_i6]);
// set attributes
if (input) {
for (var j in input.attributes) {
if (input.attributes.hasOwnProperty(j)) {
var attrName = input.attributes[j].name;
if (attrName !== 'type' && attrName !== 'value') {
input.removeAttribute(attrName);
}
}
}
for (var attr in params.inputAttributes) {
input.setAttribute(attr, params.inputAttributes[attr]);
}
}
// set class
inputContainer.className = inputClass;
if (params.inputClass) {
addClass(inputContainer, params.inputClass);
}
hide(inputContainer);
}
var populateInputOptions = void 0;
switch (params.input) {
case 'text':
case 'email':
case 'password':
case 'number':
case 'tel':
case 'url':
input = getChildByClass(modal, swalClasses.input);
input.value = params.inputValue;
input.placeholder = params.inputPlaceholder;
input.type = params.input;
show(input);
break;
case 'file':
input = getChildByClass(modal, swalClasses.file);
input.placeholder = params.inputPlaceholder;
input.type = params.input;
show(input);
break;
case 'range':
var range = getChildByClass(modal, swalClasses.range);
var rangeInput = range.querySelector('input');
var rangeOutput = range.querySelector('output');
rangeInput.value = params.inputValue;
rangeInput.type = params.input;
rangeOutput.value = params.inputValue;
show(range);
break;
case 'select':
var select = getChildByClass(modal, swalClasses.select);
select.innerHTML = '';
if (params.inputPlaceholder) {
var placeholder = document.createElement('option');
placeholder.innerHTML = params.inputPlaceholder;
placeholder.value = '';
placeholder.disabled = true;
placeholder.selected = true;
select.appendChild(placeholder);
}
populateInputOptions = function populateInputOptions(inputOptions) {
for (var optionValue in inputOptions) {
var option = document.createElement('option');
option.value = optionValue;
option.innerHTML = inputOptions[optionValue];
if (params.inputValue === optionValue) {
option.selected = true;
}
select.appendChild(option);
}
show(select);
select.focus();
};
break;
case 'radio':
var radio = getChildByClass(modal, swalClasses.radio);
radio.innerHTML = '';
populateInputOptions = function populateInputOptions(inputOptions) {
for (var radioValue in inputOptions) {
var radioInput = document.createElement('input');
var radioLabel = document.createElement('label');
var radioLabelSpan = document.createElement('span');
radioInput.type = 'radio';
radioInput.name = swalClasses.radio;
radioInput.value = radioValue;
if (params.inputValue === radioValue) {
radioInput.checked = true;
}
radioLabelSpan.innerHTML = inputOptions[radioValue];
radioLabel.appendChild(radioInput);
radioLabel.appendChild(radioLabelSpan);
radioLabel.for = radioInput.id;
radio.appendChild(radioLabel);
}
show(radio);
var radios = radio.querySelectorAll('input');
if (radios.length) {
radios[0].focus();
}
};
break;
case 'checkbox':
var checkbox = getChildByClass(modal, swalClasses.checkbox);
var checkboxInput = getInput('checkbox');
checkboxInput.type = 'checkbox';
checkboxInput.value = 1;
checkboxInput.id = swalClasses.checkbox;
checkboxInput.checked = Boolean(params.inputValue);
var label = checkbox.getElementsByTagName('span');
if (label.length) {
checkbox.removeChild(label[0]);
}
label = document.createElement('span');
label.innerHTML = params.inputPlaceholder;
checkbox.appendChild(label);
show(checkbox);
break;
case 'textarea':
var textarea = getChildByClass(modal, swalClasses.textarea);
textarea.value = params.inputValue;
textarea.placeholder = params.inputPlaceholder;
show(textarea);
break;
case null:
break;
default:
console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"');
break;
}
if (params.input === 'select' || params.input === 'radio') {
if (params.inputOptions instanceof Promise) {
sweetAlert.showLoading();
params.inputOptions.then(function (inputOptions) {
sweetAlert.hideLoading();
populateInputOptions(inputOptions);
});
} else if (_typeof(params.inputOptions) === 'object') {
populateInputOptions(params.inputOptions);
} else {
console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions));
}
}
openModal(params.animation, params.onOpen);
// Focus the first element (input or button)
if (params.allowEnterKey) {
setFocus(-1, 1);
} else {
if (document.activeElement) {
document.activeElement.blur();
}
}
// fix scroll
getContainer().scrollTop = 0;
// Observe changes inside the modal and adjust height
if (typeof MutationObserver !== 'undefined' && !swal2Observer) {
swal2Observer = new MutationObserver(sweetAlert.recalculateHeight);
swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true });
}
});
};
/*
* Global function to determine if swal2 modal is shown
*/
sweetAlert.isVisible = function () {
return !!getModal();
};
/*
* Global function for chaining sweetAlert modals
*/
sweetAlert.queue = function (steps) {
queue = steps;
var resetQueue = function resetQueue() {
queue = [];
document.body.removeAttribute('data-swal2-queue-step');
};
var queueResult = [];
return new Promise(function (resolve, reject) {
(function step(i, callback) {
if (i < queue.length) {
document.body.setAttribute('data-swal2-queue-step', i);
sweetAlert(queue[i]).then(function (result) {
queueResult.push(result);
step(i + 1, callback);
}, function (dismiss) {
resetQueue();
reject(dismiss);
});
} else {
resetQueue();
resolve(queueResult);
}
})(0);
});
};
/*
* Global function for getting the index of current modal in queue
*/
sweetAlert.getQueueStep = function () {
return document.body.getAttribute('data-swal2-queue-step');
};
/*
* Global function for inserting a modal to the queue
*/
sweetAlert.insertQueueStep = function (step, index) {
if (index && index < queue.length) {
return queue.splice(index, 0, step);
}
return queue.push(step);
};
/*
* Global function for deleting a modal from the queue
*/
sweetAlert.deleteQueueStep = function (index) {
if (typeof queue[index] !== 'undefined') {
queue.splice(index, 1);
}
};
/*
* Global function to close sweetAlert
*/
sweetAlert.close = sweetAlert.closeModal = function (onComplete) {
var container = getContainer();
var modal = getModal();
if (!modal) {
return;
}
removeClass(modal, swalClasses.show);
addClass(modal, swalClasses.hide);
clearTimeout(modal.timeout);
resetPrevState();
var removeModalAndResetState = function removeModalAndResetState() {
container.parentNode.removeChild(container);
removeClass(document.documentElement, swalClasses.shown);
removeClass(document.body, swalClasses.shown);
undoScrollbar();
undoIOSfix();
};
// If animation is supported, animate
if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
if (hasClass(modal, swalClasses.hide)) {
removeModalAndResetState();
}
});
} else {
// Otherwise, remove immediately
removeModalAndResetState();
}
if (onComplete !== null && typeof onComplete === 'function') {
setTimeout(function () {
onComplete(modal);
});
}
};
/*
* Global function to click 'Confirm' button
*/
sweetAlert.clickConfirm = function () {
return getConfirmButton().click();
};
/*
* Global function to click 'Cancel' button
*/
sweetAlert.clickCancel = function () {
return getCancelButton().click();
};
/**
* Set default params for each popup
* @param {Object} userParams
*/
sweetAlert.setDefaults = function (userParams) {
if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') {
return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object');
}
for (var param in userParams) {
if (!defaultParams.hasOwnProperty(param) && param !== 'extraParams') {
console.warn('SweetAlert2: Unknown parameter "' + param + '"');
delete userParams[param];
}
}
_extends(modalParams, userParams);
};
/**
* Reset default params for each popup
*/
sweetAlert.resetDefaults = function () {
modalParams = _extends({}, defaultParams);
};
sweetAlert.noop = function () {};
sweetAlert.version = '6.4.4';
sweetAlert.default = sweetAlert;
return sweetAlert;
})));
if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2;