├── README.md
├── alert
├── sweetalert2.common.js
├── sweetalert2.css
├── sweetalert2.js
├── sweetalert2.min.css
└── sweetalert2.min.js
├── cert
├── README.txt
└── init
├── css
├── bootstrap.min.css
├── style.css
└── styleCom.css
├── js
├── .DS_Store
├── index.js
└── jquery.min.js
├── logo.png
├── requirements.txt
├── server.py
└── tpl
├── __init__.py
├── comparison.html
└── index.html
/README.md:
--------------------------------------------------------------------------------
1 | 
2 |
3 | []()
4 | [](https://www.python.org/downloads/)
5 |
6 | ## WTF is it
7 |
8 | It can rapidly provide your server SSL support without purchasing, waiting...
9 |
10 | Where you can use:
11 |
12 | | Name | Description |
13 | | ------------- |-------------|
14 | | iOS APP Development | iOS Development restricted developers to use SSL when communicating with server|
15 | | Beautify Address | Who don't like the address started with green locks |
16 | | And more... | |
17 |
18 | But remember!! Do **NOT** use this in production. Never!
19 |
20 | Users may kill you!!
21 |
22 | ## Why Us
23 |
24 | A simple comparison
25 |
26 | || XIP.io | SSLip.io | Our SSLify |
27 | ----|----|------|----
28 | Price | Free | Private | Free
29 | Unlimited Domains | ✓ | ✓ | ✓
30 | Fast Wildcard DNS | ✓ | ✓ | ✓
31 | SSL | ✗ | ✓ | ✓
32 | Local Deployment | Hard | Hard | Easy
33 | Auto SSL Deploy | ✗ | ✗ | ✓
34 | Multi-lingual | ✗ | ✗ | ✓
35 | Stable DNS | ✗ | ✗ | ✓
36 | No Privacy Leaks | ✓ | ✗ | ✓
37 | Concept | Local DNS Server | Local DNS Server | CloudFlare
38 |
39 | ## How does it work
40 |
41 | When user already deployed our public key and private key onto their server, they can now bind their server to our domain just like DNS control pannel.
42 |
43 | Supported Record Types:
44 |
45 | | Type | Description |
46 | | ------------- |-------------|
47 | | CNAME | Used to specify that a domain name is an alias for another domain |
48 | | A | Used to specify that an IP is an alias for a domain |
49 |
50 | The backend, after recveiving the GET request of creating domain, communicate with CloudFlare API and edit the DNS setting for our domain zone.
51 |
52 | ```Python
53 | def dns(type,name,content):
54 | if type == "A":
55 | return [{'name':name, 'type':'A', 'content':content}]
56 | elif type == "CNAME":
57 | return [{'name':name, 'type':'CNAME', 'content':content}]
58 |
59 | def push(dns_records):
60 | for dns_record in dns_records:
61 | r = cf.zones.dns_records.post(zone_id, data=dns_record)
62 | ```
63 |
64 | ## Installation
65 |
66 | ```
67 | git clone https://github.com/InvidHead/SSLify.git && cd SSLify
68 | pip install -r requirements.txt
69 | python server.py
70 | ```
71 |
72 | For errors, please submit issues.
73 |
74 | ## Donations
75 | **Server eats money!**
76 |
77 | *Paypal:* [Click Here](https://www.paypal.me/kotobuki)
78 |
79 | ## Contributors
80 |
81 | Built with  by Shou Chaofan (scf@ieee.org)
82 |
83 |
84 |
--------------------------------------------------------------------------------
/alert/sweetalert2.common.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * sweetalert2 v6.8.0
3 | * Released under the MIT License.
4 | */
5 | 'use strict';
6 |
7 | var defaultParams = {
8 | title: '',
9 | titleText: '',
10 | text: '',
11 | html: '',
12 | type: null,
13 | customClass: '',
14 | target: 'body',
15 | animation: true,
16 | allowOutsideClick: true,
17 | allowEscapeKey: true,
18 | allowEnterKey: true,
19 | showConfirmButton: true,
20 | showCancelButton: false,
21 | preConfirm: null,
22 | confirmButtonText: 'OK',
23 | confirmButtonAriaLabel: '',
24 | confirmButtonColor: '#3085d6',
25 | confirmButtonClass: null,
26 | cancelButtonText: 'Cancel',
27 | cancelButtonAriaLabel: '',
28 | cancelButtonColor: '#aaa',
29 | cancelButtonClass: null,
30 | buttonsStyling: true,
31 | reverseButtons: false,
32 | focusCancel: false,
33 | showCloseButton: false,
34 | showLoaderOnConfirm: false,
35 | imageUrl: null,
36 | imageWidth: null,
37 | imageHeight: null,
38 | imageAlt: '',
39 | imageClass: null,
40 | timer: null,
41 | width: 500,
42 | padding: 20,
43 | background: '#fff',
44 | input: null,
45 | inputPlaceholder: '',
46 | inputValue: '',
47 | inputOptions: {},
48 | inputAutoTrim: true,
49 | inputClass: null,
50 | inputAttributes: {},
51 | inputValidator: null,
52 | progressSteps: [],
53 | currentProgressStep: null,
54 | progressStepsDistance: '40px',
55 | onOpen: null,
56 | onClose: null,
57 | useRejections: true
58 | };
59 |
60 | var swalPrefix = 'swal2-';
61 |
62 | var prefix = function prefix(items) {
63 | var result = {};
64 | for (var i in items) {
65 | result[items[i]] = swalPrefix + items[i];
66 | }
67 | return result;
68 | };
69 |
70 | var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']);
71 |
72 | var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
73 |
74 | /*
75 | * Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
76 | */
77 | var colorLuminance = function colorLuminance(hex, lum) {
78 | // Validate hex string
79 | hex = String(hex).replace(/[^0-9a-f]/gi, '');
80 | if (hex.length < 6) {
81 | hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
82 | }
83 | lum = lum || 0;
84 |
85 | // Convert to decimal and change luminosity
86 | var rgb = '#';
87 | for (var i = 0; i < 3; i++) {
88 | var c = parseInt(hex.substr(i * 2, 2), 16);
89 | c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16);
90 | rgb += ('00' + c).substr(c.length);
91 | }
92 |
93 | return rgb;
94 | };
95 |
96 | var uniqueArray = function uniqueArray(arr) {
97 | var result = [];
98 | for (var i in arr) {
99 | if (result.indexOf(arr[i]) === -1) {
100 | result.push(arr[i]);
101 | }
102 | }
103 | return result;
104 | };
105 |
106 | /* global MouseEvent */
107 |
108 | // Remember state in cases where opening and handling a modal will fiddle with it.
109 | var states = {
110 | previousWindowKeyDown: null,
111 | previousActiveElement: null,
112 | previousBodyPadding: null
113 |
114 | /*
115 | * Add modal + overlay to DOM
116 | */
117 | };var init = function init(params) {
118 | // Clean up the old modal if it exists
119 | var c = getContainer();
120 | if (c) {
121 | c.parentNode.removeChild(c);
122 | }
123 |
124 | if (typeof document === 'undefined') {
125 | console.error('SweetAlert2 requires document to initialize');
126 | return;
127 | }
128 |
129 | var container = document.createElement('div');
130 | container.className = swalClasses.container;
131 | container.innerHTML = sweetHTML;
132 |
133 | var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
134 | targetElement.appendChild(container);
135 |
136 | var modal = getModal();
137 | var input = getChildByClass(modal, swalClasses.input);
138 | var file = getChildByClass(modal, swalClasses.file);
139 | var range = modal.querySelector('.' + swalClasses.range + ' input');
140 | var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output');
141 | var select = getChildByClass(modal, swalClasses.select);
142 | var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input');
143 | var textarea = getChildByClass(modal, swalClasses.textarea);
144 |
145 | input.oninput = function () {
146 | sweetAlert.resetValidationError();
147 | };
148 |
149 | input.onkeydown = function (event) {
150 | setTimeout(function () {
151 | if (event.keyCode === 13 && params.allowEnterKey) {
152 | event.stopPropagation();
153 | sweetAlert.clickConfirm();
154 | }
155 | }, 0);
156 | };
157 |
158 | file.onchange = function () {
159 | sweetAlert.resetValidationError();
160 | };
161 |
162 | range.oninput = function () {
163 | sweetAlert.resetValidationError();
164 | rangeOutput.value = range.value;
165 | };
166 |
167 | range.onchange = function () {
168 | sweetAlert.resetValidationError();
169 | range.previousSibling.value = range.value;
170 | };
171 |
172 | select.onchange = function () {
173 | sweetAlert.resetValidationError();
174 | };
175 |
176 | checkbox.onchange = function () {
177 | sweetAlert.resetValidationError();
178 | };
179 |
180 | textarea.oninput = function () {
181 | sweetAlert.resetValidationError();
182 | };
183 |
184 | return modal;
185 | };
186 |
187 | /*
188 | * Manipulate DOM
189 | */
190 |
191 | var sweetHTML = ('\n
\n
\n
\n \n
\n
?
\n
!
\n
i
\n
\n
\n
\n
\n
\n
\n
\n \n \n
\n
\n
\n
\n \n \n
\n
\n
\n OK \n Cancel \n
\n
\xD7 \n
\n').replace(/(^|\n)\s*/g, '');
192 |
193 | var getContainer = function getContainer() {
194 | return document.body.querySelector('.' + swalClasses.container);
195 | };
196 |
197 | var getModal = function getModal() {
198 | return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null;
199 | };
200 |
201 | var getIcons = function getIcons() {
202 | var modal = getModal();
203 | return modal.querySelectorAll('.' + swalClasses.icon);
204 | };
205 |
206 | var elementByClass = function elementByClass(className) {
207 | return getContainer() ? getContainer().querySelector('.' + className) : null;
208 | };
209 |
210 | var getTitle = function getTitle() {
211 | return elementByClass(swalClasses.title);
212 | };
213 |
214 | var getContent = function getContent() {
215 | return elementByClass(swalClasses.content);
216 | };
217 |
218 | var getImage = function getImage() {
219 | return elementByClass(swalClasses.image);
220 | };
221 |
222 | var getButtonsWrapper = function getButtonsWrapper() {
223 | return elementByClass(swalClasses.buttonswrapper);
224 | };
225 |
226 | var getProgressSteps = function getProgressSteps() {
227 | return elementByClass(swalClasses.progresssteps);
228 | };
229 |
230 | var getValidationError = function getValidationError() {
231 | return elementByClass(swalClasses.validationerror);
232 | };
233 |
234 | var getConfirmButton = function getConfirmButton() {
235 | return elementByClass(swalClasses.confirm);
236 | };
237 |
238 | var getCancelButton = function getCancelButton() {
239 | return elementByClass(swalClasses.cancel);
240 | };
241 |
242 | var getCloseButton = function getCloseButton() {
243 | return elementByClass(swalClasses.close);
244 | };
245 |
246 | var getFocusableElements = function getFocusableElements(focusCancel) {
247 | var buttons = [getConfirmButton(), getCancelButton()];
248 | if (focusCancel) {
249 | buttons.reverse();
250 | }
251 |
252 | var focusableElementsWithTabindex = Array.from(getModal().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'))
253 | // sort according to tabindex
254 | .sort(function (a, b) {
255 | a = parseInt(a.getAttribute('tabindex'));
256 | b = parseInt(b.getAttribute('tabindex'));
257 | if (a > b) {
258 | return 1;
259 | } else if (a < b) {
260 | return -1;
261 | }
262 | return 0;
263 | });
264 |
265 | var otherFocusableElements = Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, [tabindex="0"]'));
266 |
267 | return uniqueArray(buttons.concat(focusableElementsWithTabindex, otherFocusableElements));
268 | };
269 |
270 | var hasClass = function hasClass(elem, className) {
271 | if (elem.classList) {
272 | return elem.classList.contains(className);
273 | }
274 | return false;
275 | };
276 |
277 | var focusInput = function focusInput(input) {
278 | input.focus();
279 |
280 | // place cursor at end of text in text input
281 | if (input.type !== 'file') {
282 | // http://stackoverflow.com/a/2345915/1331425
283 | var val = input.value;
284 | input.value = '';
285 | input.value = val;
286 | }
287 | };
288 |
289 | var addClass = function addClass(elem, className) {
290 | if (!elem || !className) {
291 | return;
292 | }
293 | var classes = className.split(/\s+/).filter(Boolean);
294 | classes.forEach(function (className) {
295 | elem.classList.add(className);
296 | });
297 | };
298 |
299 | var removeClass = function removeClass(elem, className) {
300 | if (!elem || !className) {
301 | return;
302 | }
303 | var classes = className.split(/\s+/).filter(Boolean);
304 | classes.forEach(function (className) {
305 | elem.classList.remove(className);
306 | });
307 | };
308 |
309 | var getChildByClass = function getChildByClass(elem, className) {
310 | for (var i = 0; i < elem.childNodes.length; i++) {
311 | if (hasClass(elem.childNodes[i], className)) {
312 | return elem.childNodes[i];
313 | }
314 | }
315 | };
316 |
317 | var show = function show(elem, display) {
318 | if (!display) {
319 | display = 'block';
320 | }
321 | elem.style.opacity = '';
322 | elem.style.display = display;
323 | };
324 |
325 | var hide = function hide(elem) {
326 | elem.style.opacity = '';
327 | elem.style.display = 'none';
328 | };
329 |
330 | var empty = function empty(elem) {
331 | while (elem.firstChild) {
332 | elem.removeChild(elem.firstChild);
333 | }
334 | };
335 |
336 | // borrowed from jqeury $(elem).is(':visible') implementation
337 | var isVisible = function isVisible(elem) {
338 | return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length;
339 | };
340 |
341 | var removeStyleProperty = function removeStyleProperty(elem, property) {
342 | if (elem.style.removeProperty) {
343 | elem.style.removeProperty(property);
344 | } else {
345 | elem.style.removeAttribute(property);
346 | }
347 | };
348 |
349 | var fireClick = function fireClick(node) {
350 | if (!isVisible(node)) {
351 | return false;
352 | }
353 |
354 | // Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/
355 | // Then fixed for today's Chrome browser.
356 | if (typeof MouseEvent === 'function') {
357 | // Up-to-date approach
358 | var mevt = new MouseEvent('click', {
359 | view: window,
360 | bubbles: false,
361 | cancelable: true
362 | });
363 | node.dispatchEvent(mevt);
364 | } else if (document.createEvent) {
365 | // Fallback
366 | var evt = document.createEvent('MouseEvents');
367 | evt.initEvent('click', false, false);
368 | node.dispatchEvent(evt);
369 | } else if (document.createEventObject) {
370 | node.fireEvent('onclick');
371 | } else if (typeof node.onclick === 'function') {
372 | node.onclick();
373 | }
374 | };
375 |
376 | var animationEndEvent = function () {
377 | var testEl = document.createElement('div');
378 | var transEndEventNames = {
379 | 'WebkitAnimation': 'webkitAnimationEnd',
380 | 'OAnimation': 'oAnimationEnd oanimationend',
381 | 'msAnimation': 'MSAnimationEnd',
382 | 'animation': 'animationend'
383 | };
384 | for (var i in transEndEventNames) {
385 | if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) {
386 | return transEndEventNames[i];
387 | }
388 | }
389 |
390 | return false;
391 | }();
392 |
393 | // Reset previous window keydown handler and focued element
394 | var resetPrevState = function resetPrevState() {
395 | window.onkeydown = states.previousWindowKeyDown;
396 | if (states.previousActiveElement && states.previousActiveElement.focus) {
397 | var x = window.scrollX;
398 | var y = window.scrollY;
399 | states.previousActiveElement.focus();
400 | if (x && y) {
401 | // IE has no scrollX/scrollY support
402 | window.scrollTo(x, y);
403 | }
404 | }
405 | };
406 |
407 | // Measure width of scrollbar
408 | // https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286
409 | var measureScrollbar = function measureScrollbar() {
410 | var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
411 | if (supportsTouch) {
412 | return 0;
413 | }
414 | var scrollDiv = document.createElement('div');
415 | scrollDiv.style.width = '50px';
416 | scrollDiv.style.height = '50px';
417 | scrollDiv.style.overflow = 'scroll';
418 | document.body.appendChild(scrollDiv);
419 | var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
420 | document.body.removeChild(scrollDiv);
421 | return scrollbarWidth;
422 | };
423 |
424 | // JavaScript Debounce Function
425 | // Simplivied version of https://davidwalsh.name/javascript-debounce-function
426 | var debounce = function debounce(func, wait) {
427 | var timeout = void 0;
428 | return function () {
429 | var later = function later() {
430 | timeout = null;
431 | func();
432 | };
433 | clearTimeout(timeout);
434 | timeout = setTimeout(later, wait);
435 | };
436 | };
437 |
438 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
439 | return typeof obj;
440 | } : function (obj) {
441 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
442 | };
443 |
444 |
445 |
446 |
447 |
448 | var asyncGenerator = function () {
449 | function AwaitValue(value) {
450 | this.value = value;
451 | }
452 |
453 | function AsyncGenerator(gen) {
454 | var front, back;
455 |
456 | function send(key, arg) {
457 | return new Promise(function (resolve, reject) {
458 | var request = {
459 | key: key,
460 | arg: arg,
461 | resolve: resolve,
462 | reject: reject,
463 | next: null
464 | };
465 |
466 | if (back) {
467 | back = back.next = request;
468 | } else {
469 | front = back = request;
470 | resume(key, arg);
471 | }
472 | });
473 | }
474 |
475 | function resume(key, arg) {
476 | try {
477 | var result = gen[key](arg);
478 | var value = result.value;
479 |
480 | if (value instanceof AwaitValue) {
481 | Promise.resolve(value.value).then(function (arg) {
482 | resume("next", arg);
483 | }, function (arg) {
484 | resume("throw", arg);
485 | });
486 | } else {
487 | settle(result.done ? "return" : "normal", result.value);
488 | }
489 | } catch (err) {
490 | settle("throw", err);
491 | }
492 | }
493 |
494 | function settle(type, value) {
495 | switch (type) {
496 | case "return":
497 | front.resolve({
498 | value: value,
499 | done: true
500 | });
501 | break;
502 |
503 | case "throw":
504 | front.reject(value);
505 | break;
506 |
507 | default:
508 | front.resolve({
509 | value: value,
510 | done: false
511 | });
512 | break;
513 | }
514 |
515 | front = front.next;
516 |
517 | if (front) {
518 | resume(front.key, front.arg);
519 | } else {
520 | back = null;
521 | }
522 | }
523 |
524 | this._invoke = send;
525 |
526 | if (typeof gen.return !== "function") {
527 | this.return = undefined;
528 | }
529 | }
530 |
531 | if (typeof Symbol === "function" && Symbol.asyncIterator) {
532 | AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
533 | return this;
534 | };
535 | }
536 |
537 | AsyncGenerator.prototype.next = function (arg) {
538 | return this._invoke("next", arg);
539 | };
540 |
541 | AsyncGenerator.prototype.throw = function (arg) {
542 | return this._invoke("throw", arg);
543 | };
544 |
545 | AsyncGenerator.prototype.return = function (arg) {
546 | return this._invoke("return", arg);
547 | };
548 |
549 | return {
550 | wrap: function (fn) {
551 | return function () {
552 | return new AsyncGenerator(fn.apply(this, arguments));
553 | };
554 | },
555 | await: function (value) {
556 | return new AwaitValue(value);
557 | }
558 | };
559 | }();
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 | var _extends = Object.assign || function (target) {
576 | for (var i = 1; i < arguments.length; i++) {
577 | var source = arguments[i];
578 |
579 | for (var key in source) {
580 | if (Object.prototype.hasOwnProperty.call(source, key)) {
581 | target[key] = source[key];
582 | }
583 | }
584 | }
585 |
586 | return target;
587 | };
588 |
589 | var modalParams = _extends({}, defaultParams);
590 | var queue = [];
591 | var swal2Observer = void 0;
592 |
593 | /*
594 | * Set type, text and actions on modal
595 | */
596 | var setParameters = function setParameters(params) {
597 | // If a custom element is set, determine if it is valid
598 | if (typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
599 | console.warn('SweetAlert2: Target parameter is not valid, defaulting to "body"');
600 | params.target = 'body';
601 | }
602 |
603 | var modal = void 0;
604 | var oldModal = getModal();
605 | var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
606 | // If the model target has changed, refresh the modal
607 | if (oldModal && targetElement && oldModal.parentNode !== targetElement.parentNode) {
608 | modal = init(params);
609 | } else {
610 | modal = oldModal || init(params);
611 | }
612 |
613 | for (var param in params) {
614 | if (!sweetAlert.isValidParameter(param)) {
615 | console.warn('SweetAlert2: Unknown parameter "' + param + '"');
616 | }
617 | }
618 |
619 | // Set modal width
620 | modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width;
621 |
622 | modal.style.padding = params.padding + 'px';
623 | modal.style.background = params.background;
624 | var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
625 | for (var i = 0; i < successIconParts.length; i++) {
626 | successIconParts[i].style.background = params.background;
627 | }
628 |
629 | var title = getTitle();
630 | var content = getContent();
631 | var buttonsWrapper = getButtonsWrapper();
632 | var confirmButton = getConfirmButton();
633 | var cancelButton = getCancelButton();
634 | var closeButton = getCloseButton();
635 |
636 | // Title
637 | if (params.titleText) {
638 | title.innerText = params.titleText;
639 | } else {
640 | title.innerHTML = params.title.split('\n').join(' ');
641 | }
642 |
643 | // Content
644 | if (params.text || params.html) {
645 | if (_typeof(params.html) === 'object') {
646 | content.innerHTML = '';
647 | if (0 in params.html) {
648 | for (var _i = 0; _i in params.html; _i++) {
649 | content.appendChild(params.html[_i].cloneNode(true));
650 | }
651 | } else {
652 | content.appendChild(params.html.cloneNode(true));
653 | }
654 | } else if (params.html) {
655 | content.innerHTML = params.html;
656 | } else if (params.text) {
657 | content.textContent = params.text;
658 | }
659 | show(content);
660 | } else {
661 | hide(content);
662 | }
663 |
664 | // Close button
665 | if (params.showCloseButton) {
666 | show(closeButton);
667 | } else {
668 | hide(closeButton);
669 | }
670 |
671 | // Custom Class
672 | modal.className = swalClasses.modal;
673 | if (params.customClass) {
674 | addClass(modal, params.customClass);
675 | }
676 |
677 | // Progress steps
678 | var progressStepsContainer = getProgressSteps();
679 | var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10);
680 | if (params.progressSteps.length) {
681 | show(progressStepsContainer);
682 | empty(progressStepsContainer);
683 | if (currentProgressStep >= params.progressSteps.length) {
684 | console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
685 | }
686 | params.progressSteps.forEach(function (step, index) {
687 | var circle = document.createElement('li');
688 | addClass(circle, swalClasses.progresscircle);
689 | circle.innerHTML = step;
690 | if (index === currentProgressStep) {
691 | addClass(circle, swalClasses.activeprogressstep);
692 | }
693 | progressStepsContainer.appendChild(circle);
694 | if (index !== params.progressSteps.length - 1) {
695 | var line = document.createElement('li');
696 | addClass(line, swalClasses.progressline);
697 | line.style.width = params.progressStepsDistance;
698 | progressStepsContainer.appendChild(line);
699 | }
700 | });
701 | } else {
702 | hide(progressStepsContainer);
703 | }
704 |
705 | // Icon
706 | var icons = getIcons();
707 | for (var _i2 = 0; _i2 < icons.length; _i2++) {
708 | hide(icons[_i2]);
709 | }
710 | if (params.type) {
711 | var validType = false;
712 | for (var iconType in iconTypes) {
713 | if (params.type === iconType) {
714 | validType = true;
715 | break;
716 | }
717 | }
718 | if (!validType) {
719 | console.error('SweetAlert2: Unknown alert type: ' + params.type);
720 | return false;
721 | }
722 | var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]);
723 | show(icon);
724 |
725 | // Animate icon
726 | if (params.animation) {
727 | switch (params.type) {
728 | case 'success':
729 | addClass(icon, 'swal2-animate-success-icon');
730 | addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip');
731 | addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long');
732 | break;
733 | case 'error':
734 | addClass(icon, 'swal2-animate-error-icon');
735 | addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark');
736 | break;
737 | default:
738 | break;
739 | }
740 | }
741 | }
742 |
743 | // Custom image
744 | var image = getImage();
745 | if (params.imageUrl) {
746 | image.setAttribute('src', params.imageUrl);
747 | image.setAttribute('alt', params.imageAlt);
748 | show(image);
749 |
750 | if (params.imageWidth) {
751 | image.setAttribute('width', params.imageWidth);
752 | } else {
753 | image.removeAttribute('width');
754 | }
755 |
756 | if (params.imageHeight) {
757 | image.setAttribute('height', params.imageHeight);
758 | } else {
759 | image.removeAttribute('height');
760 | }
761 |
762 | image.className = swalClasses.image;
763 | if (params.imageClass) {
764 | addClass(image, params.imageClass);
765 | }
766 | } else {
767 | hide(image);
768 | }
769 |
770 | // Cancel button
771 | if (params.showCancelButton) {
772 | cancelButton.style.display = 'inline-block';
773 | } else {
774 | hide(cancelButton);
775 | }
776 |
777 | // Confirm button
778 | if (params.showConfirmButton) {
779 | removeStyleProperty(confirmButton, 'display');
780 | } else {
781 | hide(confirmButton);
782 | }
783 |
784 | // Buttons wrapper
785 | if (!params.showConfirmButton && !params.showCancelButton) {
786 | hide(buttonsWrapper);
787 | } else {
788 | show(buttonsWrapper);
789 | }
790 |
791 | // Edit text on confirm and cancel buttons
792 | confirmButton.innerHTML = params.confirmButtonText;
793 | cancelButton.innerHTML = params.cancelButtonText;
794 |
795 | // ARIA labels for confirm and cancel buttons
796 | confirmButton.setAttribute('aria-label', params.confirmButtonAriaLabel);
797 | cancelButton.setAttribute('aria-label', params.cancelButtonAriaLabel);
798 |
799 | // Set buttons to selected background colors
800 | if (params.buttonsStyling) {
801 | confirmButton.style.backgroundColor = params.confirmButtonColor;
802 | cancelButton.style.backgroundColor = params.cancelButtonColor;
803 | }
804 |
805 | // Add buttons custom classes
806 | confirmButton.className = swalClasses.confirm;
807 | addClass(confirmButton, params.confirmButtonClass);
808 | cancelButton.className = swalClasses.cancel;
809 | addClass(cancelButton, params.cancelButtonClass);
810 |
811 | // Buttons styling
812 | if (params.buttonsStyling) {
813 | addClass(confirmButton, swalClasses.styled);
814 | addClass(cancelButton, swalClasses.styled);
815 | } else {
816 | removeClass(confirmButton, swalClasses.styled);
817 | removeClass(cancelButton, swalClasses.styled);
818 |
819 | confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
820 | cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
821 | }
822 |
823 | // CSS animation
824 | if (params.animation === true) {
825 | removeClass(modal, swalClasses.noanimation);
826 | } else {
827 | addClass(modal, swalClasses.noanimation);
828 | }
829 |
830 | // showLoaderOnConfirm && preConfirm
831 | if (params.showLoaderOnConfirm && !params.preConfirm) {
832 | console.warn('SweetAlert2: showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://limonte.github.io/sweetalert2/#ajax-request');
833 | }
834 | };
835 |
836 | /*
837 | * Animations
838 | */
839 | var openModal = function openModal(animation, onComplete) {
840 | var container = getContainer();
841 | var modal = getModal();
842 |
843 | if (animation) {
844 | addClass(modal, swalClasses.show);
845 | addClass(container, swalClasses.fade);
846 | removeClass(modal, swalClasses.hide);
847 | } else {
848 | removeClass(modal, swalClasses.fade);
849 | }
850 | show(modal);
851 |
852 | // scrolling is 'hidden' until animation is done, after that 'auto'
853 | container.style.overflowY = 'hidden';
854 | if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
855 | modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
856 | modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
857 | container.style.overflowY = 'auto';
858 | });
859 | } else {
860 | container.style.overflowY = 'auto';
861 | }
862 |
863 | addClass(document.documentElement, swalClasses.shown);
864 | addClass(document.body, swalClasses.shown);
865 | addClass(container, swalClasses.shown);
866 | fixScrollbar();
867 | iOSfix();
868 | states.previousActiveElement = document.activeElement;
869 | if (onComplete !== null && typeof onComplete === 'function') {
870 | setTimeout(function () {
871 | onComplete(modal);
872 | });
873 | }
874 | };
875 |
876 | var fixScrollbar = function fixScrollbar() {
877 | // for queues, do not do this more than once
878 | if (states.previousBodyPadding !== null) {
879 | return;
880 | }
881 | // if the body has overflow
882 | if (document.body.scrollHeight > window.innerHeight) {
883 | // add padding so the content doesn't shift after removal of scrollbar
884 | states.previousBodyPadding = document.body.style.paddingRight;
885 | document.body.style.paddingRight = measureScrollbar() + 'px';
886 | }
887 | };
888 |
889 | var undoScrollbar = function undoScrollbar() {
890 | if (states.previousBodyPadding !== null) {
891 | document.body.style.paddingRight = states.previousBodyPadding;
892 | states.previousBodyPadding = null;
893 | }
894 | };
895 |
896 | // Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425
897 | var iOSfix = function iOSfix() {
898 | var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
899 | if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
900 | var offset = document.body.scrollTop;
901 | document.body.style.top = offset * -1 + 'px';
902 | addClass(document.body, swalClasses.iosfix);
903 | }
904 | };
905 |
906 | var undoIOSfix = function undoIOSfix() {
907 | if (hasClass(document.body, swalClasses.iosfix)) {
908 | var offset = parseInt(document.body.style.top, 10);
909 | removeClass(document.body, swalClasses.iosfix);
910 | document.body.style.top = '';
911 | document.body.scrollTop = offset * -1;
912 | }
913 | };
914 |
915 | // SweetAlert entry point
916 | var sweetAlert = function sweetAlert() {
917 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
918 | args[_key] = arguments[_key];
919 | }
920 |
921 | if (args[0] === undefined) {
922 | console.error('SweetAlert2 expects at least 1 attribute!');
923 | return false;
924 | }
925 |
926 | var params = _extends({}, modalParams);
927 |
928 | switch (_typeof(args[0])) {
929 | case 'string':
930 | params.title = args[0];
931 | params.html = args[1];
932 | params.type = args[2];
933 |
934 | break;
935 |
936 | case 'object':
937 | _extends(params, args[0]);
938 | params.extraParams = args[0].extraParams;
939 |
940 | if (params.input === 'email' && params.inputValidator === null) {
941 | params.inputValidator = function (email) {
942 | return new Promise(function (resolve, reject) {
943 | var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
944 | if (emailRegex.test(email)) {
945 | resolve();
946 | } else {
947 | reject('Invalid email address');
948 | }
949 | });
950 | };
951 | }
952 |
953 | if (params.input === 'url' && params.inputValidator === null) {
954 | params.inputValidator = function (url) {
955 | return new Promise(function (resolve, reject) {
956 | // taken from https://stackoverflow.com/a/3809435/1331425
957 | var urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/;
958 | if (urlRegex.test(url)) {
959 | resolve();
960 | } else {
961 | reject('Invalid URL');
962 | }
963 | });
964 | };
965 | }
966 | break;
967 |
968 | default:
969 | console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0]));
970 | return false;
971 | }
972 |
973 | setParameters(params);
974 |
975 | var container = getContainer();
976 | var modal = getModal();
977 |
978 | return new Promise(function (resolve, reject) {
979 | // Close on timer
980 | if (params.timer) {
981 | modal.timeout = setTimeout(function () {
982 | sweetAlert.closeModal(params.onClose);
983 | if (params.useRejections) {
984 | reject('timer');
985 | } else {
986 | resolve({ dismiss: 'timer' });
987 | }
988 | }, params.timer);
989 | }
990 |
991 | // Get input element by specified type or, if type isn't specified, by params.input
992 | var getInput = function getInput(inputType) {
993 | inputType = inputType || params.input;
994 | if (!inputType) {
995 | return null;
996 | }
997 | switch (inputType) {
998 | case 'select':
999 | case 'textarea':
1000 | case 'file':
1001 | return getChildByClass(modal, swalClasses[inputType]);
1002 | case 'checkbox':
1003 | return modal.querySelector('.' + swalClasses.checkbox + ' input');
1004 | case 'radio':
1005 | return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child');
1006 | case 'range':
1007 | return modal.querySelector('.' + swalClasses.range + ' input');
1008 | default:
1009 | return getChildByClass(modal, swalClasses.input);
1010 | }
1011 | };
1012 |
1013 | // Get the value of the modal input
1014 | var getInputValue = function getInputValue() {
1015 | var input = getInput();
1016 | if (!input) {
1017 | return null;
1018 | }
1019 | switch (params.input) {
1020 | case 'checkbox':
1021 | return input.checked ? 1 : 0;
1022 | case 'radio':
1023 | return input.checked ? input.value : null;
1024 | case 'file':
1025 | return input.files.length ? input.files[0] : null;
1026 | default:
1027 | return params.inputAutoTrim ? input.value.trim() : input.value;
1028 | }
1029 | };
1030 |
1031 | // input autofocus
1032 | if (params.input) {
1033 | setTimeout(function () {
1034 | var input = getInput();
1035 | if (input) {
1036 | focusInput(input);
1037 | }
1038 | }, 0);
1039 | }
1040 |
1041 | var confirm = function confirm(value) {
1042 | if (params.showLoaderOnConfirm) {
1043 | sweetAlert.showLoading();
1044 | }
1045 |
1046 | if (params.preConfirm) {
1047 | params.preConfirm(value, params.extraParams).then(function (preConfirmValue) {
1048 | sweetAlert.closeModal(params.onClose);
1049 | resolve(preConfirmValue || value);
1050 | }, function (error) {
1051 | sweetAlert.hideLoading();
1052 | if (error) {
1053 | sweetAlert.showValidationError(error);
1054 | }
1055 | });
1056 | } else {
1057 | sweetAlert.closeModal(params.onClose);
1058 | if (params.useRejections) {
1059 | resolve(value);
1060 | } else {
1061 | resolve({ value: value });
1062 | }
1063 | }
1064 | };
1065 |
1066 | // Mouse interactions
1067 | var onButtonEvent = function onButtonEvent(event) {
1068 | var e = event || window.event;
1069 | var target = e.target || e.srcElement;
1070 | var confirmButton = getConfirmButton();
1071 | var cancelButton = getCancelButton();
1072 | var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target));
1073 | var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target));
1074 |
1075 | switch (e.type) {
1076 | case 'mouseover':
1077 | case 'mouseup':
1078 | if (params.buttonsStyling) {
1079 | if (targetedConfirm) {
1080 | confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1);
1081 | } else if (targetedCancel) {
1082 | cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1);
1083 | }
1084 | }
1085 | break;
1086 | case 'mouseout':
1087 | if (params.buttonsStyling) {
1088 | if (targetedConfirm) {
1089 | confirmButton.style.backgroundColor = params.confirmButtonColor;
1090 | } else if (targetedCancel) {
1091 | cancelButton.style.backgroundColor = params.cancelButtonColor;
1092 | }
1093 | }
1094 | break;
1095 | case 'mousedown':
1096 | if (params.buttonsStyling) {
1097 | if (targetedConfirm) {
1098 | confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2);
1099 | } else if (targetedCancel) {
1100 | cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2);
1101 | }
1102 | }
1103 | break;
1104 | case 'click':
1105 | // Clicked 'confirm'
1106 | if (targetedConfirm && sweetAlert.isVisible()) {
1107 | sweetAlert.disableButtons();
1108 | if (params.input) {
1109 | var inputValue = getInputValue();
1110 |
1111 | if (params.inputValidator) {
1112 | sweetAlert.disableInput();
1113 | params.inputValidator(inputValue, params.extraParams).then(function () {
1114 | sweetAlert.enableButtons();
1115 | sweetAlert.enableInput();
1116 | confirm(inputValue);
1117 | }, function (error) {
1118 | sweetAlert.enableButtons();
1119 | sweetAlert.enableInput();
1120 | if (error) {
1121 | sweetAlert.showValidationError(error);
1122 | }
1123 | });
1124 | } else {
1125 | confirm(inputValue);
1126 | }
1127 | } else {
1128 | confirm(true);
1129 | }
1130 |
1131 | // Clicked 'cancel'
1132 | } else if (targetedCancel && sweetAlert.isVisible()) {
1133 | sweetAlert.disableButtons();
1134 | sweetAlert.closeModal(params.onClose);
1135 | if (params.useRejections) {
1136 | reject('cancel');
1137 | } else {
1138 | resolve({ dismiss: 'cancel' });
1139 | }
1140 | }
1141 | break;
1142 | default:
1143 | }
1144 | };
1145 |
1146 | var buttons = modal.querySelectorAll('button');
1147 | for (var i = 0; i < buttons.length; i++) {
1148 | buttons[i].onclick = onButtonEvent;
1149 | buttons[i].onmouseover = onButtonEvent;
1150 | buttons[i].onmouseout = onButtonEvent;
1151 | buttons[i].onmousedown = onButtonEvent;
1152 | }
1153 |
1154 | // Closing modal by close button
1155 | getCloseButton().onclick = function () {
1156 | sweetAlert.closeModal(params.onClose);
1157 | if (params.useRejections) {
1158 | reject('close');
1159 | } else {
1160 | resolve({ dismiss: 'close' });
1161 | }
1162 | };
1163 |
1164 | // Closing modal by overlay click
1165 | container.onclick = function (e) {
1166 | if (e.target !== container) {
1167 | return;
1168 | }
1169 | if (params.allowOutsideClick) {
1170 | sweetAlert.closeModal(params.onClose);
1171 | if (params.useRejections) {
1172 | reject('overlay');
1173 | } else {
1174 | resolve({ dismiss: 'overlay' });
1175 | }
1176 | }
1177 | };
1178 |
1179 | var buttonsWrapper = getButtonsWrapper();
1180 | var confirmButton = getConfirmButton();
1181 | var cancelButton = getCancelButton();
1182 |
1183 | // Reverse buttons (Confirm on the right side)
1184 | if (params.reverseButtons) {
1185 | confirmButton.parentNode.insertBefore(cancelButton, confirmButton);
1186 | } else {
1187 | confirmButton.parentNode.insertBefore(confirmButton, cancelButton);
1188 | }
1189 |
1190 | // Focus handling
1191 | var setFocus = function setFocus(index, increment) {
1192 | var focusableElements = getFocusableElements(params.focusCancel);
1193 | // search for visible elements and select the next possible match
1194 | for (var _i3 = 0; _i3 < focusableElements.length; _i3++) {
1195 | index = index + increment;
1196 |
1197 | // rollover to first item
1198 | if (index === focusableElements.length) {
1199 | index = 0;
1200 |
1201 | // go to last item
1202 | } else if (index === -1) {
1203 | index = focusableElements.length - 1;
1204 | }
1205 |
1206 | // determine if element is visible
1207 | var el = focusableElements[index];
1208 | if (isVisible(el)) {
1209 | return el.focus();
1210 | }
1211 | }
1212 | };
1213 |
1214 | var handleKeyDown = function handleKeyDown(event) {
1215 | var e = event || window.event;
1216 | var keyCode = e.keyCode || e.which;
1217 |
1218 | if ([9, 13, 32, 27, 37, 38, 39, 40].indexOf(keyCode) === -1) {
1219 | // Don't do work on keys we don't care about.
1220 | return;
1221 | }
1222 |
1223 | var targetElement = e.target || e.srcElement;
1224 |
1225 | var focusableElements = getFocusableElements(params.focusCancel);
1226 | var btnIndex = -1; // Find the button - note, this is a nodelist, not an array.
1227 | for (var _i4 = 0; _i4 < focusableElements.length; _i4++) {
1228 | if (targetElement === focusableElements[_i4]) {
1229 | btnIndex = _i4;
1230 | break;
1231 | }
1232 | }
1233 |
1234 | // TAB
1235 | if (keyCode === 9) {
1236 | if (!e.shiftKey) {
1237 | // Cycle to the next button
1238 | setFocus(btnIndex, 1);
1239 | } else {
1240 | // Cycle to the prev button
1241 | setFocus(btnIndex, -1);
1242 | }
1243 | e.stopPropagation();
1244 | e.preventDefault();
1245 |
1246 | // ARROWS - switch focus between buttons
1247 | } else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) {
1248 | // focus Cancel button if Confirm button is currently focused
1249 | if (document.activeElement === confirmButton && isVisible(cancelButton)) {
1250 | cancelButton.focus();
1251 | // and vice versa
1252 | } else if (document.activeElement === cancelButton && isVisible(confirmButton)) {
1253 | confirmButton.focus();
1254 | }
1255 |
1256 | // ENTER/SPACE
1257 | } else if (keyCode === 13 || keyCode === 32) {
1258 | if (btnIndex === -1 && params.allowEnterKey) {
1259 | // ENTER/SPACE clicked outside of a button.
1260 | if (params.focusCancel) {
1261 | fireClick(cancelButton, e);
1262 | } else {
1263 | fireClick(confirmButton, e);
1264 | }
1265 | e.stopPropagation();
1266 | e.preventDefault();
1267 | }
1268 |
1269 | // ESC
1270 | } else if (keyCode === 27 && params.allowEscapeKey === true) {
1271 | sweetAlert.closeModal(params.onClose);
1272 | if (params.useRejections) {
1273 | reject('esc');
1274 | } else {
1275 | resolve({ dismiss: 'esc' });
1276 | }
1277 | }
1278 | };
1279 |
1280 | if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) {
1281 | states.previousWindowKeyDown = window.onkeydown;
1282 | window.onkeydown = handleKeyDown;
1283 | }
1284 |
1285 | // Loading state
1286 | if (params.buttonsStyling) {
1287 | confirmButton.style.borderLeftColor = params.confirmButtonColor;
1288 | confirmButton.style.borderRightColor = params.confirmButtonColor;
1289 | }
1290 |
1291 | /**
1292 | * Show spinner instead of Confirm button and disable Cancel button
1293 | */
1294 | sweetAlert.hideLoading = sweetAlert.disableLoading = function () {
1295 | if (!params.showConfirmButton) {
1296 | hide(confirmButton);
1297 | if (!params.showCancelButton) {
1298 | hide(getButtonsWrapper());
1299 | }
1300 | }
1301 | removeClass(buttonsWrapper, swalClasses.loading);
1302 | removeClass(modal, swalClasses.loading);
1303 | confirmButton.disabled = false;
1304 | cancelButton.disabled = false;
1305 | };
1306 |
1307 | sweetAlert.getTitle = function () {
1308 | return getTitle();
1309 | };
1310 | sweetAlert.getContent = function () {
1311 | return getContent();
1312 | };
1313 | sweetAlert.getInput = function () {
1314 | return getInput();
1315 | };
1316 | sweetAlert.getImage = function () {
1317 | return getImage();
1318 | };
1319 | sweetAlert.getButtonsWrapper = function () {
1320 | return getButtonsWrapper();
1321 | };
1322 | sweetAlert.getConfirmButton = function () {
1323 | return getConfirmButton();
1324 | };
1325 | sweetAlert.getCancelButton = function () {
1326 | return getCancelButton();
1327 | };
1328 |
1329 | sweetAlert.enableButtons = function () {
1330 | confirmButton.disabled = false;
1331 | cancelButton.disabled = false;
1332 | };
1333 |
1334 | sweetAlert.disableButtons = function () {
1335 | confirmButton.disabled = true;
1336 | cancelButton.disabled = true;
1337 | };
1338 |
1339 | sweetAlert.enableConfirmButton = function () {
1340 | confirmButton.disabled = false;
1341 | };
1342 |
1343 | sweetAlert.disableConfirmButton = function () {
1344 | confirmButton.disabled = true;
1345 | };
1346 |
1347 | sweetAlert.enableInput = function () {
1348 | var input = getInput();
1349 | if (!input) {
1350 | return false;
1351 | }
1352 | if (input.type === 'radio') {
1353 | var radiosContainer = input.parentNode.parentNode;
1354 | var radios = radiosContainer.querySelectorAll('input');
1355 | for (var _i5 = 0; _i5 < radios.length; _i5++) {
1356 | radios[_i5].disabled = false;
1357 | }
1358 | } else {
1359 | input.disabled = false;
1360 | }
1361 | };
1362 |
1363 | sweetAlert.disableInput = function () {
1364 | var input = getInput();
1365 | if (!input) {
1366 | return false;
1367 | }
1368 | if (input && input.type === 'radio') {
1369 | var radiosContainer = input.parentNode.parentNode;
1370 | var radios = radiosContainer.querySelectorAll('input');
1371 | for (var _i6 = 0; _i6 < radios.length; _i6++) {
1372 | radios[_i6].disabled = true;
1373 | }
1374 | } else {
1375 | input.disabled = true;
1376 | }
1377 | };
1378 |
1379 | // Set modal min-height to disable scrolling inside the modal
1380 | sweetAlert.recalculateHeight = debounce(function () {
1381 | var modal = getModal();
1382 | if (!modal) {
1383 | return;
1384 | }
1385 | var prevState = modal.style.display;
1386 | modal.style.minHeight = '';
1387 | show(modal);
1388 | modal.style.minHeight = modal.scrollHeight + 1 + 'px';
1389 | modal.style.display = prevState;
1390 | }, 50);
1391 |
1392 | // Show block with validation error
1393 | sweetAlert.showValidationError = function (error) {
1394 | var validationError = getValidationError();
1395 | validationError.innerHTML = error;
1396 | show(validationError);
1397 |
1398 | var input = getInput();
1399 | if (input) {
1400 | input.setAttribute('aria-invalid', true);
1401 | input.setAttribute('aria-describedBy', swalClasses.validationerror);
1402 | focusInput(input);
1403 | addClass(input, swalClasses.inputerror);
1404 | }
1405 | };
1406 |
1407 | // Hide block with validation error
1408 | sweetAlert.resetValidationError = function () {
1409 | var validationError = getValidationError();
1410 | hide(validationError);
1411 | sweetAlert.recalculateHeight();
1412 |
1413 | var input = getInput();
1414 | if (input) {
1415 | input.removeAttribute('aria-invalid');
1416 | input.removeAttribute('aria-describedBy');
1417 | removeClass(input, swalClasses.inputerror);
1418 | }
1419 | };
1420 |
1421 | sweetAlert.getProgressSteps = function () {
1422 | return params.progressSteps;
1423 | };
1424 |
1425 | sweetAlert.setProgressSteps = function (progressSteps) {
1426 | params.progressSteps = progressSteps;
1427 | setParameters(params);
1428 | };
1429 |
1430 | sweetAlert.showProgressSteps = function () {
1431 | show(getProgressSteps());
1432 | };
1433 |
1434 | sweetAlert.hideProgressSteps = function () {
1435 | hide(getProgressSteps());
1436 | };
1437 |
1438 | sweetAlert.enableButtons();
1439 | sweetAlert.hideLoading();
1440 | sweetAlert.resetValidationError();
1441 |
1442 | // inputs
1443 | var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
1444 | var input = void 0;
1445 | for (var _i7 = 0; _i7 < inputTypes.length; _i7++) {
1446 | var inputClass = swalClasses[inputTypes[_i7]];
1447 | var inputContainer = getChildByClass(modal, inputClass);
1448 | input = getInput(inputTypes[_i7]);
1449 |
1450 | // set attributes
1451 | if (input) {
1452 | for (var j in input.attributes) {
1453 | if (input.attributes.hasOwnProperty(j)) {
1454 | var attrName = input.attributes[j].name;
1455 | if (attrName !== 'type' && attrName !== 'value') {
1456 | input.removeAttribute(attrName);
1457 | }
1458 | }
1459 | }
1460 | for (var attr in params.inputAttributes) {
1461 | input.setAttribute(attr, params.inputAttributes[attr]);
1462 | }
1463 | }
1464 |
1465 | // set class
1466 | inputContainer.className = inputClass;
1467 | if (params.inputClass) {
1468 | addClass(inputContainer, params.inputClass);
1469 | }
1470 |
1471 | hide(inputContainer);
1472 | }
1473 |
1474 | var populateInputOptions = void 0;
1475 | switch (params.input) {
1476 | case 'text':
1477 | case 'email':
1478 | case 'password':
1479 | case 'number':
1480 | case 'tel':
1481 | case 'url':
1482 | input = getChildByClass(modal, swalClasses.input);
1483 | input.value = params.inputValue;
1484 | input.placeholder = params.inputPlaceholder;
1485 | input.type = params.input;
1486 | show(input);
1487 | break;
1488 | case 'file':
1489 | input = getChildByClass(modal, swalClasses.file);
1490 | input.placeholder = params.inputPlaceholder;
1491 | input.type = params.input;
1492 | show(input);
1493 | break;
1494 | case 'range':
1495 | var range = getChildByClass(modal, swalClasses.range);
1496 | var rangeInput = range.querySelector('input');
1497 | var rangeOutput = range.querySelector('output');
1498 | rangeInput.value = params.inputValue;
1499 | rangeInput.type = params.input;
1500 | rangeOutput.value = params.inputValue;
1501 | show(range);
1502 | break;
1503 | case 'select':
1504 | var select = getChildByClass(modal, swalClasses.select);
1505 | select.innerHTML = '';
1506 | if (params.inputPlaceholder) {
1507 | var placeholder = document.createElement('option');
1508 | placeholder.innerHTML = params.inputPlaceholder;
1509 | placeholder.value = '';
1510 | placeholder.disabled = true;
1511 | placeholder.selected = true;
1512 | select.appendChild(placeholder);
1513 | }
1514 | populateInputOptions = function populateInputOptions(inputOptions) {
1515 | for (var optionValue in inputOptions) {
1516 | var option = document.createElement('option');
1517 | option.value = optionValue;
1518 | option.innerHTML = inputOptions[optionValue];
1519 | if (params.inputValue === optionValue) {
1520 | option.selected = true;
1521 | }
1522 | select.appendChild(option);
1523 | }
1524 | show(select);
1525 | select.focus();
1526 | };
1527 | break;
1528 | case 'radio':
1529 | var radio = getChildByClass(modal, swalClasses.radio);
1530 | radio.innerHTML = '';
1531 | populateInputOptions = function populateInputOptions(inputOptions) {
1532 | for (var radioValue in inputOptions) {
1533 | var radioInput = document.createElement('input');
1534 | var radioLabel = document.createElement('label');
1535 | var radioLabelSpan = document.createElement('span');
1536 | radioInput.type = 'radio';
1537 | radioInput.name = swalClasses.radio;
1538 | radioInput.value = radioValue;
1539 | if (params.inputValue === radioValue) {
1540 | radioInput.checked = true;
1541 | }
1542 | radioLabelSpan.innerHTML = inputOptions[radioValue];
1543 | radioLabel.appendChild(radioInput);
1544 | radioLabel.appendChild(radioLabelSpan);
1545 | radioLabel.for = radioInput.id;
1546 | radio.appendChild(radioLabel);
1547 | }
1548 | show(radio);
1549 | var radios = radio.querySelectorAll('input');
1550 | if (radios.length) {
1551 | radios[0].focus();
1552 | }
1553 | };
1554 | break;
1555 | case 'checkbox':
1556 | var checkbox = getChildByClass(modal, swalClasses.checkbox);
1557 | var checkboxInput = getInput('checkbox');
1558 | checkboxInput.type = 'checkbox';
1559 | checkboxInput.value = 1;
1560 | checkboxInput.id = swalClasses.checkbox;
1561 | checkboxInput.checked = Boolean(params.inputValue);
1562 | var label = checkbox.getElementsByTagName('span');
1563 | if (label.length) {
1564 | checkbox.removeChild(label[0]);
1565 | }
1566 | label = document.createElement('span');
1567 | label.innerHTML = params.inputPlaceholder;
1568 | checkbox.appendChild(label);
1569 | show(checkbox);
1570 | break;
1571 | case 'textarea':
1572 | var textarea = getChildByClass(modal, swalClasses.textarea);
1573 | textarea.value = params.inputValue;
1574 | textarea.placeholder = params.inputPlaceholder;
1575 | show(textarea);
1576 | break;
1577 | case null:
1578 | break;
1579 | default:
1580 | console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"');
1581 | break;
1582 | }
1583 |
1584 | if (params.input === 'select' || params.input === 'radio') {
1585 | if (params.inputOptions instanceof Promise) {
1586 | sweetAlert.showLoading();
1587 | params.inputOptions.then(function (inputOptions) {
1588 | sweetAlert.hideLoading();
1589 | populateInputOptions(inputOptions);
1590 | });
1591 | } else if (_typeof(params.inputOptions) === 'object') {
1592 | populateInputOptions(params.inputOptions);
1593 | } else {
1594 | console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions));
1595 | }
1596 | }
1597 |
1598 | openModal(params.animation, params.onOpen);
1599 |
1600 | // Focus the first focusable element
1601 | if (params.allowEnterKey) {
1602 | setFocus(-1, 1);
1603 | } else {
1604 | if (document.activeElement) {
1605 | document.activeElement.blur();
1606 | }
1607 | }
1608 |
1609 | // fix scroll
1610 | getContainer().scrollTop = 0;
1611 |
1612 | // Observe changes inside the modal and adjust height
1613 | if (typeof MutationObserver !== 'undefined' && !swal2Observer) {
1614 | swal2Observer = new MutationObserver(sweetAlert.recalculateHeight);
1615 | swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true });
1616 | }
1617 | });
1618 | };
1619 |
1620 | /*
1621 | * Global function to determine if swal2 modal is shown
1622 | */
1623 | sweetAlert.isVisible = function () {
1624 | return !!getModal();
1625 | };
1626 |
1627 | /*
1628 | * Global function for chaining sweetAlert modals
1629 | */
1630 | sweetAlert.queue = function (steps) {
1631 | queue = steps;
1632 | var resetQueue = function resetQueue() {
1633 | queue = [];
1634 | document.body.removeAttribute('data-swal2-queue-step');
1635 | };
1636 | var queueResult = [];
1637 | return new Promise(function (resolve, reject) {
1638 | (function step(i, callback) {
1639 | if (i < queue.length) {
1640 | document.body.setAttribute('data-swal2-queue-step', i);
1641 |
1642 | sweetAlert(queue[i]).then(function (result) {
1643 | queueResult.push(result);
1644 | step(i + 1, callback);
1645 | }, function (dismiss) {
1646 | resetQueue();
1647 | reject(dismiss);
1648 | });
1649 | } else {
1650 | resetQueue();
1651 | resolve(queueResult);
1652 | }
1653 | })(0);
1654 | });
1655 | };
1656 |
1657 | /*
1658 | * Global function for getting the index of current modal in queue
1659 | */
1660 | sweetAlert.getQueueStep = function () {
1661 | return document.body.getAttribute('data-swal2-queue-step');
1662 | };
1663 |
1664 | /*
1665 | * Global function for inserting a modal to the queue
1666 | */
1667 | sweetAlert.insertQueueStep = function (step, index) {
1668 | if (index && index < queue.length) {
1669 | return queue.splice(index, 0, step);
1670 | }
1671 | return queue.push(step);
1672 | };
1673 |
1674 | /*
1675 | * Global function for deleting a modal from the queue
1676 | */
1677 | sweetAlert.deleteQueueStep = function (index) {
1678 | if (typeof queue[index] !== 'undefined') {
1679 | queue.splice(index, 1);
1680 | }
1681 | };
1682 |
1683 | /*
1684 | * Global function to close sweetAlert
1685 | */
1686 | sweetAlert.close = sweetAlert.closeModal = function (onComplete) {
1687 | var container = getContainer();
1688 | var modal = getModal();
1689 | if (!modal) {
1690 | return;
1691 | }
1692 | removeClass(modal, swalClasses.show);
1693 | addClass(modal, swalClasses.hide);
1694 | clearTimeout(modal.timeout);
1695 |
1696 | resetPrevState();
1697 |
1698 | var removeModalAndResetState = function removeModalAndResetState() {
1699 | if (container.parentNode) {
1700 | container.parentNode.removeChild(container);
1701 | }
1702 | removeClass(document.documentElement, swalClasses.shown);
1703 | removeClass(document.body, swalClasses.shown);
1704 | undoScrollbar();
1705 | undoIOSfix();
1706 | };
1707 |
1708 | // If animation is supported, animate
1709 | if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
1710 | modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
1711 | modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
1712 | if (hasClass(modal, swalClasses.hide)) {
1713 | removeModalAndResetState();
1714 | }
1715 | });
1716 | } else {
1717 | // Otherwise, remove immediately
1718 | removeModalAndResetState();
1719 | }
1720 | if (onComplete !== null && typeof onComplete === 'function') {
1721 | setTimeout(function () {
1722 | onComplete(modal);
1723 | });
1724 | }
1725 | };
1726 |
1727 | /*
1728 | * Global function to click 'Confirm' button
1729 | */
1730 | sweetAlert.clickConfirm = function () {
1731 | return getConfirmButton().click();
1732 | };
1733 |
1734 | /*
1735 | * Global function to click 'Cancel' button
1736 | */
1737 | sweetAlert.clickCancel = function () {
1738 | return getCancelButton().click();
1739 | };
1740 |
1741 | /**
1742 | * Show spinner instead of Confirm button and disable Cancel button
1743 | */
1744 | sweetAlert.showLoading = sweetAlert.enableLoading = function () {
1745 | var modal = getModal();
1746 | if (!modal) {
1747 | sweetAlert('');
1748 | }
1749 | var buttonsWrapper = getButtonsWrapper();
1750 | var confirmButton = getConfirmButton();
1751 | var cancelButton = getCancelButton();
1752 |
1753 | show(buttonsWrapper);
1754 | show(confirmButton, 'inline-block');
1755 | addClass(buttonsWrapper, swalClasses.loading);
1756 | addClass(modal, swalClasses.loading);
1757 | confirmButton.disabled = true;
1758 | cancelButton.disabled = true;
1759 | };
1760 |
1761 | /**
1762 | * Is valid parameter
1763 | * @param {String} paramName
1764 | */
1765 | sweetAlert.isValidParameter = function (paramName) {
1766 | return defaultParams.hasOwnProperty(paramName) || paramName === 'extraParams';
1767 | };
1768 |
1769 | /**
1770 | * Set default params for each popup
1771 | * @param {Object} userParams
1772 | */
1773 | sweetAlert.setDefaults = function (userParams) {
1774 | if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') {
1775 | return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object');
1776 | }
1777 |
1778 | for (var param in userParams) {
1779 | if (!sweetAlert.isValidParameter(param)) {
1780 | console.warn('SweetAlert2: Unknown parameter "' + param + '"');
1781 | delete userParams[param];
1782 | }
1783 | }
1784 |
1785 | _extends(modalParams, userParams);
1786 | };
1787 |
1788 | /**
1789 | * Reset default params for each popup
1790 | */
1791 | sweetAlert.resetDefaults = function () {
1792 | modalParams = _extends({}, defaultParams);
1793 | };
1794 |
1795 | sweetAlert.noop = function () {};
1796 |
1797 | sweetAlert.version = '6.8.0';
1798 |
1799 | sweetAlert.default = sweetAlert;
1800 |
1801 | module.exports = sweetAlert;
1802 | if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2;
1803 |
--------------------------------------------------------------------------------
/alert/sweetalert2.css:
--------------------------------------------------------------------------------
1 | body.swal2-shown {
2 | overflow-y: hidden; }
3 |
4 | body.swal2-iosfix {
5 | position: fixed;
6 | left: 0;
7 | right: 0; }
8 |
9 | .swal2-container {
10 | display: -webkit-box;
11 | display: -ms-flexbox;
12 | display: flex;
13 | -webkit-box-align: center;
14 | -ms-flex-align: center;
15 | align-items: center;
16 | position: fixed;
17 | top: 0;
18 | left: 0;
19 | bottom: 0;
20 | right: 0;
21 | padding: 10px;
22 | background-color: transparent;
23 | z-index: 1060; }
24 | .swal2-container.swal2-fade {
25 | -webkit-transition: background-color .1s;
26 | transition: background-color .1s; }
27 | .swal2-container.swal2-shown {
28 | background-color: rgba(0, 0, 0, 0.4); }
29 |
30 | .swal2-modal {
31 | background-color: #fff;
32 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
33 | border-radius: 5px;
34 | -webkit-box-sizing: border-box;
35 | box-sizing: border-box;
36 | text-align: center;
37 | margin: auto;
38 | overflow-x: hidden;
39 | overflow-y: auto;
40 | display: none;
41 | position: relative;
42 | max-width: 100%; }
43 | .swal2-modal:focus {
44 | outline: none; }
45 | .swal2-modal.swal2-loading {
46 | overflow-y: hidden; }
47 | .swal2-modal .swal2-title {
48 | color: #595959;
49 | font-size: 30px;
50 | text-align: center;
51 | font-weight: 600;
52 | text-transform: none;
53 | position: relative;
54 | margin: 0 0 .4em;
55 | padding: 0;
56 | display: block;
57 | word-wrap: break-word; }
58 | .swal2-modal .swal2-buttonswrapper {
59 | margin-top: 15px; }
60 | .swal2-modal .swal2-buttonswrapper:not(.swal2-loading) .swal2-styled[disabled] {
61 | opacity: .4;
62 | cursor: no-drop; }
63 | .swal2-modal .swal2-buttonswrapper.swal2-loading .swal2-styled.swal2-confirm {
64 | -webkit-box-sizing: border-box;
65 | box-sizing: border-box;
66 | border: 4px solid transparent;
67 | border-color: transparent;
68 | width: 40px;
69 | height: 40px;
70 | padding: 0;
71 | margin: 7.5px;
72 | vertical-align: top;
73 | background-color: transparent !important;
74 | color: transparent;
75 | cursor: default;
76 | border-radius: 100%;
77 | -webkit-animation: rotate-loading 1.5s linear 0s infinite normal;
78 | animation: rotate-loading 1.5s linear 0s infinite normal;
79 | -webkit-user-select: none;
80 | -moz-user-select: none;
81 | -ms-user-select: none;
82 | user-select: none; }
83 | .swal2-modal .swal2-buttonswrapper.swal2-loading .swal2-styled.swal2-cancel {
84 | margin-left: 30px;
85 | margin-right: 30px; }
86 | .swal2-modal .swal2-buttonswrapper.swal2-loading :not(.swal2-styled).swal2-confirm::after {
87 | display: inline-block;
88 | content: '';
89 | margin-left: 5px;
90 | vertical-align: -1px;
91 | height: 15px;
92 | width: 15px;
93 | border: 3px solid #999999;
94 | -webkit-box-shadow: 1px 1px 1px #fff;
95 | box-shadow: 1px 1px 1px #fff;
96 | border-right-color: transparent;
97 | border-radius: 50%;
98 | -webkit-animation: rotate-loading 1.5s linear 0s infinite normal;
99 | animation: rotate-loading 1.5s linear 0s infinite normal; }
100 | .swal2-modal .swal2-styled {
101 | border: 0;
102 | border-radius: 3px;
103 | -webkit-box-shadow: none;
104 | box-shadow: none;
105 | color: #fff;
106 | cursor: pointer;
107 | font-size: 17px;
108 | font-weight: 500;
109 | margin: 15px 5px 0;
110 | padding: 10px 32px; }
111 | .swal2-modal .swal2-styled:focus {
112 | outline: none;
113 | -webkit-box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(50, 100, 150, 0.4);
114 | box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(50, 100, 150, 0.4); }
115 | .swal2-modal .swal2-image {
116 | margin: 20px auto;
117 | max-width: 100%; }
118 | .swal2-modal .swal2-close {
119 | background: transparent;
120 | border: 0;
121 | margin: 0;
122 | padding: 0;
123 | width: 38px;
124 | height: 40px;
125 | font-size: 36px;
126 | line-height: 40px;
127 | font-family: serif;
128 | position: absolute;
129 | top: 5px;
130 | right: 8px;
131 | cursor: pointer;
132 | color: #cccccc;
133 | -webkit-transition: color .1s ease;
134 | transition: color .1s ease; }
135 | .swal2-modal .swal2-close:hover {
136 | color: #d55; }
137 | .swal2-modal > .swal2-input,
138 | .swal2-modal > .swal2-file,
139 | .swal2-modal > .swal2-textarea,
140 | .swal2-modal > .swal2-select,
141 | .swal2-modal > .swal2-radio,
142 | .swal2-modal > .swal2-checkbox {
143 | display: none; }
144 | .swal2-modal .swal2-content {
145 | font-size: 18px;
146 | text-align: center;
147 | font-weight: 300;
148 | position: relative;
149 | float: none;
150 | margin: 0;
151 | padding: 0;
152 | line-height: normal;
153 | color: #545454;
154 | word-wrap: break-word; }
155 | .swal2-modal .swal2-input,
156 | .swal2-modal .swal2-file,
157 | .swal2-modal .swal2-textarea,
158 | .swal2-modal .swal2-select,
159 | .swal2-modal .swal2-radio,
160 | .swal2-modal .swal2-checkbox {
161 | margin: 20px auto; }
162 | .swal2-modal .swal2-input,
163 | .swal2-modal .swal2-file,
164 | .swal2-modal .swal2-textarea {
165 | width: 100%;
166 | -webkit-box-sizing: border-box;
167 | box-sizing: border-box;
168 | font-size: 18px;
169 | border-radius: 3px;
170 | border: 1px solid #d9d9d9;
171 | -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06);
172 | box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.06);
173 | -webkit-transition: border-color .3s, -webkit-box-shadow .3s;
174 | transition: border-color .3s, -webkit-box-shadow .3s;
175 | transition: border-color .3s, box-shadow .3s;
176 | transition: border-color .3s, box-shadow .3s, -webkit-box-shadow .3s; }
177 | .swal2-modal .swal2-input.swal2-inputerror,
178 | .swal2-modal .swal2-file.swal2-inputerror,
179 | .swal2-modal .swal2-textarea.swal2-inputerror {
180 | border-color: #f27474 !important;
181 | -webkit-box-shadow: 0 0 2px #f27474 !important;
182 | box-shadow: 0 0 2px #f27474 !important; }
183 | .swal2-modal .swal2-input:focus,
184 | .swal2-modal .swal2-file:focus,
185 | .swal2-modal .swal2-textarea:focus {
186 | outline: none;
187 | border: 1px solid #b4dbed;
188 | -webkit-box-shadow: 0 0 3px #c4e6f5;
189 | box-shadow: 0 0 3px #c4e6f5; }
190 | .swal2-modal .swal2-input::-webkit-input-placeholder,
191 | .swal2-modal .swal2-file::-webkit-input-placeholder,
192 | .swal2-modal .swal2-textarea::-webkit-input-placeholder {
193 | color: #cccccc; }
194 | .swal2-modal .swal2-input:-ms-input-placeholder,
195 | .swal2-modal .swal2-file:-ms-input-placeholder,
196 | .swal2-modal .swal2-textarea:-ms-input-placeholder {
197 | color: #cccccc; }
198 | .swal2-modal .swal2-input::placeholder,
199 | .swal2-modal .swal2-file::placeholder,
200 | .swal2-modal .swal2-textarea::placeholder {
201 | color: #cccccc; }
202 | .swal2-modal .swal2-range input {
203 | float: left;
204 | width: 80%; }
205 | .swal2-modal .swal2-range output {
206 | float: right;
207 | width: 20%;
208 | font-size: 20px;
209 | font-weight: 600;
210 | text-align: center; }
211 | .swal2-modal .swal2-range input,
212 | .swal2-modal .swal2-range output {
213 | height: 43px;
214 | line-height: 43px;
215 | vertical-align: middle;
216 | margin: 20px auto;
217 | padding: 0; }
218 | .swal2-modal .swal2-input {
219 | height: 43px;
220 | padding: 0 12px; }
221 | .swal2-modal .swal2-input[type='number'] {
222 | max-width: 150px; }
223 | .swal2-modal .swal2-file {
224 | font-size: 20px; }
225 | .swal2-modal .swal2-textarea {
226 | height: 108px;
227 | padding: 12px; }
228 | .swal2-modal .swal2-select {
229 | color: #545454;
230 | font-size: inherit;
231 | padding: 5px 10px;
232 | min-width: 40%;
233 | max-width: 100%; }
234 | .swal2-modal .swal2-radio {
235 | border: 0; }
236 | .swal2-modal .swal2-radio label:not(:first-child) {
237 | margin-left: 20px; }
238 | .swal2-modal .swal2-radio input,
239 | .swal2-modal .swal2-radio span {
240 | vertical-align: middle; }
241 | .swal2-modal .swal2-radio input {
242 | margin: 0 3px 0 0; }
243 | .swal2-modal .swal2-checkbox {
244 | color: #545454; }
245 | .swal2-modal .swal2-checkbox input,
246 | .swal2-modal .swal2-checkbox span {
247 | vertical-align: middle; }
248 | .swal2-modal .swal2-validationerror {
249 | background-color: #f0f0f0;
250 | margin: 0 -20px;
251 | overflow: hidden;
252 | padding: 10px;
253 | color: gray;
254 | font-size: 16px;
255 | font-weight: 300;
256 | display: none; }
257 | .swal2-modal .swal2-validationerror::before {
258 | content: '!';
259 | display: inline-block;
260 | width: 24px;
261 | height: 24px;
262 | border-radius: 50%;
263 | background-color: #ea7d7d;
264 | color: #fff;
265 | line-height: 24px;
266 | text-align: center;
267 | margin-right: 10px; }
268 |
269 | @supports (-ms-accelerator: true) {
270 | .swal2-range input {
271 | width: 100% !important; }
272 | .swal2-range output {
273 | display: none; } }
274 |
275 | @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
276 | .swal2-range input {
277 | width: 100% !important; }
278 | .swal2-range output {
279 | display: none; } }
280 |
281 | .swal2-icon {
282 | width: 80px;
283 | height: 80px;
284 | border: 4px solid transparent;
285 | border-radius: 50%;
286 | margin: 20px auto 30px;
287 | padding: 0;
288 | position: relative;
289 | -webkit-box-sizing: content-box;
290 | box-sizing: content-box;
291 | cursor: default;
292 | -webkit-user-select: none;
293 | -moz-user-select: none;
294 | -ms-user-select: none;
295 | user-select: none; }
296 | .swal2-icon.swal2-error {
297 | border-color: #f27474; }
298 | .swal2-icon.swal2-error .swal2-x-mark {
299 | position: relative;
300 | display: block; }
301 | .swal2-icon.swal2-error [class^='swal2-x-mark-line'] {
302 | position: absolute;
303 | height: 5px;
304 | width: 47px;
305 | background-color: #f27474;
306 | display: block;
307 | top: 37px;
308 | border-radius: 2px; }
309 | .swal2-icon.swal2-error [class^='swal2-x-mark-line'][class$='left'] {
310 | -webkit-transform: rotate(45deg);
311 | transform: rotate(45deg);
312 | left: 17px; }
313 | .swal2-icon.swal2-error [class^='swal2-x-mark-line'][class$='right'] {
314 | -webkit-transform: rotate(-45deg);
315 | transform: rotate(-45deg);
316 | right: 16px; }
317 | .swal2-icon.swal2-warning {
318 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
319 | color: #f8bb86;
320 | border-color: #facea8;
321 | font-size: 60px;
322 | line-height: 80px;
323 | text-align: center; }
324 | .swal2-icon.swal2-info {
325 | font-family: 'Open Sans', sans-serif;
326 | color: #3fc3ee;
327 | border-color: #9de0f6;
328 | font-size: 60px;
329 | line-height: 80px;
330 | text-align: center; }
331 | .swal2-icon.swal2-question {
332 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
333 | color: #87adbd;
334 | border-color: #c9dae1;
335 | font-size: 60px;
336 | line-height: 80px;
337 | text-align: center; }
338 | .swal2-icon.swal2-success {
339 | border-color: #a5dc86; }
340 | .swal2-icon.swal2-success [class^='swal2-success-circular-line'] {
341 | border-radius: 50%;
342 | position: absolute;
343 | width: 60px;
344 | height: 120px;
345 | -webkit-transform: rotate(45deg);
346 | transform: rotate(45deg); }
347 | .swal2-icon.swal2-success [class^='swal2-success-circular-line'][class$='left'] {
348 | border-radius: 120px 0 0 120px;
349 | top: -7px;
350 | left: -33px;
351 | -webkit-transform: rotate(-45deg);
352 | transform: rotate(-45deg);
353 | -webkit-transform-origin: 60px 60px;
354 | transform-origin: 60px 60px; }
355 | .swal2-icon.swal2-success [class^='swal2-success-circular-line'][class$='right'] {
356 | border-radius: 0 120px 120px 0;
357 | top: -11px;
358 | left: 30px;
359 | -webkit-transform: rotate(-45deg);
360 | transform: rotate(-45deg);
361 | -webkit-transform-origin: 0 60px;
362 | transform-origin: 0 60px; }
363 | .swal2-icon.swal2-success .swal2-success-ring {
364 | width: 80px;
365 | height: 80px;
366 | border: 4px solid rgba(165, 220, 134, 0.2);
367 | border-radius: 50%;
368 | -webkit-box-sizing: content-box;
369 | box-sizing: content-box;
370 | position: absolute;
371 | left: -4px;
372 | top: -4px;
373 | z-index: 2; }
374 | .swal2-icon.swal2-success .swal2-success-fix {
375 | width: 7px;
376 | height: 90px;
377 | position: absolute;
378 | left: 28px;
379 | top: 8px;
380 | z-index: 1;
381 | -webkit-transform: rotate(-45deg);
382 | transform: rotate(-45deg); }
383 | .swal2-icon.swal2-success [class^='swal2-success-line'] {
384 | height: 5px;
385 | background-color: #a5dc86;
386 | display: block;
387 | border-radius: 2px;
388 | position: absolute;
389 | z-index: 2; }
390 | .swal2-icon.swal2-success [class^='swal2-success-line'][class$='tip'] {
391 | width: 25px;
392 | left: 14px;
393 | top: 46px;
394 | -webkit-transform: rotate(45deg);
395 | transform: rotate(45deg); }
396 | .swal2-icon.swal2-success [class^='swal2-success-line'][class$='long'] {
397 | width: 47px;
398 | right: 8px;
399 | top: 38px;
400 | -webkit-transform: rotate(-45deg);
401 | transform: rotate(-45deg); }
402 |
403 | .swal2-progresssteps {
404 | font-weight: 600;
405 | margin: 0 0 20px;
406 | padding: 0; }
407 | .swal2-progresssteps li {
408 | display: inline-block;
409 | position: relative; }
410 | .swal2-progresssteps .swal2-progresscircle {
411 | background: #3085d6;
412 | border-radius: 2em;
413 | color: #fff;
414 | height: 2em;
415 | line-height: 2em;
416 | text-align: center;
417 | width: 2em;
418 | z-index: 20; }
419 | .swal2-progresssteps .swal2-progresscircle:first-child {
420 | margin-left: 0; }
421 | .swal2-progresssteps .swal2-progresscircle:last-child {
422 | margin-right: 0; }
423 | .swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep {
424 | background: #3085d6; }
425 | .swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep ~ .swal2-progresscircle {
426 | background: #add8e6; }
427 | .swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep ~ .swal2-progressline {
428 | background: #add8e6; }
429 | .swal2-progresssteps .swal2-progressline {
430 | background: #3085d6;
431 | height: .4em;
432 | margin: 0 -1px;
433 | z-index: 10; }
434 |
435 | [class^='swal2'] {
436 | -webkit-tap-highlight-color: transparent; }
437 |
438 | @-webkit-keyframes showSweetAlert {
439 | 0% {
440 | -webkit-transform: scale(0.7);
441 | transform: scale(0.7); }
442 | 45% {
443 | -webkit-transform: scale(1.05);
444 | transform: scale(1.05); }
445 | 80% {
446 | -webkit-transform: scale(0.95);
447 | transform: scale(0.95); }
448 | 100% {
449 | -webkit-transform: scale(1);
450 | transform: scale(1); } }
451 |
452 | @keyframes showSweetAlert {
453 | 0% {
454 | -webkit-transform: scale(0.7);
455 | transform: scale(0.7); }
456 | 45% {
457 | -webkit-transform: scale(1.05);
458 | transform: scale(1.05); }
459 | 80% {
460 | -webkit-transform: scale(0.95);
461 | transform: scale(0.95); }
462 | 100% {
463 | -webkit-transform: scale(1);
464 | transform: scale(1); } }
465 |
466 | @-webkit-keyframes hideSweetAlert {
467 | 0% {
468 | -webkit-transform: scale(1);
469 | transform: scale(1);
470 | opacity: 1; }
471 | 100% {
472 | -webkit-transform: scale(0.5);
473 | transform: scale(0.5);
474 | opacity: 0; } }
475 |
476 | @keyframes hideSweetAlert {
477 | 0% {
478 | -webkit-transform: scale(1);
479 | transform: scale(1);
480 | opacity: 1; }
481 | 100% {
482 | -webkit-transform: scale(0.5);
483 | transform: scale(0.5);
484 | opacity: 0; } }
485 |
486 | .swal2-show {
487 | -webkit-animation: showSweetAlert .3s;
488 | animation: showSweetAlert .3s; }
489 | .swal2-show.swal2-noanimation {
490 | -webkit-animation: none;
491 | animation: none; }
492 |
493 | .swal2-hide {
494 | -webkit-animation: hideSweetAlert .15s forwards;
495 | animation: hideSweetAlert .15s forwards; }
496 | .swal2-hide.swal2-noanimation {
497 | -webkit-animation: none;
498 | animation: none; }
499 |
500 | @-webkit-keyframes animate-success-tip {
501 | 0% {
502 | width: 0;
503 | left: 1px;
504 | top: 19px; }
505 | 54% {
506 | width: 0;
507 | left: 1px;
508 | top: 19px; }
509 | 70% {
510 | width: 50px;
511 | left: -8px;
512 | top: 37px; }
513 | 84% {
514 | width: 17px;
515 | left: 21px;
516 | top: 48px; }
517 | 100% {
518 | width: 25px;
519 | left: 14px;
520 | top: 45px; } }
521 |
522 | @keyframes animate-success-tip {
523 | 0% {
524 | width: 0;
525 | left: 1px;
526 | top: 19px; }
527 | 54% {
528 | width: 0;
529 | left: 1px;
530 | top: 19px; }
531 | 70% {
532 | width: 50px;
533 | left: -8px;
534 | top: 37px; }
535 | 84% {
536 | width: 17px;
537 | left: 21px;
538 | top: 48px; }
539 | 100% {
540 | width: 25px;
541 | left: 14px;
542 | top: 45px; } }
543 |
544 | @-webkit-keyframes animate-success-long {
545 | 0% {
546 | width: 0;
547 | right: 46px;
548 | top: 54px; }
549 | 65% {
550 | width: 0;
551 | right: 46px;
552 | top: 54px; }
553 | 84% {
554 | width: 55px;
555 | right: 0;
556 | top: 35px; }
557 | 100% {
558 | width: 47px;
559 | right: 8px;
560 | top: 38px; } }
561 |
562 | @keyframes animate-success-long {
563 | 0% {
564 | width: 0;
565 | right: 46px;
566 | top: 54px; }
567 | 65% {
568 | width: 0;
569 | right: 46px;
570 | top: 54px; }
571 | 84% {
572 | width: 55px;
573 | right: 0;
574 | top: 35px; }
575 | 100% {
576 | width: 47px;
577 | right: 8px;
578 | top: 38px; } }
579 |
580 | @-webkit-keyframes rotatePlaceholder {
581 | 0% {
582 | -webkit-transform: rotate(-45deg);
583 | transform: rotate(-45deg); }
584 | 5% {
585 | -webkit-transform: rotate(-45deg);
586 | transform: rotate(-45deg); }
587 | 12% {
588 | -webkit-transform: rotate(-405deg);
589 | transform: rotate(-405deg); }
590 | 100% {
591 | -webkit-transform: rotate(-405deg);
592 | transform: rotate(-405deg); } }
593 |
594 | @keyframes rotatePlaceholder {
595 | 0% {
596 | -webkit-transform: rotate(-45deg);
597 | transform: rotate(-45deg); }
598 | 5% {
599 | -webkit-transform: rotate(-45deg);
600 | transform: rotate(-45deg); }
601 | 12% {
602 | -webkit-transform: rotate(-405deg);
603 | transform: rotate(-405deg); }
604 | 100% {
605 | -webkit-transform: rotate(-405deg);
606 | transform: rotate(-405deg); } }
607 |
608 | .swal2-animate-success-line-tip {
609 | -webkit-animation: animate-success-tip .75s;
610 | animation: animate-success-tip .75s; }
611 |
612 | .swal2-animate-success-line-long {
613 | -webkit-animation: animate-success-long .75s;
614 | animation: animate-success-long .75s; }
615 |
616 | .swal2-success.swal2-animate-success-icon .swal2-success-circular-line-right {
617 | -webkit-animation: rotatePlaceholder 4.25s ease-in;
618 | animation: rotatePlaceholder 4.25s ease-in; }
619 |
620 | @-webkit-keyframes animate-error-icon {
621 | 0% {
622 | -webkit-transform: rotateX(100deg);
623 | transform: rotateX(100deg);
624 | opacity: 0; }
625 | 100% {
626 | -webkit-transform: rotateX(0deg);
627 | transform: rotateX(0deg);
628 | opacity: 1; } }
629 |
630 | @keyframes animate-error-icon {
631 | 0% {
632 | -webkit-transform: rotateX(100deg);
633 | transform: rotateX(100deg);
634 | opacity: 0; }
635 | 100% {
636 | -webkit-transform: rotateX(0deg);
637 | transform: rotateX(0deg);
638 | opacity: 1; } }
639 |
640 | .swal2-animate-error-icon {
641 | -webkit-animation: animate-error-icon .5s;
642 | animation: animate-error-icon .5s; }
643 |
644 | @-webkit-keyframes animate-x-mark {
645 | 0% {
646 | -webkit-transform: scale(0.4);
647 | transform: scale(0.4);
648 | margin-top: 26px;
649 | opacity: 0; }
650 | 50% {
651 | -webkit-transform: scale(0.4);
652 | transform: scale(0.4);
653 | margin-top: 26px;
654 | opacity: 0; }
655 | 80% {
656 | -webkit-transform: scale(1.15);
657 | transform: scale(1.15);
658 | margin-top: -6px; }
659 | 100% {
660 | -webkit-transform: scale(1);
661 | transform: scale(1);
662 | margin-top: 0;
663 | opacity: 1; } }
664 |
665 | @keyframes animate-x-mark {
666 | 0% {
667 | -webkit-transform: scale(0.4);
668 | transform: scale(0.4);
669 | margin-top: 26px;
670 | opacity: 0; }
671 | 50% {
672 | -webkit-transform: scale(0.4);
673 | transform: scale(0.4);
674 | margin-top: 26px;
675 | opacity: 0; }
676 | 80% {
677 | -webkit-transform: scale(1.15);
678 | transform: scale(1.15);
679 | margin-top: -6px; }
680 | 100% {
681 | -webkit-transform: scale(1);
682 | transform: scale(1);
683 | margin-top: 0;
684 | opacity: 1; } }
685 |
686 | .swal2-animate-x-mark {
687 | -webkit-animation: animate-x-mark .5s;
688 | animation: animate-x-mark .5s; }
689 |
690 | @-webkit-keyframes rotate-loading {
691 | 0% {
692 | -webkit-transform: rotate(0deg);
693 | transform: rotate(0deg); }
694 | 100% {
695 | -webkit-transform: rotate(360deg);
696 | transform: rotate(360deg); } }
697 |
698 | @keyframes rotate-loading {
699 | 0% {
700 | -webkit-transform: rotate(0deg);
701 | transform: rotate(0deg); }
702 | 100% {
703 | -webkit-transform: rotate(360deg);
704 | transform: rotate(360deg); } }
705 |
--------------------------------------------------------------------------------
/alert/sweetalert2.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * sweetalert2 v6.8.0
3 | * Released under the MIT License.
4 | */
5 | (function (global, factory) {
6 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
7 | typeof define === 'function' && define.amd ? define(factory) :
8 | (global.Sweetalert2 = factory());
9 | }(this, (function () { 'use strict';
10 |
11 | var defaultParams = {
12 | title: '',
13 | titleText: '',
14 | text: '',
15 | html: '',
16 | type: null,
17 | customClass: '',
18 | target: 'body',
19 | animation: true,
20 | allowOutsideClick: true,
21 | allowEscapeKey: true,
22 | allowEnterKey: true,
23 | showConfirmButton: true,
24 | showCancelButton: false,
25 | preConfirm: null,
26 | confirmButtonText: 'OK',
27 | confirmButtonAriaLabel: '',
28 | confirmButtonColor: '#3085d6',
29 | confirmButtonClass: null,
30 | cancelButtonText: 'Cancel',
31 | cancelButtonAriaLabel: '',
32 | cancelButtonColor: '#aaa',
33 | cancelButtonClass: null,
34 | buttonsStyling: true,
35 | reverseButtons: false,
36 | focusCancel: false,
37 | showCloseButton: false,
38 | showLoaderOnConfirm: false,
39 | imageUrl: null,
40 | imageWidth: null,
41 | imageHeight: null,
42 | imageAlt: '',
43 | imageClass: null,
44 | timer: null,
45 | width: 500,
46 | padding: 20,
47 | background: '#fff',
48 | input: null,
49 | inputPlaceholder: '',
50 | inputValue: '',
51 | inputOptions: {},
52 | inputAutoTrim: true,
53 | inputClass: null,
54 | inputAttributes: {},
55 | inputValidator: null,
56 | progressSteps: [],
57 | currentProgressStep: null,
58 | progressStepsDistance: '40px',
59 | onOpen: null,
60 | onClose: null,
61 | useRejections: true
62 | };
63 |
64 | var swalPrefix = 'swal2-';
65 |
66 | var prefix = function prefix(items) {
67 | var result = {};
68 | for (var i in items) {
69 | result[items[i]] = swalPrefix + items[i];
70 | }
71 | return result;
72 | };
73 |
74 | var swalClasses = prefix(['container', 'shown', 'iosfix', 'modal', 'overlay', 'fade', 'show', 'hide', 'noanimation', 'close', 'title', 'content', 'buttonswrapper', 'confirm', 'cancel', 'icon', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea', 'inputerror', 'validationerror', 'progresssteps', 'activeprogressstep', 'progresscircle', 'progressline', 'loading', 'styled']);
75 |
76 | var iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
77 |
78 | /*
79 | * Set hover, active and focus-states for buttons (source: http://www.sitepoint.com/javascript-generate-lighter-darker-color)
80 | */
81 | var colorLuminance = function colorLuminance(hex, lum) {
82 | // Validate hex string
83 | hex = String(hex).replace(/[^0-9a-f]/gi, '');
84 | if (hex.length < 6) {
85 | hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
86 | }
87 | lum = lum || 0;
88 |
89 | // Convert to decimal and change luminosity
90 | var rgb = '#';
91 | for (var i = 0; i < 3; i++) {
92 | var c = parseInt(hex.substr(i * 2, 2), 16);
93 | c = Math.round(Math.min(Math.max(0, c + c * lum), 255)).toString(16);
94 | rgb += ('00' + c).substr(c.length);
95 | }
96 |
97 | return rgb;
98 | };
99 |
100 | var uniqueArray = function uniqueArray(arr) {
101 | var result = [];
102 | for (var i in arr) {
103 | if (result.indexOf(arr[i]) === -1) {
104 | result.push(arr[i]);
105 | }
106 | }
107 | return result;
108 | };
109 |
110 | /* global MouseEvent */
111 |
112 | // Remember state in cases where opening and handling a modal will fiddle with it.
113 | var states = {
114 | previousWindowKeyDown: null,
115 | previousActiveElement: null,
116 | previousBodyPadding: null
117 |
118 | /*
119 | * Add modal + overlay to DOM
120 | */
121 | };var init = function init(params) {
122 | // Clean up the old modal if it exists
123 | var c = getContainer();
124 | if (c) {
125 | c.parentNode.removeChild(c);
126 | }
127 |
128 | if (typeof document === 'undefined') {
129 | console.error('SweetAlert2 requires document to initialize');
130 | return;
131 | }
132 |
133 | var container = document.createElement('div');
134 | container.className = swalClasses.container;
135 | container.innerHTML = sweetHTML;
136 |
137 | var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
138 | targetElement.appendChild(container);
139 |
140 | var modal = getModal();
141 | var input = getChildByClass(modal, swalClasses.input);
142 | var file = getChildByClass(modal, swalClasses.file);
143 | var range = modal.querySelector('.' + swalClasses.range + ' input');
144 | var rangeOutput = modal.querySelector('.' + swalClasses.range + ' output');
145 | var select = getChildByClass(modal, swalClasses.select);
146 | var checkbox = modal.querySelector('.' + swalClasses.checkbox + ' input');
147 | var textarea = getChildByClass(modal, swalClasses.textarea);
148 |
149 | input.oninput = function () {
150 | sweetAlert.resetValidationError();
151 | };
152 |
153 | input.onkeydown = function (event) {
154 | setTimeout(function () {
155 | if (event.keyCode === 13 && params.allowEnterKey) {
156 | event.stopPropagation();
157 | sweetAlert.clickConfirm();
158 | }
159 | }, 0);
160 | };
161 |
162 | file.onchange = function () {
163 | sweetAlert.resetValidationError();
164 | };
165 |
166 | range.oninput = function () {
167 | sweetAlert.resetValidationError();
168 | rangeOutput.value = range.value;
169 | };
170 |
171 | range.onchange = function () {
172 | sweetAlert.resetValidationError();
173 | range.previousSibling.value = range.value;
174 | };
175 |
176 | select.onchange = function () {
177 | sweetAlert.resetValidationError();
178 | };
179 |
180 | checkbox.onchange = function () {
181 | sweetAlert.resetValidationError();
182 | };
183 |
184 | textarea.oninput = function () {
185 | sweetAlert.resetValidationError();
186 | };
187 |
188 | return modal;
189 | };
190 |
191 | /*
192 | * Manipulate DOM
193 | */
194 |
195 | var sweetHTML = ('\n \n
\n
\n \n
\n
?
\n
!
\n
i
\n
\n
\n
\n
\n
\n
\n
\n \n \n
\n
\n
\n
\n \n \n
\n
\n
\n OK \n Cancel \n
\n
\xD7 \n
\n').replace(/(^|\n)\s*/g, '');
196 |
197 | var getContainer = function getContainer() {
198 | return document.body.querySelector('.' + swalClasses.container);
199 | };
200 |
201 | var getModal = function getModal() {
202 | return getContainer() ? getContainer().querySelector('.' + swalClasses.modal) : null;
203 | };
204 |
205 | var getIcons = function getIcons() {
206 | var modal = getModal();
207 | return modal.querySelectorAll('.' + swalClasses.icon);
208 | };
209 |
210 | var elementByClass = function elementByClass(className) {
211 | return getContainer() ? getContainer().querySelector('.' + className) : null;
212 | };
213 |
214 | var getTitle = function getTitle() {
215 | return elementByClass(swalClasses.title);
216 | };
217 |
218 | var getContent = function getContent() {
219 | return elementByClass(swalClasses.content);
220 | };
221 |
222 | var getImage = function getImage() {
223 | return elementByClass(swalClasses.image);
224 | };
225 |
226 | var getButtonsWrapper = function getButtonsWrapper() {
227 | return elementByClass(swalClasses.buttonswrapper);
228 | };
229 |
230 | var getProgressSteps = function getProgressSteps() {
231 | return elementByClass(swalClasses.progresssteps);
232 | };
233 |
234 | var getValidationError = function getValidationError() {
235 | return elementByClass(swalClasses.validationerror);
236 | };
237 |
238 | var getConfirmButton = function getConfirmButton() {
239 | return elementByClass(swalClasses.confirm);
240 | };
241 |
242 | var getCancelButton = function getCancelButton() {
243 | return elementByClass(swalClasses.cancel);
244 | };
245 |
246 | var getCloseButton = function getCloseButton() {
247 | return elementByClass(swalClasses.close);
248 | };
249 |
250 | var getFocusableElements = function getFocusableElements(focusCancel) {
251 | var buttons = [getConfirmButton(), getCancelButton()];
252 | if (focusCancel) {
253 | buttons.reverse();
254 | }
255 |
256 | var focusableElementsWithTabindex = Array.from(getModal().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'))
257 | // sort according to tabindex
258 | .sort(function (a, b) {
259 | a = parseInt(a.getAttribute('tabindex'));
260 | b = parseInt(b.getAttribute('tabindex'));
261 | if (a > b) {
262 | return 1;
263 | } else if (a < b) {
264 | return -1;
265 | }
266 | return 0;
267 | });
268 |
269 | var otherFocusableElements = Array.prototype.slice.call(getModal().querySelectorAll('button, input:not([type=hidden]), textarea, select, a, [tabindex="0"]'));
270 |
271 | return uniqueArray(buttons.concat(focusableElementsWithTabindex, otherFocusableElements));
272 | };
273 |
274 | var hasClass = function hasClass(elem, className) {
275 | if (elem.classList) {
276 | return elem.classList.contains(className);
277 | }
278 | return false;
279 | };
280 |
281 | var focusInput = function focusInput(input) {
282 | input.focus();
283 |
284 | // place cursor at end of text in text input
285 | if (input.type !== 'file') {
286 | // http://stackoverflow.com/a/2345915/1331425
287 | var val = input.value;
288 | input.value = '';
289 | input.value = val;
290 | }
291 | };
292 |
293 | var addClass = function addClass(elem, className) {
294 | if (!elem || !className) {
295 | return;
296 | }
297 | var classes = className.split(/\s+/).filter(Boolean);
298 | classes.forEach(function (className) {
299 | elem.classList.add(className);
300 | });
301 | };
302 |
303 | var removeClass = function removeClass(elem, className) {
304 | if (!elem || !className) {
305 | return;
306 | }
307 | var classes = className.split(/\s+/).filter(Boolean);
308 | classes.forEach(function (className) {
309 | elem.classList.remove(className);
310 | });
311 | };
312 |
313 | var getChildByClass = function getChildByClass(elem, className) {
314 | for (var i = 0; i < elem.childNodes.length; i++) {
315 | if (hasClass(elem.childNodes[i], className)) {
316 | return elem.childNodes[i];
317 | }
318 | }
319 | };
320 |
321 | var show = function show(elem, display) {
322 | if (!display) {
323 | display = 'block';
324 | }
325 | elem.style.opacity = '';
326 | elem.style.display = display;
327 | };
328 |
329 | var hide = function hide(elem) {
330 | elem.style.opacity = '';
331 | elem.style.display = 'none';
332 | };
333 |
334 | var empty = function empty(elem) {
335 | while (elem.firstChild) {
336 | elem.removeChild(elem.firstChild);
337 | }
338 | };
339 |
340 | // borrowed from jqeury $(elem).is(':visible') implementation
341 | var isVisible = function isVisible(elem) {
342 | return elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length;
343 | };
344 |
345 | var removeStyleProperty = function removeStyleProperty(elem, property) {
346 | if (elem.style.removeProperty) {
347 | elem.style.removeProperty(property);
348 | } else {
349 | elem.style.removeAttribute(property);
350 | }
351 | };
352 |
353 | var fireClick = function fireClick(node) {
354 | if (!isVisible(node)) {
355 | return false;
356 | }
357 |
358 | // Taken from http://www.nonobtrusive.com/2011/11/29/programatically-fire-crossbrowser-click-event-with-javascript/
359 | // Then fixed for today's Chrome browser.
360 | if (typeof MouseEvent === 'function') {
361 | // Up-to-date approach
362 | var mevt = new MouseEvent('click', {
363 | view: window,
364 | bubbles: false,
365 | cancelable: true
366 | });
367 | node.dispatchEvent(mevt);
368 | } else if (document.createEvent) {
369 | // Fallback
370 | var evt = document.createEvent('MouseEvents');
371 | evt.initEvent('click', false, false);
372 | node.dispatchEvent(evt);
373 | } else if (document.createEventObject) {
374 | node.fireEvent('onclick');
375 | } else if (typeof node.onclick === 'function') {
376 | node.onclick();
377 | }
378 | };
379 |
380 | var animationEndEvent = function () {
381 | var testEl = document.createElement('div');
382 | var transEndEventNames = {
383 | 'WebkitAnimation': 'webkitAnimationEnd',
384 | 'OAnimation': 'oAnimationEnd oanimationend',
385 | 'msAnimation': 'MSAnimationEnd',
386 | 'animation': 'animationend'
387 | };
388 | for (var i in transEndEventNames) {
389 | if (transEndEventNames.hasOwnProperty(i) && testEl.style[i] !== undefined) {
390 | return transEndEventNames[i];
391 | }
392 | }
393 |
394 | return false;
395 | }();
396 |
397 | // Reset previous window keydown handler and focued element
398 | var resetPrevState = function resetPrevState() {
399 | window.onkeydown = states.previousWindowKeyDown;
400 | if (states.previousActiveElement && states.previousActiveElement.focus) {
401 | var x = window.scrollX;
402 | var y = window.scrollY;
403 | states.previousActiveElement.focus();
404 | if (x && y) {
405 | // IE has no scrollX/scrollY support
406 | window.scrollTo(x, y);
407 | }
408 | }
409 | };
410 |
411 | // Measure width of scrollbar
412 | // https://github.com/twbs/bootstrap/blob/master/js/modal.js#L279-L286
413 | var measureScrollbar = function measureScrollbar() {
414 | var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
415 | if (supportsTouch) {
416 | return 0;
417 | }
418 | var scrollDiv = document.createElement('div');
419 | scrollDiv.style.width = '50px';
420 | scrollDiv.style.height = '50px';
421 | scrollDiv.style.overflow = 'scroll';
422 | document.body.appendChild(scrollDiv);
423 | var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
424 | document.body.removeChild(scrollDiv);
425 | return scrollbarWidth;
426 | };
427 |
428 | // JavaScript Debounce Function
429 | // Simplivied version of https://davidwalsh.name/javascript-debounce-function
430 | var debounce = function debounce(func, wait) {
431 | var timeout = void 0;
432 | return function () {
433 | var later = function later() {
434 | timeout = null;
435 | func();
436 | };
437 | clearTimeout(timeout);
438 | timeout = setTimeout(later, wait);
439 | };
440 | };
441 |
442 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
443 | return typeof obj;
444 | } : function (obj) {
445 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
446 | };
447 |
448 |
449 |
450 |
451 |
452 | var asyncGenerator = function () {
453 | function AwaitValue(value) {
454 | this.value = value;
455 | }
456 |
457 | function AsyncGenerator(gen) {
458 | var front, back;
459 |
460 | function send(key, arg) {
461 | return new Promise(function (resolve, reject) {
462 | var request = {
463 | key: key,
464 | arg: arg,
465 | resolve: resolve,
466 | reject: reject,
467 | next: null
468 | };
469 |
470 | if (back) {
471 | back = back.next = request;
472 | } else {
473 | front = back = request;
474 | resume(key, arg);
475 | }
476 | });
477 | }
478 |
479 | function resume(key, arg) {
480 | try {
481 | var result = gen[key](arg);
482 | var value = result.value;
483 |
484 | if (value instanceof AwaitValue) {
485 | Promise.resolve(value.value).then(function (arg) {
486 | resume("next", arg);
487 | }, function (arg) {
488 | resume("throw", arg);
489 | });
490 | } else {
491 | settle(result.done ? "return" : "normal", result.value);
492 | }
493 | } catch (err) {
494 | settle("throw", err);
495 | }
496 | }
497 |
498 | function settle(type, value) {
499 | switch (type) {
500 | case "return":
501 | front.resolve({
502 | value: value,
503 | done: true
504 | });
505 | break;
506 |
507 | case "throw":
508 | front.reject(value);
509 | break;
510 |
511 | default:
512 | front.resolve({
513 | value: value,
514 | done: false
515 | });
516 | break;
517 | }
518 |
519 | front = front.next;
520 |
521 | if (front) {
522 | resume(front.key, front.arg);
523 | } else {
524 | back = null;
525 | }
526 | }
527 |
528 | this._invoke = send;
529 |
530 | if (typeof gen.return !== "function") {
531 | this.return = undefined;
532 | }
533 | }
534 |
535 | if (typeof Symbol === "function" && Symbol.asyncIterator) {
536 | AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
537 | return this;
538 | };
539 | }
540 |
541 | AsyncGenerator.prototype.next = function (arg) {
542 | return this._invoke("next", arg);
543 | };
544 |
545 | AsyncGenerator.prototype.throw = function (arg) {
546 | return this._invoke("throw", arg);
547 | };
548 |
549 | AsyncGenerator.prototype.return = function (arg) {
550 | return this._invoke("return", arg);
551 | };
552 |
553 | return {
554 | wrap: function (fn) {
555 | return function () {
556 | return new AsyncGenerator(fn.apply(this, arguments));
557 | };
558 | },
559 | await: function (value) {
560 | return new AwaitValue(value);
561 | }
562 | };
563 | }();
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 | var _extends = Object.assign || function (target) {
580 | for (var i = 1; i < arguments.length; i++) {
581 | var source = arguments[i];
582 |
583 | for (var key in source) {
584 | if (Object.prototype.hasOwnProperty.call(source, key)) {
585 | target[key] = source[key];
586 | }
587 | }
588 | }
589 |
590 | return target;
591 | };
592 |
593 | var modalParams = _extends({}, defaultParams);
594 | var queue = [];
595 | var swal2Observer = void 0;
596 |
597 | /*
598 | * Set type, text and actions on modal
599 | */
600 | var setParameters = function setParameters(params) {
601 | // If a custom element is set, determine if it is valid
602 | if (typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
603 | console.warn('SweetAlert2: Target parameter is not valid, defaulting to "body"');
604 | params.target = 'body';
605 | }
606 |
607 | var modal = void 0;
608 | var oldModal = getModal();
609 | var targetElement = typeof params.target === 'string' ? document.querySelector(params.target) : params.target;
610 | // If the model target has changed, refresh the modal
611 | if (oldModal && targetElement && oldModal.parentNode !== targetElement.parentNode) {
612 | modal = init(params);
613 | } else {
614 | modal = oldModal || init(params);
615 | }
616 |
617 | for (var param in params) {
618 | if (!sweetAlert.isValidParameter(param)) {
619 | console.warn('SweetAlert2: Unknown parameter "' + param + '"');
620 | }
621 | }
622 |
623 | // Set modal width
624 | modal.style.width = typeof params.width === 'number' ? params.width + 'px' : params.width;
625 |
626 | modal.style.padding = params.padding + 'px';
627 | modal.style.background = params.background;
628 | var successIconParts = modal.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
629 | for (var i = 0; i < successIconParts.length; i++) {
630 | successIconParts[i].style.background = params.background;
631 | }
632 |
633 | var title = getTitle();
634 | var content = getContent();
635 | var buttonsWrapper = getButtonsWrapper();
636 | var confirmButton = getConfirmButton();
637 | var cancelButton = getCancelButton();
638 | var closeButton = getCloseButton();
639 |
640 | // Title
641 | if (params.titleText) {
642 | title.innerText = params.titleText;
643 | } else {
644 | title.innerHTML = params.title.split('\n').join(' ');
645 | }
646 |
647 | // Content
648 | if (params.text || params.html) {
649 | if (_typeof(params.html) === 'object') {
650 | content.innerHTML = '';
651 | if (0 in params.html) {
652 | for (var _i = 0; _i in params.html; _i++) {
653 | content.appendChild(params.html[_i].cloneNode(true));
654 | }
655 | } else {
656 | content.appendChild(params.html.cloneNode(true));
657 | }
658 | } else if (params.html) {
659 | content.innerHTML = params.html;
660 | } else if (params.text) {
661 | content.textContent = params.text;
662 | }
663 | show(content);
664 | } else {
665 | hide(content);
666 | }
667 |
668 | // Close button
669 | if (params.showCloseButton) {
670 | show(closeButton);
671 | } else {
672 | hide(closeButton);
673 | }
674 |
675 | // Custom Class
676 | modal.className = swalClasses.modal;
677 | if (params.customClass) {
678 | addClass(modal, params.customClass);
679 | }
680 |
681 | // Progress steps
682 | var progressStepsContainer = getProgressSteps();
683 | var currentProgressStep = parseInt(params.currentProgressStep === null ? sweetAlert.getQueueStep() : params.currentProgressStep, 10);
684 | if (params.progressSteps.length) {
685 | show(progressStepsContainer);
686 | empty(progressStepsContainer);
687 | if (currentProgressStep >= params.progressSteps.length) {
688 | console.warn('SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
689 | }
690 | params.progressSteps.forEach(function (step, index) {
691 | var circle = document.createElement('li');
692 | addClass(circle, swalClasses.progresscircle);
693 | circle.innerHTML = step;
694 | if (index === currentProgressStep) {
695 | addClass(circle, swalClasses.activeprogressstep);
696 | }
697 | progressStepsContainer.appendChild(circle);
698 | if (index !== params.progressSteps.length - 1) {
699 | var line = document.createElement('li');
700 | addClass(line, swalClasses.progressline);
701 | line.style.width = params.progressStepsDistance;
702 | progressStepsContainer.appendChild(line);
703 | }
704 | });
705 | } else {
706 | hide(progressStepsContainer);
707 | }
708 |
709 | // Icon
710 | var icons = getIcons();
711 | for (var _i2 = 0; _i2 < icons.length; _i2++) {
712 | hide(icons[_i2]);
713 | }
714 | if (params.type) {
715 | var validType = false;
716 | for (var iconType in iconTypes) {
717 | if (params.type === iconType) {
718 | validType = true;
719 | break;
720 | }
721 | }
722 | if (!validType) {
723 | console.error('SweetAlert2: Unknown alert type: ' + params.type);
724 | return false;
725 | }
726 | var icon = modal.querySelector('.' + swalClasses.icon + '.' + iconTypes[params.type]);
727 | show(icon);
728 |
729 | // Animate icon
730 | if (params.animation) {
731 | switch (params.type) {
732 | case 'success':
733 | addClass(icon, 'swal2-animate-success-icon');
734 | addClass(icon.querySelector('.swal2-success-line-tip'), 'swal2-animate-success-line-tip');
735 | addClass(icon.querySelector('.swal2-success-line-long'), 'swal2-animate-success-line-long');
736 | break;
737 | case 'error':
738 | addClass(icon, 'swal2-animate-error-icon');
739 | addClass(icon.querySelector('.swal2-x-mark'), 'swal2-animate-x-mark');
740 | break;
741 | default:
742 | break;
743 | }
744 | }
745 | }
746 |
747 | // Custom image
748 | var image = getImage();
749 | if (params.imageUrl) {
750 | image.setAttribute('src', params.imageUrl);
751 | image.setAttribute('alt', params.imageAlt);
752 | show(image);
753 |
754 | if (params.imageWidth) {
755 | image.setAttribute('width', params.imageWidth);
756 | } else {
757 | image.removeAttribute('width');
758 | }
759 |
760 | if (params.imageHeight) {
761 | image.setAttribute('height', params.imageHeight);
762 | } else {
763 | image.removeAttribute('height');
764 | }
765 |
766 | image.className = swalClasses.image;
767 | if (params.imageClass) {
768 | addClass(image, params.imageClass);
769 | }
770 | } else {
771 | hide(image);
772 | }
773 |
774 | // Cancel button
775 | if (params.showCancelButton) {
776 | cancelButton.style.display = 'inline-block';
777 | } else {
778 | hide(cancelButton);
779 | }
780 |
781 | // Confirm button
782 | if (params.showConfirmButton) {
783 | removeStyleProperty(confirmButton, 'display');
784 | } else {
785 | hide(confirmButton);
786 | }
787 |
788 | // Buttons wrapper
789 | if (!params.showConfirmButton && !params.showCancelButton) {
790 | hide(buttonsWrapper);
791 | } else {
792 | show(buttonsWrapper);
793 | }
794 |
795 | // Edit text on confirm and cancel buttons
796 | confirmButton.innerHTML = params.confirmButtonText;
797 | cancelButton.innerHTML = params.cancelButtonText;
798 |
799 | // ARIA labels for confirm and cancel buttons
800 | confirmButton.setAttribute('aria-label', params.confirmButtonAriaLabel);
801 | cancelButton.setAttribute('aria-label', params.cancelButtonAriaLabel);
802 |
803 | // Set buttons to selected background colors
804 | if (params.buttonsStyling) {
805 | confirmButton.style.backgroundColor = params.confirmButtonColor;
806 | cancelButton.style.backgroundColor = params.cancelButtonColor;
807 | }
808 |
809 | // Add buttons custom classes
810 | confirmButton.className = swalClasses.confirm;
811 | addClass(confirmButton, params.confirmButtonClass);
812 | cancelButton.className = swalClasses.cancel;
813 | addClass(cancelButton, params.cancelButtonClass);
814 |
815 | // Buttons styling
816 | if (params.buttonsStyling) {
817 | addClass(confirmButton, swalClasses.styled);
818 | addClass(cancelButton, swalClasses.styled);
819 | } else {
820 | removeClass(confirmButton, swalClasses.styled);
821 | removeClass(cancelButton, swalClasses.styled);
822 |
823 | confirmButton.style.backgroundColor = confirmButton.style.borderLeftColor = confirmButton.style.borderRightColor = '';
824 | cancelButton.style.backgroundColor = cancelButton.style.borderLeftColor = cancelButton.style.borderRightColor = '';
825 | }
826 |
827 | // CSS animation
828 | if (params.animation === true) {
829 | removeClass(modal, swalClasses.noanimation);
830 | } else {
831 | addClass(modal, swalClasses.noanimation);
832 | }
833 |
834 | // showLoaderOnConfirm && preConfirm
835 | if (params.showLoaderOnConfirm && !params.preConfirm) {
836 | console.warn('SweetAlert2: showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://limonte.github.io/sweetalert2/#ajax-request');
837 | }
838 | };
839 |
840 | /*
841 | * Animations
842 | */
843 | var openModal = function openModal(animation, onComplete) {
844 | var container = getContainer();
845 | var modal = getModal();
846 |
847 | if (animation) {
848 | addClass(modal, swalClasses.show);
849 | addClass(container, swalClasses.fade);
850 | removeClass(modal, swalClasses.hide);
851 | } else {
852 | removeClass(modal, swalClasses.fade);
853 | }
854 | show(modal);
855 |
856 | // scrolling is 'hidden' until animation is done, after that 'auto'
857 | container.style.overflowY = 'hidden';
858 | if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
859 | modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
860 | modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
861 | container.style.overflowY = 'auto';
862 | });
863 | } else {
864 | container.style.overflowY = 'auto';
865 | }
866 |
867 | addClass(document.documentElement, swalClasses.shown);
868 | addClass(document.body, swalClasses.shown);
869 | addClass(container, swalClasses.shown);
870 | fixScrollbar();
871 | iOSfix();
872 | states.previousActiveElement = document.activeElement;
873 | if (onComplete !== null && typeof onComplete === 'function') {
874 | setTimeout(function () {
875 | onComplete(modal);
876 | });
877 | }
878 | };
879 |
880 | var fixScrollbar = function fixScrollbar() {
881 | // for queues, do not do this more than once
882 | if (states.previousBodyPadding !== null) {
883 | return;
884 | }
885 | // if the body has overflow
886 | if (document.body.scrollHeight > window.innerHeight) {
887 | // add padding so the content doesn't shift after removal of scrollbar
888 | states.previousBodyPadding = document.body.style.paddingRight;
889 | document.body.style.paddingRight = measureScrollbar() + 'px';
890 | }
891 | };
892 |
893 | var undoScrollbar = function undoScrollbar() {
894 | if (states.previousBodyPadding !== null) {
895 | document.body.style.paddingRight = states.previousBodyPadding;
896 | states.previousBodyPadding = null;
897 | }
898 | };
899 |
900 | // Fix iOS scrolling http://stackoverflow.com/q/39626302/1331425
901 | var iOSfix = function iOSfix() {
902 | var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
903 | if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
904 | var offset = document.body.scrollTop;
905 | document.body.style.top = offset * -1 + 'px';
906 | addClass(document.body, swalClasses.iosfix);
907 | }
908 | };
909 |
910 | var undoIOSfix = function undoIOSfix() {
911 | if (hasClass(document.body, swalClasses.iosfix)) {
912 | var offset = parseInt(document.body.style.top, 10);
913 | removeClass(document.body, swalClasses.iosfix);
914 | document.body.style.top = '';
915 | document.body.scrollTop = offset * -1;
916 | }
917 | };
918 |
919 | // SweetAlert entry point
920 | var sweetAlert = function sweetAlert() {
921 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
922 | args[_key] = arguments[_key];
923 | }
924 |
925 | if (args[0] === undefined) {
926 | console.error('SweetAlert2 expects at least 1 attribute!');
927 | return false;
928 | }
929 |
930 | var params = _extends({}, modalParams);
931 |
932 | switch (_typeof(args[0])) {
933 | case 'string':
934 | params.title = args[0];
935 | params.html = args[1];
936 | params.type = args[2];
937 |
938 | break;
939 |
940 | case 'object':
941 | _extends(params, args[0]);
942 | params.extraParams = args[0].extraParams;
943 |
944 | if (params.input === 'email' && params.inputValidator === null) {
945 | params.inputValidator = function (email) {
946 | return new Promise(function (resolve, reject) {
947 | var emailRegex = /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
948 | if (emailRegex.test(email)) {
949 | resolve();
950 | } else {
951 | reject('Invalid email address');
952 | }
953 | });
954 | };
955 | }
956 |
957 | if (params.input === 'url' && params.inputValidator === null) {
958 | params.inputValidator = function (url) {
959 | return new Promise(function (resolve, reject) {
960 | // taken from https://stackoverflow.com/a/3809435/1331425
961 | var urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)$/;
962 | if (urlRegex.test(url)) {
963 | resolve();
964 | } else {
965 | reject('Invalid URL');
966 | }
967 | });
968 | };
969 | }
970 | break;
971 |
972 | default:
973 | console.error('SweetAlert2: Unexpected type of argument! Expected "string" or "object", got ' + _typeof(args[0]));
974 | return false;
975 | }
976 |
977 | setParameters(params);
978 |
979 | var container = getContainer();
980 | var modal = getModal();
981 |
982 | return new Promise(function (resolve, reject) {
983 | // Close on timer
984 | if (params.timer) {
985 | modal.timeout = setTimeout(function () {
986 | sweetAlert.closeModal(params.onClose);
987 | if (params.useRejections) {
988 | reject('timer');
989 | } else {
990 | resolve({ dismiss: 'timer' });
991 | }
992 | }, params.timer);
993 | }
994 |
995 | // Get input element by specified type or, if type isn't specified, by params.input
996 | var getInput = function getInput(inputType) {
997 | inputType = inputType || params.input;
998 | if (!inputType) {
999 | return null;
1000 | }
1001 | switch (inputType) {
1002 | case 'select':
1003 | case 'textarea':
1004 | case 'file':
1005 | return getChildByClass(modal, swalClasses[inputType]);
1006 | case 'checkbox':
1007 | return modal.querySelector('.' + swalClasses.checkbox + ' input');
1008 | case 'radio':
1009 | return modal.querySelector('.' + swalClasses.radio + ' input:checked') || modal.querySelector('.' + swalClasses.radio + ' input:first-child');
1010 | case 'range':
1011 | return modal.querySelector('.' + swalClasses.range + ' input');
1012 | default:
1013 | return getChildByClass(modal, swalClasses.input);
1014 | }
1015 | };
1016 |
1017 | // Get the value of the modal input
1018 | var getInputValue = function getInputValue() {
1019 | var input = getInput();
1020 | if (!input) {
1021 | return null;
1022 | }
1023 | switch (params.input) {
1024 | case 'checkbox':
1025 | return input.checked ? 1 : 0;
1026 | case 'radio':
1027 | return input.checked ? input.value : null;
1028 | case 'file':
1029 | return input.files.length ? input.files[0] : null;
1030 | default:
1031 | return params.inputAutoTrim ? input.value.trim() : input.value;
1032 | }
1033 | };
1034 |
1035 | // input autofocus
1036 | if (params.input) {
1037 | setTimeout(function () {
1038 | var input = getInput();
1039 | if (input) {
1040 | focusInput(input);
1041 | }
1042 | }, 0);
1043 | }
1044 |
1045 | var confirm = function confirm(value) {
1046 | if (params.showLoaderOnConfirm) {
1047 | sweetAlert.showLoading();
1048 | }
1049 |
1050 | if (params.preConfirm) {
1051 | params.preConfirm(value, params.extraParams).then(function (preConfirmValue) {
1052 | sweetAlert.closeModal(params.onClose);
1053 | resolve(preConfirmValue || value);
1054 | }, function (error) {
1055 | sweetAlert.hideLoading();
1056 | if (error) {
1057 | sweetAlert.showValidationError(error);
1058 | }
1059 | });
1060 | } else {
1061 | sweetAlert.closeModal(params.onClose);
1062 | if (params.useRejections) {
1063 | resolve(value);
1064 | } else {
1065 | resolve({ value: value });
1066 | }
1067 | }
1068 | };
1069 |
1070 | // Mouse interactions
1071 | var onButtonEvent = function onButtonEvent(event) {
1072 | var e = event || window.event;
1073 | var target = e.target || e.srcElement;
1074 | var confirmButton = getConfirmButton();
1075 | var cancelButton = getCancelButton();
1076 | var targetedConfirm = confirmButton && (confirmButton === target || confirmButton.contains(target));
1077 | var targetedCancel = cancelButton && (cancelButton === target || cancelButton.contains(target));
1078 |
1079 | switch (e.type) {
1080 | case 'mouseover':
1081 | case 'mouseup':
1082 | if (params.buttonsStyling) {
1083 | if (targetedConfirm) {
1084 | confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.1);
1085 | } else if (targetedCancel) {
1086 | cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.1);
1087 | }
1088 | }
1089 | break;
1090 | case 'mouseout':
1091 | if (params.buttonsStyling) {
1092 | if (targetedConfirm) {
1093 | confirmButton.style.backgroundColor = params.confirmButtonColor;
1094 | } else if (targetedCancel) {
1095 | cancelButton.style.backgroundColor = params.cancelButtonColor;
1096 | }
1097 | }
1098 | break;
1099 | case 'mousedown':
1100 | if (params.buttonsStyling) {
1101 | if (targetedConfirm) {
1102 | confirmButton.style.backgroundColor = colorLuminance(params.confirmButtonColor, -0.2);
1103 | } else if (targetedCancel) {
1104 | cancelButton.style.backgroundColor = colorLuminance(params.cancelButtonColor, -0.2);
1105 | }
1106 | }
1107 | break;
1108 | case 'click':
1109 | // Clicked 'confirm'
1110 | if (targetedConfirm && sweetAlert.isVisible()) {
1111 | sweetAlert.disableButtons();
1112 | if (params.input) {
1113 | var inputValue = getInputValue();
1114 |
1115 | if (params.inputValidator) {
1116 | sweetAlert.disableInput();
1117 | params.inputValidator(inputValue, params.extraParams).then(function () {
1118 | sweetAlert.enableButtons();
1119 | sweetAlert.enableInput();
1120 | confirm(inputValue);
1121 | }, function (error) {
1122 | sweetAlert.enableButtons();
1123 | sweetAlert.enableInput();
1124 | if (error) {
1125 | sweetAlert.showValidationError(error);
1126 | }
1127 | });
1128 | } else {
1129 | confirm(inputValue);
1130 | }
1131 | } else {
1132 | confirm(true);
1133 | }
1134 |
1135 | // Clicked 'cancel'
1136 | } else if (targetedCancel && sweetAlert.isVisible()) {
1137 | sweetAlert.disableButtons();
1138 | sweetAlert.closeModal(params.onClose);
1139 | if (params.useRejections) {
1140 | reject('cancel');
1141 | } else {
1142 | resolve({ dismiss: 'cancel' });
1143 | }
1144 | }
1145 | break;
1146 | default:
1147 | }
1148 | };
1149 |
1150 | var buttons = modal.querySelectorAll('button');
1151 | for (var i = 0; i < buttons.length; i++) {
1152 | buttons[i].onclick = onButtonEvent;
1153 | buttons[i].onmouseover = onButtonEvent;
1154 | buttons[i].onmouseout = onButtonEvent;
1155 | buttons[i].onmousedown = onButtonEvent;
1156 | }
1157 |
1158 | // Closing modal by close button
1159 | getCloseButton().onclick = function () {
1160 | sweetAlert.closeModal(params.onClose);
1161 | if (params.useRejections) {
1162 | reject('close');
1163 | } else {
1164 | resolve({ dismiss: 'close' });
1165 | }
1166 | };
1167 |
1168 | // Closing modal by overlay click
1169 | container.onclick = function (e) {
1170 | if (e.target !== container) {
1171 | return;
1172 | }
1173 | if (params.allowOutsideClick) {
1174 | sweetAlert.closeModal(params.onClose);
1175 | if (params.useRejections) {
1176 | reject('overlay');
1177 | } else {
1178 | resolve({ dismiss: 'overlay' });
1179 | }
1180 | }
1181 | };
1182 |
1183 | var buttonsWrapper = getButtonsWrapper();
1184 | var confirmButton = getConfirmButton();
1185 | var cancelButton = getCancelButton();
1186 |
1187 | // Reverse buttons (Confirm on the right side)
1188 | if (params.reverseButtons) {
1189 | confirmButton.parentNode.insertBefore(cancelButton, confirmButton);
1190 | } else {
1191 | confirmButton.parentNode.insertBefore(confirmButton, cancelButton);
1192 | }
1193 |
1194 | // Focus handling
1195 | var setFocus = function setFocus(index, increment) {
1196 | var focusableElements = getFocusableElements(params.focusCancel);
1197 | // search for visible elements and select the next possible match
1198 | for (var _i3 = 0; _i3 < focusableElements.length; _i3++) {
1199 | index = index + increment;
1200 |
1201 | // rollover to first item
1202 | if (index === focusableElements.length) {
1203 | index = 0;
1204 |
1205 | // go to last item
1206 | } else if (index === -1) {
1207 | index = focusableElements.length - 1;
1208 | }
1209 |
1210 | // determine if element is visible
1211 | var el = focusableElements[index];
1212 | if (isVisible(el)) {
1213 | return el.focus();
1214 | }
1215 | }
1216 | };
1217 |
1218 | var handleKeyDown = function handleKeyDown(event) {
1219 | var e = event || window.event;
1220 | var keyCode = e.keyCode || e.which;
1221 |
1222 | if ([9, 13, 32, 27, 37, 38, 39, 40].indexOf(keyCode) === -1) {
1223 | // Don't do work on keys we don't care about.
1224 | return;
1225 | }
1226 |
1227 | var targetElement = e.target || e.srcElement;
1228 |
1229 | var focusableElements = getFocusableElements(params.focusCancel);
1230 | var btnIndex = -1; // Find the button - note, this is a nodelist, not an array.
1231 | for (var _i4 = 0; _i4 < focusableElements.length; _i4++) {
1232 | if (targetElement === focusableElements[_i4]) {
1233 | btnIndex = _i4;
1234 | break;
1235 | }
1236 | }
1237 |
1238 | // TAB
1239 | if (keyCode === 9) {
1240 | if (!e.shiftKey) {
1241 | // Cycle to the next button
1242 | setFocus(btnIndex, 1);
1243 | } else {
1244 | // Cycle to the prev button
1245 | setFocus(btnIndex, -1);
1246 | }
1247 | e.stopPropagation();
1248 | e.preventDefault();
1249 |
1250 | // ARROWS - switch focus between buttons
1251 | } else if (keyCode === 37 || keyCode === 38 || keyCode === 39 || keyCode === 40) {
1252 | // focus Cancel button if Confirm button is currently focused
1253 | if (document.activeElement === confirmButton && isVisible(cancelButton)) {
1254 | cancelButton.focus();
1255 | // and vice versa
1256 | } else if (document.activeElement === cancelButton && isVisible(confirmButton)) {
1257 | confirmButton.focus();
1258 | }
1259 |
1260 | // ENTER/SPACE
1261 | } else if (keyCode === 13 || keyCode === 32) {
1262 | if (btnIndex === -1 && params.allowEnterKey) {
1263 | // ENTER/SPACE clicked outside of a button.
1264 | if (params.focusCancel) {
1265 | fireClick(cancelButton, e);
1266 | } else {
1267 | fireClick(confirmButton, e);
1268 | }
1269 | e.stopPropagation();
1270 | e.preventDefault();
1271 | }
1272 |
1273 | // ESC
1274 | } else if (keyCode === 27 && params.allowEscapeKey === true) {
1275 | sweetAlert.closeModal(params.onClose);
1276 | if (params.useRejections) {
1277 | reject('esc');
1278 | } else {
1279 | resolve({ dismiss: 'esc' });
1280 | }
1281 | }
1282 | };
1283 |
1284 | if (!window.onkeydown || window.onkeydown.toString() !== handleKeyDown.toString()) {
1285 | states.previousWindowKeyDown = window.onkeydown;
1286 | window.onkeydown = handleKeyDown;
1287 | }
1288 |
1289 | // Loading state
1290 | if (params.buttonsStyling) {
1291 | confirmButton.style.borderLeftColor = params.confirmButtonColor;
1292 | confirmButton.style.borderRightColor = params.confirmButtonColor;
1293 | }
1294 |
1295 | /**
1296 | * Show spinner instead of Confirm button and disable Cancel button
1297 | */
1298 | sweetAlert.hideLoading = sweetAlert.disableLoading = function () {
1299 | if (!params.showConfirmButton) {
1300 | hide(confirmButton);
1301 | if (!params.showCancelButton) {
1302 | hide(getButtonsWrapper());
1303 | }
1304 | }
1305 | removeClass(buttonsWrapper, swalClasses.loading);
1306 | removeClass(modal, swalClasses.loading);
1307 | confirmButton.disabled = false;
1308 | cancelButton.disabled = false;
1309 | };
1310 |
1311 | sweetAlert.getTitle = function () {
1312 | return getTitle();
1313 | };
1314 | sweetAlert.getContent = function () {
1315 | return getContent();
1316 | };
1317 | sweetAlert.getInput = function () {
1318 | return getInput();
1319 | };
1320 | sweetAlert.getImage = function () {
1321 | return getImage();
1322 | };
1323 | sweetAlert.getButtonsWrapper = function () {
1324 | return getButtonsWrapper();
1325 | };
1326 | sweetAlert.getConfirmButton = function () {
1327 | return getConfirmButton();
1328 | };
1329 | sweetAlert.getCancelButton = function () {
1330 | return getCancelButton();
1331 | };
1332 |
1333 | sweetAlert.enableButtons = function () {
1334 | confirmButton.disabled = false;
1335 | cancelButton.disabled = false;
1336 | };
1337 |
1338 | sweetAlert.disableButtons = function () {
1339 | confirmButton.disabled = true;
1340 | cancelButton.disabled = true;
1341 | };
1342 |
1343 | sweetAlert.enableConfirmButton = function () {
1344 | confirmButton.disabled = false;
1345 | };
1346 |
1347 | sweetAlert.disableConfirmButton = function () {
1348 | confirmButton.disabled = true;
1349 | };
1350 |
1351 | sweetAlert.enableInput = function () {
1352 | var input = getInput();
1353 | if (!input) {
1354 | return false;
1355 | }
1356 | if (input.type === 'radio') {
1357 | var radiosContainer = input.parentNode.parentNode;
1358 | var radios = radiosContainer.querySelectorAll('input');
1359 | for (var _i5 = 0; _i5 < radios.length; _i5++) {
1360 | radios[_i5].disabled = false;
1361 | }
1362 | } else {
1363 | input.disabled = false;
1364 | }
1365 | };
1366 |
1367 | sweetAlert.disableInput = function () {
1368 | var input = getInput();
1369 | if (!input) {
1370 | return false;
1371 | }
1372 | if (input && input.type === 'radio') {
1373 | var radiosContainer = input.parentNode.parentNode;
1374 | var radios = radiosContainer.querySelectorAll('input');
1375 | for (var _i6 = 0; _i6 < radios.length; _i6++) {
1376 | radios[_i6].disabled = true;
1377 | }
1378 | } else {
1379 | input.disabled = true;
1380 | }
1381 | };
1382 |
1383 | // Set modal min-height to disable scrolling inside the modal
1384 | sweetAlert.recalculateHeight = debounce(function () {
1385 | var modal = getModal();
1386 | if (!modal) {
1387 | return;
1388 | }
1389 | var prevState = modal.style.display;
1390 | modal.style.minHeight = '';
1391 | show(modal);
1392 | modal.style.minHeight = modal.scrollHeight + 1 + 'px';
1393 | modal.style.display = prevState;
1394 | }, 50);
1395 |
1396 | // Show block with validation error
1397 | sweetAlert.showValidationError = function (error) {
1398 | var validationError = getValidationError();
1399 | validationError.innerHTML = error;
1400 | show(validationError);
1401 |
1402 | var input = getInput();
1403 | if (input) {
1404 | input.setAttribute('aria-invalid', true);
1405 | input.setAttribute('aria-describedBy', swalClasses.validationerror);
1406 | focusInput(input);
1407 | addClass(input, swalClasses.inputerror);
1408 | }
1409 | };
1410 |
1411 | // Hide block with validation error
1412 | sweetAlert.resetValidationError = function () {
1413 | var validationError = getValidationError();
1414 | hide(validationError);
1415 | sweetAlert.recalculateHeight();
1416 |
1417 | var input = getInput();
1418 | if (input) {
1419 | input.removeAttribute('aria-invalid');
1420 | input.removeAttribute('aria-describedBy');
1421 | removeClass(input, swalClasses.inputerror);
1422 | }
1423 | };
1424 |
1425 | sweetAlert.getProgressSteps = function () {
1426 | return params.progressSteps;
1427 | };
1428 |
1429 | sweetAlert.setProgressSteps = function (progressSteps) {
1430 | params.progressSteps = progressSteps;
1431 | setParameters(params);
1432 | };
1433 |
1434 | sweetAlert.showProgressSteps = function () {
1435 | show(getProgressSteps());
1436 | };
1437 |
1438 | sweetAlert.hideProgressSteps = function () {
1439 | hide(getProgressSteps());
1440 | };
1441 |
1442 | sweetAlert.enableButtons();
1443 | sweetAlert.hideLoading();
1444 | sweetAlert.resetValidationError();
1445 |
1446 | // inputs
1447 | var inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
1448 | var input = void 0;
1449 | for (var _i7 = 0; _i7 < inputTypes.length; _i7++) {
1450 | var inputClass = swalClasses[inputTypes[_i7]];
1451 | var inputContainer = getChildByClass(modal, inputClass);
1452 | input = getInput(inputTypes[_i7]);
1453 |
1454 | // set attributes
1455 | if (input) {
1456 | for (var j in input.attributes) {
1457 | if (input.attributes.hasOwnProperty(j)) {
1458 | var attrName = input.attributes[j].name;
1459 | if (attrName !== 'type' && attrName !== 'value') {
1460 | input.removeAttribute(attrName);
1461 | }
1462 | }
1463 | }
1464 | for (var attr in params.inputAttributes) {
1465 | input.setAttribute(attr, params.inputAttributes[attr]);
1466 | }
1467 | }
1468 |
1469 | // set class
1470 | inputContainer.className = inputClass;
1471 | if (params.inputClass) {
1472 | addClass(inputContainer, params.inputClass);
1473 | }
1474 |
1475 | hide(inputContainer);
1476 | }
1477 |
1478 | var populateInputOptions = void 0;
1479 | switch (params.input) {
1480 | case 'text':
1481 | case 'email':
1482 | case 'password':
1483 | case 'number':
1484 | case 'tel':
1485 | case 'url':
1486 | input = getChildByClass(modal, swalClasses.input);
1487 | input.value = params.inputValue;
1488 | input.placeholder = params.inputPlaceholder;
1489 | input.type = params.input;
1490 | show(input);
1491 | break;
1492 | case 'file':
1493 | input = getChildByClass(modal, swalClasses.file);
1494 | input.placeholder = params.inputPlaceholder;
1495 | input.type = params.input;
1496 | show(input);
1497 | break;
1498 | case 'range':
1499 | var range = getChildByClass(modal, swalClasses.range);
1500 | var rangeInput = range.querySelector('input');
1501 | var rangeOutput = range.querySelector('output');
1502 | rangeInput.value = params.inputValue;
1503 | rangeInput.type = params.input;
1504 | rangeOutput.value = params.inputValue;
1505 | show(range);
1506 | break;
1507 | case 'select':
1508 | var select = getChildByClass(modal, swalClasses.select);
1509 | select.innerHTML = '';
1510 | if (params.inputPlaceholder) {
1511 | var placeholder = document.createElement('option');
1512 | placeholder.innerHTML = params.inputPlaceholder;
1513 | placeholder.value = '';
1514 | placeholder.disabled = true;
1515 | placeholder.selected = true;
1516 | select.appendChild(placeholder);
1517 | }
1518 | populateInputOptions = function populateInputOptions(inputOptions) {
1519 | for (var optionValue in inputOptions) {
1520 | var option = document.createElement('option');
1521 | option.value = optionValue;
1522 | option.innerHTML = inputOptions[optionValue];
1523 | if (params.inputValue === optionValue) {
1524 | option.selected = true;
1525 | }
1526 | select.appendChild(option);
1527 | }
1528 | show(select);
1529 | select.focus();
1530 | };
1531 | break;
1532 | case 'radio':
1533 | var radio = getChildByClass(modal, swalClasses.radio);
1534 | radio.innerHTML = '';
1535 | populateInputOptions = function populateInputOptions(inputOptions) {
1536 | for (var radioValue in inputOptions) {
1537 | var radioInput = document.createElement('input');
1538 | var radioLabel = document.createElement('label');
1539 | var radioLabelSpan = document.createElement('span');
1540 | radioInput.type = 'radio';
1541 | radioInput.name = swalClasses.radio;
1542 | radioInput.value = radioValue;
1543 | if (params.inputValue === radioValue) {
1544 | radioInput.checked = true;
1545 | }
1546 | radioLabelSpan.innerHTML = inputOptions[radioValue];
1547 | radioLabel.appendChild(radioInput);
1548 | radioLabel.appendChild(radioLabelSpan);
1549 | radioLabel.for = radioInput.id;
1550 | radio.appendChild(radioLabel);
1551 | }
1552 | show(radio);
1553 | var radios = radio.querySelectorAll('input');
1554 | if (radios.length) {
1555 | radios[0].focus();
1556 | }
1557 | };
1558 | break;
1559 | case 'checkbox':
1560 | var checkbox = getChildByClass(modal, swalClasses.checkbox);
1561 | var checkboxInput = getInput('checkbox');
1562 | checkboxInput.type = 'checkbox';
1563 | checkboxInput.value = 1;
1564 | checkboxInput.id = swalClasses.checkbox;
1565 | checkboxInput.checked = Boolean(params.inputValue);
1566 | var label = checkbox.getElementsByTagName('span');
1567 | if (label.length) {
1568 | checkbox.removeChild(label[0]);
1569 | }
1570 | label = document.createElement('span');
1571 | label.innerHTML = params.inputPlaceholder;
1572 | checkbox.appendChild(label);
1573 | show(checkbox);
1574 | break;
1575 | case 'textarea':
1576 | var textarea = getChildByClass(modal, swalClasses.textarea);
1577 | textarea.value = params.inputValue;
1578 | textarea.placeholder = params.inputPlaceholder;
1579 | show(textarea);
1580 | break;
1581 | case null:
1582 | break;
1583 | default:
1584 | console.error('SweetAlert2: Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "' + params.input + '"');
1585 | break;
1586 | }
1587 |
1588 | if (params.input === 'select' || params.input === 'radio') {
1589 | if (params.inputOptions instanceof Promise) {
1590 | sweetAlert.showLoading();
1591 | params.inputOptions.then(function (inputOptions) {
1592 | sweetAlert.hideLoading();
1593 | populateInputOptions(inputOptions);
1594 | });
1595 | } else if (_typeof(params.inputOptions) === 'object') {
1596 | populateInputOptions(params.inputOptions);
1597 | } else {
1598 | console.error('SweetAlert2: Unexpected type of inputOptions! Expected object or Promise, got ' + _typeof(params.inputOptions));
1599 | }
1600 | }
1601 |
1602 | openModal(params.animation, params.onOpen);
1603 |
1604 | // Focus the first focusable element
1605 | if (params.allowEnterKey) {
1606 | setFocus(-1, 1);
1607 | } else {
1608 | if (document.activeElement) {
1609 | document.activeElement.blur();
1610 | }
1611 | }
1612 |
1613 | // fix scroll
1614 | getContainer().scrollTop = 0;
1615 |
1616 | // Observe changes inside the modal and adjust height
1617 | if (typeof MutationObserver !== 'undefined' && !swal2Observer) {
1618 | swal2Observer = new MutationObserver(sweetAlert.recalculateHeight);
1619 | swal2Observer.observe(modal, { childList: true, characterData: true, subtree: true });
1620 | }
1621 | });
1622 | };
1623 |
1624 | /*
1625 | * Global function to determine if swal2 modal is shown
1626 | */
1627 | sweetAlert.isVisible = function () {
1628 | return !!getModal();
1629 | };
1630 |
1631 | /*
1632 | * Global function for chaining sweetAlert modals
1633 | */
1634 | sweetAlert.queue = function (steps) {
1635 | queue = steps;
1636 | var resetQueue = function resetQueue() {
1637 | queue = [];
1638 | document.body.removeAttribute('data-swal2-queue-step');
1639 | };
1640 | var queueResult = [];
1641 | return new Promise(function (resolve, reject) {
1642 | (function step(i, callback) {
1643 | if (i < queue.length) {
1644 | document.body.setAttribute('data-swal2-queue-step', i);
1645 |
1646 | sweetAlert(queue[i]).then(function (result) {
1647 | queueResult.push(result);
1648 | step(i + 1, callback);
1649 | }, function (dismiss) {
1650 | resetQueue();
1651 | reject(dismiss);
1652 | });
1653 | } else {
1654 | resetQueue();
1655 | resolve(queueResult);
1656 | }
1657 | })(0);
1658 | });
1659 | };
1660 |
1661 | /*
1662 | * Global function for getting the index of current modal in queue
1663 | */
1664 | sweetAlert.getQueueStep = function () {
1665 | return document.body.getAttribute('data-swal2-queue-step');
1666 | };
1667 |
1668 | /*
1669 | * Global function for inserting a modal to the queue
1670 | */
1671 | sweetAlert.insertQueueStep = function (step, index) {
1672 | if (index && index < queue.length) {
1673 | return queue.splice(index, 0, step);
1674 | }
1675 | return queue.push(step);
1676 | };
1677 |
1678 | /*
1679 | * Global function for deleting a modal from the queue
1680 | */
1681 | sweetAlert.deleteQueueStep = function (index) {
1682 | if (typeof queue[index] !== 'undefined') {
1683 | queue.splice(index, 1);
1684 | }
1685 | };
1686 |
1687 | /*
1688 | * Global function to close sweetAlert
1689 | */
1690 | sweetAlert.close = sweetAlert.closeModal = function (onComplete) {
1691 | var container = getContainer();
1692 | var modal = getModal();
1693 | if (!modal) {
1694 | return;
1695 | }
1696 | removeClass(modal, swalClasses.show);
1697 | addClass(modal, swalClasses.hide);
1698 | clearTimeout(modal.timeout);
1699 |
1700 | resetPrevState();
1701 |
1702 | var removeModalAndResetState = function removeModalAndResetState() {
1703 | if (container.parentNode) {
1704 | container.parentNode.removeChild(container);
1705 | }
1706 | removeClass(document.documentElement, swalClasses.shown);
1707 | removeClass(document.body, swalClasses.shown);
1708 | undoScrollbar();
1709 | undoIOSfix();
1710 | };
1711 |
1712 | // If animation is supported, animate
1713 | if (animationEndEvent && !hasClass(modal, swalClasses.noanimation)) {
1714 | modal.addEventListener(animationEndEvent, function swalCloseEventFinished() {
1715 | modal.removeEventListener(animationEndEvent, swalCloseEventFinished);
1716 | if (hasClass(modal, swalClasses.hide)) {
1717 | removeModalAndResetState();
1718 | }
1719 | });
1720 | } else {
1721 | // Otherwise, remove immediately
1722 | removeModalAndResetState();
1723 | }
1724 | if (onComplete !== null && typeof onComplete === 'function') {
1725 | setTimeout(function () {
1726 | onComplete(modal);
1727 | });
1728 | }
1729 | };
1730 |
1731 | /*
1732 | * Global function to click 'Confirm' button
1733 | */
1734 | sweetAlert.clickConfirm = function () {
1735 | return getConfirmButton().click();
1736 | };
1737 |
1738 | /*
1739 | * Global function to click 'Cancel' button
1740 | */
1741 | sweetAlert.clickCancel = function () {
1742 | return getCancelButton().click();
1743 | };
1744 |
1745 | /**
1746 | * Show spinner instead of Confirm button and disable Cancel button
1747 | */
1748 | sweetAlert.showLoading = sweetAlert.enableLoading = function () {
1749 | var modal = getModal();
1750 | if (!modal) {
1751 | sweetAlert('');
1752 | }
1753 | var buttonsWrapper = getButtonsWrapper();
1754 | var confirmButton = getConfirmButton();
1755 | var cancelButton = getCancelButton();
1756 |
1757 | show(buttonsWrapper);
1758 | show(confirmButton, 'inline-block');
1759 | addClass(buttonsWrapper, swalClasses.loading);
1760 | addClass(modal, swalClasses.loading);
1761 | confirmButton.disabled = true;
1762 | cancelButton.disabled = true;
1763 | };
1764 |
1765 | /**
1766 | * Is valid parameter
1767 | * @param {String} paramName
1768 | */
1769 | sweetAlert.isValidParameter = function (paramName) {
1770 | return defaultParams.hasOwnProperty(paramName) || paramName === 'extraParams';
1771 | };
1772 |
1773 | /**
1774 | * Set default params for each popup
1775 | * @param {Object} userParams
1776 | */
1777 | sweetAlert.setDefaults = function (userParams) {
1778 | if (!userParams || (typeof userParams === 'undefined' ? 'undefined' : _typeof(userParams)) !== 'object') {
1779 | return console.error('SweetAlert2: the argument for setDefaults() is required and has to be a object');
1780 | }
1781 |
1782 | for (var param in userParams) {
1783 | if (!sweetAlert.isValidParameter(param)) {
1784 | console.warn('SweetAlert2: Unknown parameter "' + param + '"');
1785 | delete userParams[param];
1786 | }
1787 | }
1788 |
1789 | _extends(modalParams, userParams);
1790 | };
1791 |
1792 | /**
1793 | * Reset default params for each popup
1794 | */
1795 | sweetAlert.resetDefaults = function () {
1796 | modalParams = _extends({}, defaultParams);
1797 | };
1798 |
1799 | sweetAlert.noop = function () {};
1800 |
1801 | sweetAlert.version = '6.8.0';
1802 |
1803 | sweetAlert.default = sweetAlert;
1804 |
1805 | return sweetAlert;
1806 |
1807 | })));
1808 | if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2;
1809 |
--------------------------------------------------------------------------------
/alert/sweetalert2.min.css:
--------------------------------------------------------------------------------
1 | body.swal2-shown{overflow-y:hidden}body.swal2-iosfix{position:fixed;left:0;right:0}.swal2-container{display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:fixed;top:0;left:0;bottom:0;right:0;padding:10px;background-color:transparent;z-index:1060}.swal2-container.swal2-fade{-webkit-transition:background-color .1s;transition:background-color .1s}.swal2-container.swal2-shown{background-color:rgba(0,0,0,.4)}.swal2-modal{background-color:#fff;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;border-radius:5px;-webkit-box-sizing:border-box;box-sizing:border-box;text-align:center;margin:auto;overflow-x:hidden;overflow-y:auto;display:none;position:relative;max-width:100%}.swal2-modal:focus{outline:0}.swal2-modal.swal2-loading{overflow-y:hidden}.swal2-modal .swal2-title{color:#595959;font-size:30px;text-align:center;font-weight:600;text-transform:none;position:relative;margin:0 0 .4em;padding:0;display:block;word-wrap:break-word}.swal2-modal .swal2-buttonswrapper{margin-top:15px}.swal2-modal .swal2-buttonswrapper:not(.swal2-loading) .swal2-styled[disabled]{opacity:.4;cursor:no-drop}.swal2-modal .swal2-buttonswrapper.swal2-loading .swal2-styled.swal2-confirm{-webkit-box-sizing:border-box;box-sizing:border-box;border:4px solid transparent;border-color:transparent;width:40px;height:40px;padding:0;margin:7.5px;vertical-align:top;background-color:transparent!important;color:transparent;cursor:default;border-radius:100%;-webkit-animation:rotate-loading 1.5s linear 0s infinite normal;animation:rotate-loading 1.5s linear 0s infinite normal;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-modal .swal2-buttonswrapper.swal2-loading .swal2-styled.swal2-cancel{margin-left:30px;margin-right:30px}.swal2-modal .swal2-buttonswrapper.swal2-loading :not(.swal2-styled).swal2-confirm::after{display:inline-block;content:'';margin-left:5px;vertical-align:-1px;height:15px;width:15px;border:3px solid #999;-webkit-box-shadow:1px 1px 1px #fff;box-shadow:1px 1px 1px #fff;border-right-color:transparent;border-radius:50%;-webkit-animation:rotate-loading 1.5s linear 0s infinite normal;animation:rotate-loading 1.5s linear 0s infinite normal}.swal2-modal .swal2-styled{border:0;border-radius:3px;-webkit-box-shadow:none;box-shadow:none;color:#fff;cursor:pointer;font-size:17px;font-weight:500;margin:15px 5px 0;padding:10px 32px}.swal2-modal .swal2-styled:focus{outline:0;-webkit-box-shadow:0 0 0 2px #fff,0 0 0 4px rgba(50,100,150,.4);box-shadow:0 0 0 2px #fff,0 0 0 4px rgba(50,100,150,.4)}.swal2-modal .swal2-image{margin:20px auto;max-width:100%}.swal2-modal .swal2-close{background:0 0;border:0;margin:0;padding:0;width:38px;height:40px;font-size:36px;line-height:40px;font-family:serif;position:absolute;top:5px;right:8px;cursor:pointer;color:#ccc;-webkit-transition:color .1s ease;transition:color .1s ease}.swal2-modal .swal2-close:hover{color:#d55}.swal2-modal>.swal2-checkbox,.swal2-modal>.swal2-file,.swal2-modal>.swal2-input,.swal2-modal>.swal2-radio,.swal2-modal>.swal2-select,.swal2-modal>.swal2-textarea{display:none}.swal2-modal .swal2-content{font-size:18px;text-align:center;font-weight:300;position:relative;float:none;margin:0;padding:0;line-height:normal;color:#545454;word-wrap:break-word}.swal2-modal .swal2-checkbox,.swal2-modal .swal2-file,.swal2-modal .swal2-input,.swal2-modal .swal2-radio,.swal2-modal .swal2-select,.swal2-modal .swal2-textarea{margin:20px auto}.swal2-modal .swal2-file,.swal2-modal .swal2-input,.swal2-modal .swal2-textarea{width:100%;-webkit-box-sizing:border-box;box-sizing:border-box;font-size:18px;border-radius:3px;border:1px solid #d9d9d9;-webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.06);box-shadow:inset 0 1px 1px rgba(0,0,0,.06);-webkit-transition:border-color .3s,-webkit-box-shadow .3s;transition:border-color .3s,-webkit-box-shadow .3s;transition:border-color .3s,box-shadow .3s;transition:border-color .3s,box-shadow .3s,-webkit-box-shadow .3s}.swal2-modal .swal2-file.swal2-inputerror,.swal2-modal .swal2-input.swal2-inputerror,.swal2-modal .swal2-textarea.swal2-inputerror{border-color:#f27474!important;-webkit-box-shadow:0 0 2px #f27474!important;box-shadow:0 0 2px #f27474!important}.swal2-modal .swal2-file:focus,.swal2-modal .swal2-input:focus,.swal2-modal .swal2-textarea:focus{outline:0;border:1px solid #b4dbed;-webkit-box-shadow:0 0 3px #c4e6f5;box-shadow:0 0 3px #c4e6f5}.swal2-modal .swal2-file::-webkit-input-placeholder,.swal2-modal .swal2-input::-webkit-input-placeholder,.swal2-modal .swal2-textarea::-webkit-input-placeholder{color:#ccc}.swal2-modal .swal2-file:-ms-input-placeholder,.swal2-modal .swal2-input:-ms-input-placeholder,.swal2-modal .swal2-textarea:-ms-input-placeholder{color:#ccc}.swal2-modal .swal2-file::placeholder,.swal2-modal .swal2-input::placeholder,.swal2-modal .swal2-textarea::placeholder{color:#ccc}.swal2-modal .swal2-range input{float:left;width:80%}.swal2-modal .swal2-range output{float:right;width:20%;font-size:20px;font-weight:600;text-align:center}.swal2-modal .swal2-range input,.swal2-modal .swal2-range output{height:43px;line-height:43px;vertical-align:middle;margin:20px auto;padding:0}.swal2-modal .swal2-input{height:43px;padding:0 12px}.swal2-modal .swal2-input[type=number]{max-width:150px}.swal2-modal .swal2-file{font-size:20px}.swal2-modal .swal2-textarea{height:108px;padding:12px}.swal2-modal .swal2-select{color:#545454;font-size:inherit;padding:5px 10px;min-width:40%;max-width:100%}.swal2-modal .swal2-radio{border:0}.swal2-modal .swal2-radio label:not(:first-child){margin-left:20px}.swal2-modal .swal2-radio input,.swal2-modal .swal2-radio span{vertical-align:middle}.swal2-modal .swal2-radio input{margin:0 3px 0 0}.swal2-modal .swal2-checkbox{color:#545454}.swal2-modal .swal2-checkbox input,.swal2-modal .swal2-checkbox span{vertical-align:middle}.swal2-modal .swal2-validationerror{background-color:#f0f0f0;margin:0 -20px;overflow:hidden;padding:10px;color:gray;font-size:16px;font-weight:300;display:none}.swal2-modal .swal2-validationerror::before{content:'!';display:inline-block;width:24px;height:24px;border-radius:50%;background-color:#ea7d7d;color:#fff;line-height:24px;text-align:center;margin-right:10px}@supports (-ms-accelerator:true){.swal2-range input{width:100%!important}.swal2-range output{display:none}}@media all and (-ms-high-contrast:none),(-ms-high-contrast:active){.swal2-range input{width:100%!important}.swal2-range output{display:none}}.swal2-icon{width:80px;height:80px;border:4px solid transparent;border-radius:50%;margin:20px auto 30px;padding:0;position:relative;-webkit-box-sizing:content-box;box-sizing:content-box;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-icon.swal2-error{border-color:#f27474}.swal2-icon.swal2-error .swal2-x-mark{position:relative;display:block}.swal2-icon.swal2-error [class^=swal2-x-mark-line]{position:absolute;height:5px;width:47px;background-color:#f27474;display:block;top:37px;border-radius:2px}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{-webkit-transform:rotate(45deg);transform:rotate(45deg);left:17px}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{-webkit-transform:rotate(-45deg);transform:rotate(-45deg);right:16px}.swal2-icon.swal2-warning{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#f8bb86;border-color:#facea8;font-size:60px;line-height:80px;text-align:center}.swal2-icon.swal2-info{font-family:'Open Sans',sans-serif;color:#3fc3ee;border-color:#9de0f6;font-size:60px;line-height:80px;text-align:center}.swal2-icon.swal2-question{font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;color:#87adbd;border-color:#c9dae1;font-size:60px;line-height:80px;text-align:center}.swal2-icon.swal2-success{border-color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-circular-line]{border-radius:50%;position:absolute;width:60px;height:120px;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=left]{border-radius:120px 0 0 120px;top:-7px;left:-33px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:60px 60px;transform-origin:60px 60px}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=right]{border-radius:0 120px 120px 0;top:-11px;left:30px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg);-webkit-transform-origin:0 60px;transform-origin:0 60px}.swal2-icon.swal2-success .swal2-success-ring{width:80px;height:80px;border:4px solid rgba(165,220,134,.2);border-radius:50%;-webkit-box-sizing:content-box;box-sizing:content-box;position:absolute;left:-4px;top:-4px;z-index:2}.swal2-icon.swal2-success .swal2-success-fix{width:7px;height:90px;position:absolute;left:28px;top:8px;z-index:1;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-icon.swal2-success [class^=swal2-success-line]{height:5px;background-color:#a5dc86;display:block;border-radius:2px;position:absolute;z-index:2}.swal2-icon.swal2-success [class^=swal2-success-line][class$=tip]{width:25px;left:14px;top:46px;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.swal2-icon.swal2-success [class^=swal2-success-line][class$=long]{width:47px;right:8px;top:38px;-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}.swal2-progresssteps{font-weight:600;margin:0 0 20px;padding:0}.swal2-progresssteps li{display:inline-block;position:relative}.swal2-progresssteps .swal2-progresscircle{background:#3085d6;border-radius:2em;color:#fff;height:2em;line-height:2em;text-align:center;width:2em;z-index:20}.swal2-progresssteps .swal2-progresscircle:first-child{margin-left:0}.swal2-progresssteps .swal2-progresscircle:last-child{margin-right:0}.swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep{background:#3085d6}.swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep~.swal2-progresscircle{background:#add8e6}.swal2-progresssteps .swal2-progresscircle.swal2-activeprogressstep~.swal2-progressline{background:#add8e6}.swal2-progresssteps .swal2-progressline{background:#3085d6;height:.4em;margin:0 -1px;z-index:10}[class^=swal2]{-webkit-tap-highlight-color:transparent}@-webkit-keyframes showSweetAlert{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@keyframes showSweetAlert{0%{-webkit-transform:scale(.7);transform:scale(.7)}45%{-webkit-transform:scale(1.05);transform:scale(1.05)}80%{-webkit-transform:scale(.95);transform:scale(.95)}100%{-webkit-transform:scale(1);transform:scale(1)}}@-webkit-keyframes hideSweetAlert{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}@keyframes hideSweetAlert{0%{-webkit-transform:scale(1);transform:scale(1);opacity:1}100%{-webkit-transform:scale(.5);transform:scale(.5);opacity:0}}.swal2-show{-webkit-animation:showSweetAlert .3s;animation:showSweetAlert .3s}.swal2-show.swal2-noanimation{-webkit-animation:none;animation:none}.swal2-hide{-webkit-animation:hideSweetAlert .15s forwards;animation:hideSweetAlert .15s forwards}.swal2-hide.swal2-noanimation{-webkit-animation:none;animation:none}@-webkit-keyframes animate-success-tip{0%{width:0;left:1px;top:19px}54%{width:0;left:1px;top:19px}70%{width:50px;left:-8px;top:37px}84%{width:17px;left:21px;top:48px}100%{width:25px;left:14px;top:45px}}@keyframes animate-success-tip{0%{width:0;left:1px;top:19px}54%{width:0;left:1px;top:19px}70%{width:50px;left:-8px;top:37px}84%{width:17px;left:21px;top:48px}100%{width:25px;left:14px;top:45px}}@-webkit-keyframes animate-success-long{0%{width:0;right:46px;top:54px}65%{width:0;right:46px;top:54px}84%{width:55px;right:0;top:35px}100%{width:47px;right:8px;top:38px}}@keyframes animate-success-long{0%{width:0;right:46px;top:54px}65%{width:0;right:46px;top:54px}84%{width:55px;right:0;top:35px}100%{width:47px;right:8px;top:38px}}@-webkit-keyframes rotatePlaceholder{0%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}100%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}@keyframes rotatePlaceholder{0%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}5%{-webkit-transform:rotate(-45deg);transform:rotate(-45deg)}12%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}100%{-webkit-transform:rotate(-405deg);transform:rotate(-405deg)}}.swal2-animate-success-line-tip{-webkit-animation:animate-success-tip .75s;animation:animate-success-tip .75s}.swal2-animate-success-line-long{-webkit-animation:animate-success-long .75s;animation:animate-success-long .75s}.swal2-success.swal2-animate-success-icon .swal2-success-circular-line-right{-webkit-animation:rotatePlaceholder 4.25s ease-in;animation:rotatePlaceholder 4.25s ease-in}@-webkit-keyframes animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}@keyframes animate-error-icon{0%{-webkit-transform:rotateX(100deg);transform:rotateX(100deg);opacity:0}100%{-webkit-transform:rotateX(0);transform:rotateX(0);opacity:1}}.swal2-animate-error-icon{-webkit-animation:animate-error-icon .5s;animation:animate-error-icon .5s}@-webkit-keyframes animate-x-mark{0%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}50%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}80%{-webkit-transform:scale(1.15);transform:scale(1.15);margin-top:-6px}100%{-webkit-transform:scale(1);transform:scale(1);margin-top:0;opacity:1}}@keyframes animate-x-mark{0%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}50%{-webkit-transform:scale(.4);transform:scale(.4);margin-top:26px;opacity:0}80%{-webkit-transform:scale(1.15);transform:scale(1.15);margin-top:-6px}100%{-webkit-transform:scale(1);transform:scale(1);margin-top:0;opacity:1}}.swal2-animate-x-mark{-webkit-animation:animate-x-mark .5s;animation:animate-x-mark .5s}@-webkit-keyframes rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes rotate-loading{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}
--------------------------------------------------------------------------------
/alert/sweetalert2.min.js:
--------------------------------------------------------------------------------
1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Sweetalert2=t()}(this,function(){"use strict";var e={title:"",titleText:"",text:"",html:"",type:null,customClass:"",target:"body",animation:!0,allowOutsideClick:!0,allowEscapeKey:!0,allowEnterKey:!0,showConfirmButton:!0,showCancelButton:!1,preConfirm:null,confirmButtonText:"OK",confirmButtonAriaLabel:"",confirmButtonColor:"#3085d6",confirmButtonClass:null,cancelButtonText:"Cancel",cancelButtonAriaLabel:"",cancelButtonColor:"#aaa",cancelButtonClass:null,buttonsStyling:!0,reverseButtons:!1,focusCancel:!1,showCloseButton:!1,showLoaderOnConfirm:!1,imageUrl:null,imageWidth:null,imageHeight:null,imageAlt:"",imageClass:null,timer:null,width:500,padding:20,background:"#fff",input:null,inputPlaceholder:"",inputValue:"",inputOptions:{},inputAutoTrim:!0,inputClass:null,inputAttributes:{},inputValidator:null,progressSteps:[],currentProgressStep:null,progressStepsDistance:"40px",onOpen:null,onClose:null,useRejections:!0},t=function(e){var t={};for(var n in e)t[e[n]]="swal2-"+e[n];return t},n=t(["container","shown","iosfix","modal","overlay","fade","show","hide","noanimation","close","title","content","buttonswrapper","confirm","cancel","icon","image","input","file","range","select","radio","checkbox","textarea","inputerror","validationerror","progresssteps","activeprogressstep","progresscircle","progressline","loading","styled"]),o=t(["success","warning","info","question","error"]),r=function(e,t){(e=String(e).replace(/[^0-9a-f]/gi,"")).length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;for(var n="#",o=0;o<3;o++){var r=parseInt(e.substr(2*o,2),16);n+=("00"+(r=Math.round(Math.min(Math.max(0,r+r*t),255)).toString(16))).substr(r.length)}return n},i=function(e){var t=[];for(var n in e)-1===t.indexOf(e[n])&&t.push(e[n]);return t},a={previousWindowKeyDown:null,previousActiveElement:null,previousBodyPadding:null},l=function(e){var t=u();t&&t.parentNode.removeChild(t);{if("undefined"!=typeof document){var o=document.createElement("div");o.className=n.container,o.innerHTML=s,("string"==typeof e.target?document.querySelector(e.target):e.target).appendChild(o);var r=c(),i=B(r,n.input),a=B(r,n.file),l=r.querySelector("."+n.range+" input"),d=r.querySelector("."+n.range+" output"),p=B(r,n.select),f=r.querySelector("."+n.checkbox+" input"),m=B(r,n.textarea);return i.oninput=function(){$.resetValidationError()},i.onkeydown=function(t){setTimeout(function(){13===t.keyCode&&e.allowEnterKey&&(t.stopPropagation(),$.clickConfirm())},0)},a.onchange=function(){$.resetValidationError()},l.oninput=function(){$.resetValidationError(),d.value=l.value},l.onchange=function(){$.resetValidationError(),l.previousSibling.value=l.value},p.onchange=function(){$.resetValidationError()},f.onchange=function(){$.resetValidationError()},m.oninput=function(){$.resetValidationError()},r}console.error("SweetAlert2 requires document to initialize")}},s=('\n \n
\n
\n \n
\n
?
\n
!
\n
i
\n
\n
\n
\n
\n
\n
\n
\n \n \n
\n
\n
\n
\n \n \n
\n
\n
\n OK \n Cancel \n
\n
× \n
\n').replace(/(^|\n)\s*/g,""),u=function(){return document.body.querySelector("."+n.container)},c=function(){return u()?u().querySelector("."+n.modal):null},d=function(){return c().querySelectorAll("."+n.icon)},p=function(e){return u()?u().querySelector("."+e):null},f=function(){return p(n.title)},m=function(){return p(n.content)},v=function(){return p(n.image)},h=function(){return p(n.buttonswrapper)},b=function(){return p(n.progresssteps)},y=function(){return p(n.validationerror)},g=function(){return p(n.confirm)},w=function(){return p(n.cancel)},C=function(){return p(n.close)},k=function(e){var t=[g(),w()];e&&t.reverse();var n=Array.from(c().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')).sort(function(e,t){return e=parseInt(e.getAttribute("tabindex")),t=parseInt(t.getAttribute("tabindex")),e>t?1:e "),e.text||e.html){if("object"===I(e.html))if(y.innerHTML="",0 in e.html)for(var q=0;q in e.html;q++)y.appendChild(e.html[q].cloneNode(!0));else y.appendChild(e.html.cloneNode(!0));else e.html?y.innerHTML=e.html:e.text&&(y.textContent=e.text);P(y)}else L(y);e.showCloseButton?P(B):L(B),t.className=n.modal,e.customClass&&A(t,e.customClass);var V=b(),O=parseInt(null===e.currentProgressStep?$.getQueueStep():e.currentProgressStep,10);e.progressSteps.length?(P(V),T(V),O>=e.progressSteps.length&&console.warn("SweetAlert2: Invalid currentProgressStep parameter, it should be less than progressSteps.length (currentProgressStep like JS arrays starts from 0)"),e.progressSteps.forEach(function(t,o){var r=document.createElement("li");if(A(r,n.progresscircle),r.innerHTML=t,o===O&&A(r,n.activeprogressstep),V.appendChild(r),o!==e.progressSteps.length-1){var i=document.createElement("li");A(i,n.progressline),i.style.width=e.progressStepsDistance,V.appendChild(i)}})):L(V);for(var H=d(),N=0;Nwindow.innerHeight&&(a.previousBodyPadding=document.body.style.paddingRight,document.body.style.paddingRight=N()+"px")},Z=function(){null!==a.previousBodyPadding&&(document.body.style.paddingRight=a.previousBodyPadding,a.previousBodyPadding=null)},Q=function(){if(/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream&&!x(document.body,n.iosfix)){var e=document.body.scrollTop;document.body.style.top=-1*e+"px",A(document.body,n.iosfix)}},Y=function(){if(x(document.body,n.iosfix)){var e=parseInt(document.body.style.top,10);E(document.body,n.iosfix),document.body.style.top="",document.body.scrollTop=-1*e}},$=function e(){for(var t=arguments.length,o=Array(t),i=0;i= 0 &&
14 | rect.left >= 0 &&
15 | rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)+45 &&
16 | rect.right <= (window.innerWidth || document.documentElement.clientWidth)
17 | );
18 | }
19 |
20 | function callbackFunc() {
21 | for (var i = 0; i < items.length; i++) {
22 | if (isElementInViewport(items[i])) {
23 | items[i].classList.add("in-view");
24 | }
25 | }
26 | }
27 |
28 | // listen for events
29 | window.addEventListener("load", callbackFunc);
30 | window.addEventListener("resize", callbackFunc);
31 | window.addEventListener("scroll", callbackFunc);
32 |
33 | })();
34 |
35 |
36 |
37 | $(document).ready(function() {
38 | $('.scroll1').click(function(){
39 | $('html, body').animate({scrollTop:$('#tutorial').position().top}, 'slow');
40 | return false;
41 | });
42 | });
43 | function alrtinfo(){
44 | swal({
45 | title: 'About us',
46 | html: "Hi! This system is developed by Shou and supported by his school! The source code can be found here . Extremely easy to deploy! "
47 | })
48 | }
49 | function alrtintro(){
50 | swal({
51 | title: 'Detailed Introduction',
52 | html: "SSLify.tech is a means for developers to test against valid SSL certificates without the bother of purchasing them. A wildcard SSL certificate for *.sslify.tech and the corresponding key, both downloadable from cert/ Install the certificate and key on the server, modify the server's configuration to use the certificate and key, and restart the daemon. After that, browse the server using the SSLify.tech hostname via HTTPS (e.g.https://bla.SSLify.tech ) and receive a valid SSL connection (green lock), all in a matter of seconds."
53 | })
54 | }
55 | function alrt(){
56 | swal.setDefaults({
57 | confirmButtonText: 'Next →',
58 | showCancelButton: true,
59 | animation: false,
60 | progressSteps: ['1', '2']
61 | })
62 |
63 | var steps = [
64 | {
65 | input: 'select',
66 | title: 'Record type!',
67 | text: "If your server provider gives you the IP, you'd better choose A and vice versa.",
68 | inputOptions: {
69 | 'CNAME': 'CNAME',
70 | 'A': 'A',
71 | },
72 | },
73 | {
74 | input: 'text',
75 | title: 'Server info!',
76 | text: "Please input your sever's hostname or IP",
77 | inputValidator: function (value) {
78 | return new Promise(function (resolve, reject) {
79 | if (value.indexOf(".")!=-1) {
80 | resolve()
81 | } else {
82 | reject('Please correctly input the information!')
83 | }
84 | })
85 | }
86 | }
87 | ]
88 |
89 | swal.queue(steps).then(function (result) {
90 | swal.resetDefaults()
91 | var xmlHttp = new XMLHttpRequest();
92 | var url = "/api/"+result[0]+"/"+result[1]+"/";
93 | xmlHttp.open( "GET", url , false );
94 | // false for synchronous request
95 | xmlHttp.send( null );
96 | obj = JSON.parse(xmlHttp.responseText);
97 | if (obj.type == "success"){
98 | swal({
99 | type: 'success',
100 | title: 'Enjoy!!!',
101 | html: obj.message
102 | })
103 | }
104 | else{
105 | swal({
106 | type: 'error',
107 | title: 'Failed!!!',
108 | html: obj.message
109 | })
110 | }
111 |
112 | }, function () {
113 | swal.resetDefaults()
114 | })
115 | }
116 |
117 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shouc/SSLify/2c2d7b874c948ed4c86b58fd0ac147bc2ebb1bde/logo.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | bottle==0.12.13
2 | cloudflare==1.7.5
3 | protobuf
4 |
--------------------------------------------------------------------------------
/server.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | import sys
3 | import CloudFlare
4 | from bottle import route, run, template, hook,response,static_file
5 | import re
6 | import os
7 |
8 | print("""
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 | Developed by Shou Chaofan (scf@ieee.org)
40 |
41 | """)
42 | Email = raw_input("CloudFlare's Email? ")
43 | Token = raw_input("CloudFlare's token? ")
44 | cf = CloudFlare.CloudFlare(email=Email, token=Token)
45 | zones = cf.zones.get()
46 | z = []
47 | k = 1
48 | for zone in zones:
49 | zone_id = zone['id']
50 | zone_name = zone['name']
51 | z.append([zone_id,zone_name])
52 | print(k, zone_id, zone_name)
53 | k = k + 1
54 | k = raw_input("Which domain you'd like to choose? [e.g. 1] ")
55 | port = raw_input("Server's port? [Optional] ")
56 | hostname = raw_input("Server's hostname? [Optional] ")
57 |
58 | end = z[int(k)-1][1]
59 | zone_id = z[int(k)-1][0]
60 |
61 |
62 | def dns(type,name,content):
63 | if type == "A":
64 | return [{'name':name, 'type':'A', 'content':content}]
65 | elif type == "CNAME":
66 | return [{'name':name, 'type':'CNAME', 'content':content}]
67 |
68 | def push(dns_records):
69 | for dns_record in dns_records:
70 | r = cf.zones.dns_records.post(zone_id, data=dns_record)
71 | def checkip(ip):
72 | p = re.compile('^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$')
73 | if p.match(ip):
74 | return True
75 | else:
76 | return False
77 |
78 | @hook('after_request')
79 | def enable_cors():
80 | response.headers['Access-Control-Allow-Origin'] = '*'
81 | @route('/api///')
82 | def api(type,name):
83 | domain = name + "." + end
84 | if type == "CNAME":
85 | if checkip(name) == True:
86 | return {
87 | 'type' : 'failed',
88 | 'message' : "CNAME is not the friend of IP",
89 | }
90 | else:
91 | push(dns(type,name,name))
92 | return {
93 | 'type' : 'success',
94 | 'message' : "Enjoy! The address is " + domain + " ",
95 | }
96 | elif type == "A":
97 | if checkip(name) == False:
98 | return {
99 | 'type' : 'failed',
100 | 'message' : "A is the friend of IP",
101 | }
102 | else:
103 | push(dns(type,name,name))
104 | return {
105 | 'type' : 'success',
106 | 'message' : "Enjoy! The address is " + domain + " ",
107 | }
108 | else:
109 | return {
110 | 'type' : 'failed',
111 | 'message' : "There may already be records in our database. Try to visit " + domain + " If you don't think it's the problem, contact admin!"
112 | }
113 | @route('/')
114 | def index():
115 | return template("tpl/index.html")
116 | @route('/Comparison')
117 | def com():
118 | return template("tpl/comparison.html")
119 | @route('/css/')
120 | def static_content(filename):
121 | return static_file(filename, root='./css')
122 | @route('/js/')
123 | def js(filename):
124 | return static_file(filename, root='./js')
125 | @route('/alert/')
126 | def alert(filename):
127 | return static_file(filename, root='./alert')
128 | @route('/cert/')
129 | def cert(filename):
130 | return static_file(filename, root='./cert')
131 | @route('/cert/')
132 | def certindex():
133 | d = os.listdir("./cert/")
134 | result = "certs:"
135 | for i in d:
136 | result = result + ""
137 | return result
138 |
139 |
140 | if port == None and hostname==None:
141 | run(host='0.0.0.0', port=8080)
142 | elif port == None and hostname!=None:
143 | run(host=hostname, port=8080)
144 | elif port != None and hostname == None:
145 | run(host='0.0.0.0', port=port)
146 | else:
147 | run(host=hostname, port=port)
148 |
--------------------------------------------------------------------------------
/tpl/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/tpl/comparison.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
5 | SSLify
6 |
7 |
8 |
9 |
10 |
11 |
25 |
26 | Chinese Version
27 |
28 |
29 |
30 |
31 |
32 | Comparison
33 |
34 |
35 |
36 |
37 |
42 |
43 |
44 |
Comparison
45 |
46 |
47 |
XIP.io
48 |
Free
49 |
50 | Unlimited Domains
51 | Fast DNS Supported
52 | No Privacy Leaks
53 |
Visit
54 |
55 |
Our SSLify
56 |
Free
57 |
58 | * Easy for Local Deployment
59 | * Auto SSL Deploy Supported
60 | * Multi-lingual Supported
61 | * Stable DNS based on Cloudflare
62 | Unlimited Domains
63 | No Privacy Leaks
64 | SSL Supported
65 | Fast Wildcard DNS Supported
66 |
67 |
68 |
Visit
69 |
70 |
SSLip.io
71 |
Private
72 |
73 | Unlimited Domains
74 | SSL Supported
75 | Fast DNS Supported
76 | Unlimited Domains
77 |
Visit
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/tpl/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SSLify - Rapidly SSLify Your Server
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | SSLify
17 |
18 |
19 |
20 |
21 |
22 |
36 |
37 | Chinese Version
38 |
39 |
40 |
41 |
42 |
43 |
44 |
SSLify
45 |
Rapidly SSLify Your Server
46 |
47 | Introduction
48 | Tutorial
49 |
50 |
51 |
52 | We could no longer purchase a wildcard SSL license, but you can still bind your server to our domain. If you want to setup the environment for private use and hope to enable the SSL function, please deploy on your own behalf.
53 | Source code is at
https://github.com/InvidHead/SSLify
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
71 |
72 |
73 |
74 | Recording Make your server bind with our domain like managing the DNS!
75 | Create Records!
76 |
77 |
78 |
79 |
80 |
81 |
82 | Enjoy!
83 | You can use this in iOS APP demo.
84 | You can beautify your website's address.
85 | And more....
86 | But remember!! Do not use this in production. Never!
87 | User may kill you!!
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |