sweetalert.min.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. ! function(e, t, n) { "use strict";! function o(e, t, n) {
  2. function a(s, l) { if (!t[s]) { if (!e[s]) { var i = "function" == typeof require && require; if (!l && i) return i(s, !0); if (r) return r(s, !0); var u = new Error("Cannot find module '" + s + "'"); throw u.code = "MODULE_NOT_FOUND", u } var c = t[s] = { exports: {} };
  3. e[s][0].call(c.exports, function(t) { var n = e[s][1][t]; return a(n ? n : t) }, c, c.exports, o, e, t, n) } return t[s].exports } for (var r = "function" == typeof require && require, s = 0; s < n.length; s++) a(n[s]); return a }({ 1: [function(o, a, r) { var s = function(e) { return e && e.__esModule ? e : { "default": e } };
  4. Object.defineProperty(r, "__esModule", { value: !0 }); var l, i, u, c, d = o("./modules/handle-dom"),
  5. f = o("./modules/utils"),
  6. p = o("./modules/handle-swal-dom"),
  7. m = o("./modules/handle-click"),
  8. v = o("./modules/handle-key"),
  9. y = s(v),
  10. h = o("./modules/default-params"),
  11. b = s(h),
  12. g = o("./modules/set-params"),
  13. w = s(g);
  14. r["default"] = u = c = function() {
  15. function o(e) { var t = a; return t[e] === n ? b["default"][e] : t[e] } var a = arguments[0]; if (d.addClass(t.body, "stop-scrolling"), p.resetInput(), a === n) return f.logStr("SweetAlert expects at least 1 attribute!"), !1; var r = f.extend({}, b["default"]); switch (typeof a) {
  16. case "string":
  17. r.title = a, r.text = arguments[1] || "", r.type = arguments[2] || ""; break;
  18. case "object":
  19. if (a.title === n) return f.logStr('Missing "title" argument!'), !1;
  20. r.title = a.title; for (var s in b["default"]) r[s] = o(s);
  21. r.confirmButtonText = r.showCancelButton ? "Confirm" : b["default"].confirmButtonText, r.confirmButtonText = o("confirmButtonText"), r.doneFunction = arguments[1] || null; break;
  22. default:
  23. return f.logStr('Unexpected type of argument! Expected "string" or "object", got ' + typeof a), !1 }
  24. w["default"](r), p.fixVerticalPosition(), p.openModal(arguments[1]); for (var u = p.getModal(), v = u.querySelectorAll("button"), h = ["onclick", "onmouseover", "onmouseout", "onmousedown", "onmouseup", "onfocus"], g = function(e) { return m.handleButton(e, r, u) }, C = 0; C < v.length; C++)
  25. for (var S = 0; S < h.length; S++) { var x = h[S];
  26. v[C][x] = g }
  27. p.getOverlay().onclick = g, l = e.onkeydown; var k = function(e) { return y["default"](e, r, u) };
  28. e.onkeydown = k, e.onfocus = function() { setTimeout(function() { i !== n && (i.focus(), i = n) }, 0) }, c.enableButtons() }, u.setDefaults = c.setDefaults = function(e) { if (!e) throw new Error("userParams is required"); if ("object" != typeof e) throw new Error("userParams has to be a object");
  29. f.extend(b["default"], e) }, u.close = c.close = function() { var o = p.getModal();
  30. d.fadeOut(p.getOverlay(), 5), d.fadeOut(o, 5), d.removeClass(o, "showSweetAlert"), d.addClass(o, "hideSweetAlert"), d.removeClass(o, "visible"); var a = o.querySelector(".sa-icon.sa-success");
  31. d.removeClass(a, "animate"), d.removeClass(a.querySelector(".sa-tip"), "animateSuccessTip"), d.removeClass(a.querySelector(".sa-long"), "animateSuccessLong"); var r = o.querySelector(".sa-icon.sa-error");
  32. d.removeClass(r, "animateErrorIcon"), d.removeClass(r.querySelector(".sa-x-mark"), "animateXMark"); var s = o.querySelector(".sa-icon.sa-warning"); return d.removeClass(s, "pulseWarning"), d.removeClass(s.querySelector(".sa-body"), "pulseWarningIns"), d.removeClass(s.querySelector(".sa-dot"), "pulseWarningIns"), setTimeout(function() { var e = o.getAttribute("data-custom-class");
  33. d.removeClass(o, e) }, 300), d.removeClass(t.body, "stop-scrolling"), e.onkeydown = l, e.previousActiveElement && e.previousActiveElement.focus(), i = n, clearTimeout(o.timeout), !0 }, u.showInputError = c.showInputError = function(e) { var t = p.getModal(),
  34. n = t.querySelector(".sa-input-error");
  35. d.addClass(n, "show"); var o = t.querySelector(".sa-error-container");
  36. d.addClass(o, "show"), o.querySelector("p").innerHTML = e, setTimeout(function() { u.enableButtons() }, 1), t.querySelector("input").focus() }, u.resetInputError = c.resetInputError = function(e) { if (e && 13 === e.keyCode) return !1; var t = p.getModal(),
  37. n = t.querySelector(".sa-input-error");
  38. d.removeClass(n, "show"); var o = t.querySelector(".sa-error-container");
  39. d.removeClass(o, "show") }, u.disableButtons = c.disableButtons = function() { var e = p.getModal(),
  40. t = e.querySelector("button.confirm"),
  41. n = e.querySelector("button.cancel");
  42. t.disabled = !0, n.disabled = !0 }, u.enableButtons = c.enableButtons = function() { var e = p.getModal(),
  43. t = e.querySelector("button.confirm"),
  44. n = e.querySelector("button.cancel");
  45. t.disabled = !1, n.disabled = !1 }, "undefined" != typeof e ? e.sweetAlert = e.swal = u : f.logStr("SweetAlert is a frontend module!"), a.exports = r["default"] }, { "./modules/default-params": 2, "./modules/handle-click": 3, "./modules/handle-dom": 4, "./modules/handle-key": 5, "./modules/handle-swal-dom": 6, "./modules/set-params": 8, "./modules/utils": 9 }], 2: [function(e, t, n) { Object.defineProperty(n, "__esModule", { value: !0 }); var o = { title: "", text: "", type: null, allowOutsideClick: !1, showConfirmButton: !0, showCancelButton: !1, closeOnConfirm: !0, closeOnCancel: !0, confirmButtonText: "OK", confirmButtonColor: "#8CD4F5", cancelButtonText: "Cancel", imageUrl: null, imageSize: null, timer: null, customClass: "", html: !1, animation: !0, allowEscapeKey: !0, inputType: "text", inputPlaceholder: "", inputValue: "", showLoaderOnConfirm: !1 };
  46. n["default"] = o, t.exports = n["default"] }, {}], 3: [function(t, n, o) { Object.defineProperty(o, "__esModule", { value: !0 }); var a = t("./utils"),
  47. r = (t("./handle-swal-dom"), t("./handle-dom")),
  48. s = function(t, n, o) {
  49. function s(e) { m && n.confirmButtonColor && (p.style.backgroundColor = e) } var u, c, d, f = t || e.event,
  50. p = f.target || f.srcElement,
  51. m = -1 !== p.className.indexOf("confirm"),
  52. v = -1 !== p.className.indexOf("sweet-overlay"),
  53. y = r.hasClass(o, "visible"),
  54. h = n.doneFunction && "true" === o.getAttribute("data-has-done-function"); switch (m && n.confirmButtonColor && (u = n.confirmButtonColor, c = a.colorLuminance(u, -.04), d = a.colorLuminance(u, -.14)), f.type) {
  55. case "mouseover":
  56. s(c); break;
  57. case "mouseout":
  58. s(u); break;
  59. case "mousedown":
  60. s(d); break;
  61. case "mouseup":
  62. s(c); break;
  63. case "focus":
  64. var b = o.querySelector("button.confirm"),
  65. g = o.querySelector("button.cancel");
  66. m ? g.style.boxShadow = "none" : b.style.boxShadow = "none"; break;
  67. case "click":
  68. var w = o === p,
  69. C = r.isDescendant(o, p); if (!w && !C && y && !n.allowOutsideClick) break;
  70. m && h && y ? l(o, n) : h && y || v ? i(o, n) : r.isDescendant(o, p) && "BUTTON" === p.tagName && sweetAlert.close() } },
  71. l = function(e, t) { var n = !0;
  72. r.hasClass(e, "show-input") && (n = e.querySelector("input").value, n || (n = "")), t.doneFunction(n), t.closeOnConfirm && sweetAlert.close(), t.showLoaderOnConfirm && sweetAlert.disableButtons() },
  73. i = function(e, t) { var n = String(t.doneFunction).replace(/\s/g, ""),
  74. o = "function(" === n.substring(0, 9) && ")" !== n.substring(9, 10);
  75. o && t.doneFunction(!1), t.closeOnCancel && sweetAlert.close() };
  76. o["default"] = { handleButton: s, handleConfirm: l, handleCancel: i }, n.exports = o["default"] }, { "./handle-dom": 4, "./handle-swal-dom": 6, "./utils": 9 }], 4: [function(n, o, a) { Object.defineProperty(a, "__esModule", { value: !0 }); var r = function(e, t) { return new RegExp(" " + t + " ").test(" " + e.className + " ") },
  77. s = function(e, t) { r(e, t) || (e.className += " " + t) },
  78. l = function(e, t) { var n = " " + e.className.replace(/[\t\r\n]/g, " ") + " "; if (r(e, t)) { for (; n.indexOf(" " + t + " ") >= 0;) n = n.replace(" " + t + " ", " ");
  79. e.className = n.replace(/^\s+|\s+$/g, "") } },
  80. i = function(e) { var n = t.createElement("div"); return n.appendChild(t.createTextNode(e)), n.innerHTML },
  81. u = function(e) { e.style.opacity = "", e.style.display = "block" },
  82. c = function(e) { if (e && !e.length) return u(e); for (var t = 0; t < e.length; ++t) u(e[t]) },
  83. d = function(e) { e.style.opacity = "", e.style.display = "none" },
  84. f = function(e) { if (e && !e.length) return d(e); for (var t = 0; t < e.length; ++t) d(e[t]) },
  85. p = function(e, t) { for (var n = t.parentNode; null !== n;) { if (n === e) return !0;
  86. n = n.parentNode } return !1 },
  87. m = function(e) { e.style.left = "-9999px", e.style.display = "block"; var t, n = e.clientHeight; return t = "undefined" != typeof getComputedStyle ? parseInt(getComputedStyle(e).getPropertyValue("padding-top"), 10) : parseInt(e.currentStyle.padding), e.style.left = "", e.style.display = "none", "-" + parseInt((n + t) / 2) + "px" },
  88. v = function(e, t) { if (+e.style.opacity < 1) { t = t || 16, e.style.opacity = 0, e.style.display = "block"; var n = +new Date,
  89. o = function(e) {
  90. function t() { return e.apply(this, arguments) } return t.toString = function() { return e.toString() }, t }(function() { e.style.opacity = +e.style.opacity + (new Date - n) / 100, n = +new Date, +e.style.opacity < 1 && setTimeout(o, t) });
  91. o() }
  92. e.style.display = "block" },
  93. y = function(e, t) { t = t || 16, e.style.opacity = 1; var n = +new Date,
  94. o = function(e) {
  95. function t() { return e.apply(this, arguments) } return t.toString = function() { return e.toString() }, t }(function() { e.style.opacity = +e.style.opacity - (new Date - n) / 100, n = +new Date, +e.style.opacity > 0 ? setTimeout(o, t) : e.style.display = "none" });
  96. o() },
  97. h = function(n) { if ("function" == typeof MouseEvent) { var o = new MouseEvent("click", { view: e, bubbles: !1, cancelable: !0 });
  98. n.dispatchEvent(o) } else if (t.createEvent) { var a = t.createEvent("MouseEvents");
  99. a.initEvent("click", !1, !1), n.dispatchEvent(a) } else t.createEventObject ? n.fireEvent("onclick") : "function" == typeof n.onclick && n.onclick() },
  100. b = function(t) { "function" == typeof t.stopPropagation ? (t.stopPropagation(), t.preventDefault()) : e.event && e.event.hasOwnProperty("cancelBubble") && (e.event.cancelBubble = !0) };
  101. a.hasClass = r, a.addClass = s, a.removeClass = l, a.escapeHtml = i, a._show = u, a.show = c, a._hide = d, a.hide = f, a.isDescendant = p, a.getTopMargin = m, a.fadeIn = v, a.fadeOut = y, a.fireClick = h, a.stopEventPropagation = b }, {}], 5: [function(t, o, a) { Object.defineProperty(a, "__esModule", { value: !0 }); var r = t("./handle-dom"),
  102. s = t("./handle-swal-dom"),
  103. l = function(t, o, a) { var l = t || e.event,
  104. i = l.keyCode || l.which,
  105. u = a.querySelector("button.confirm"),
  106. c = a.querySelector("button.cancel"),
  107. d = a.querySelectorAll("button[tabindex]"); if (-1 !== [9, 13, 32, 27].indexOf(i)) { for (var f = l.target || l.srcElement, p = -1, m = 0; m < d.length; m++)
  108. if (f === d[m]) { p = m; break }
  109. 9 === i ? (f = -1 === p ? u : p === d.length - 1 ? d[0] : d[p + 1], r.stopEventPropagation(l), f.focus(), o.confirmButtonColor && s.setFocusStyle(f, o.confirmButtonColor)) : 13 === i ? ("INPUT" === f.tagName && (f = u, u.focus()), f = -1 === p ? u : n) : 27 === i && o.allowEscapeKey === !0 ? (f = c, r.fireClick(f, l)) : f = n } };
  110. a["default"] = l, o.exports = a["default"] }, { "./handle-dom": 4, "./handle-swal-dom": 6 }], 6: [function(n, o, a) { var r = function(e) { return e && e.__esModule ? e : { "default": e } };
  111. Object.defineProperty(a, "__esModule", { value: !0 }); var s = n("./utils"),
  112. l = n("./handle-dom"),
  113. i = n("./default-params"),
  114. u = r(i),
  115. c = n("./injected-html"),
  116. d = r(c),
  117. f = ".sweet-alert",
  118. p = ".sweet-overlay",
  119. m = function() { var e = t.createElement("div"); for (e.innerHTML = d["default"]; e.firstChild;) t.body.appendChild(e.firstChild) },
  120. v = function(e) {
  121. function t() { return e.apply(this, arguments) } return t.toString = function() { return e.toString() }, t }(function() { var e = t.querySelector(f); return e || (m(), e = v()), e }),
  122. y = function() { var e = v(); return e ? e.querySelector("input") : void 0 },
  123. h = function() { return t.querySelector(p) },
  124. b = function(e, t) { var n = s.hexToRgb(t);
  125. e.style.boxShadow = "0 0 2px rgba(" + n + ", 0.8), inset 0 0 0 1px rgba(0, 0, 0, 0.05)" },
  126. g = function(n) { var o = v();
  127. l.fadeIn(h(), 10), l.show(o), l.addClass(o, "showSweetAlert"), l.removeClass(o, "hideSweetAlert"), e.previousActiveElement = t.activeElement; var a = o.querySelector("button.confirm");
  128. a.focus(), setTimeout(function() { l.addClass(o, "visible") }, 500); var r = o.getAttribute("data-timer"); if ("null" !== r && "" !== r) { var s = n;
  129. o.timeout = setTimeout(function() { var e = (s || null) && "true" === o.getAttribute("data-has-done-function");
  130. e ? s(null) : sweetAlert.close() }, r) } },
  131. w = function() { var e = v(),
  132. t = y();
  133. l.removeClass(e, "show-input"), t.value = u["default"].inputValue, t.setAttribute("type", u["default"].inputType), t.setAttribute("placeholder", u["default"].inputPlaceholder), C() },
  134. C = function(e) { if (e && 13 === e.keyCode) return !1; var t = v(),
  135. n = t.querySelector(".sa-input-error");
  136. l.removeClass(n, "show"); var o = t.querySelector(".sa-error-container");
  137. l.removeClass(o, "show") },
  138. S = function() { var e = v();
  139. e.style.marginTop = l.getTopMargin(v()) };
  140. a.sweetAlertInitialize = m, a.getModal = v, a.getOverlay = h, a.getInput = y, a.setFocusStyle = b, a.openModal = g, a.resetInput = w, a.resetInputError = C, a.fixVerticalPosition = S }, { "./default-params": 2, "./handle-dom": 4, "./injected-html": 7, "./utils": 9 }], 7: [function(e, t, n) { Object.defineProperty(n, "__esModule", { value: !0 }); var o = '<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert"><div class="sa-icon sa-error">\n <span class="sa-x-mark">\n <span class="sa-line sa-left"></span>\n <span class="sa-line sa-right"></span>\n </span>\n </div><div class="sa-icon sa-warning">\n <span class="sa-body"></span>\n <span class="sa-dot"></span>\n </div><div class="sa-icon sa-info"></div><div class="sa-icon sa-success">\n <span class="sa-line sa-tip"></span>\n <span class="sa-line sa-long"></span>\n\n <div class="sa-placeholder"></div>\n <div class="sa-fix"></div>\n </div><div class="sa-icon sa-custom"></div><h2>Title</h2>\n <p>Text</p>\n <fieldset>\n <input type="text" tabIndex="3" />\n <div class="sa-input-error"></div>\n </fieldset><div class="sa-error-container">\n <div class="icon">!</div>\n <p>Not valid!</p>\n </div><div class="sa-button-container">\n <button class="cancel" tabIndex="2">Cancel</button>\n <div class="sa-confirm-button-container">\n <button class="confirm" tabIndex="1">OK</button><div class="la-ball-fall">\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div>\n </div></div>';
  141. n["default"] = o, t.exports = n["default"] }, {}], 8: [function(e, t, o) { Object.defineProperty(o, "__esModule", { value: !0 }); var a = e("./utils"),
  142. r = e("./handle-swal-dom"),
  143. s = e("./handle-dom"),
  144. l = ["error", "warning", "info", "success", "input", "prompt"],
  145. i = function(e) { var t = r.getModal(),
  146. o = t.querySelector("h2"),
  147. i = t.querySelector("p"),
  148. u = t.querySelector("button.cancel"),
  149. c = t.querySelector("button.confirm"); if (o.innerHTML = e.html ? e.title : s.escapeHtml(e.title).split("\n").join("<br>"), i.innerHTML = e.html ? e.text : s.escapeHtml(e.text || "").split("\n").join("<br>"), e.text && s.show(i), e.customClass) s.addClass(t, e.customClass), t.setAttribute("data-custom-class", e.customClass);
  150. else { var d = t.getAttribute("data-custom-class");
  151. s.removeClass(t, d), t.setAttribute("data-custom-class", "") } if (s.hide(t.querySelectorAll(".sa-icon")), e.type && !a.isIE8()) { var f = function() { for (var o = !1, a = 0; a < l.length; a++)
  152. if (e.type === l[a]) { o = !0; break }
  153. if (!o) return logStr("Unknown alert type: " + e.type), { v: !1 }; var i = ["success", "error", "warning", "info"],
  154. u = n; - 1 !== i.indexOf(e.type) && (u = t.querySelector(".sa-icon.sa-" + e.type), s.show(u)); var c = r.getInput(); switch (e.type) {
  155. case "success":
  156. s.addClass(u, "animate"), s.addClass(u.querySelector(".sa-tip"), "animateSuccessTip"), s.addClass(u.querySelector(".sa-long"), "animateSuccessLong"); break;
  157. case "error":
  158. s.addClass(u, "animateErrorIcon"), s.addClass(u.querySelector(".sa-x-mark"), "animateXMark"); break;
  159. case "warning":
  160. s.addClass(u, "pulseWarning"), s.addClass(u.querySelector(".sa-body"), "pulseWarningIns"), s.addClass(u.querySelector(".sa-dot"), "pulseWarningIns"); break;
  161. case "input":
  162. case "prompt":
  163. c.setAttribute("type", e.inputType), c.value = e.inputValue, c.setAttribute("placeholder", e.inputPlaceholder), s.addClass(t, "show-input"), setTimeout(function() { c.focus(), c.addEventListener("keyup", swal.resetInputError) }, 400) } }(); if ("object" == typeof f) return f.v } if (e.imageUrl) { var p = t.querySelector(".sa-icon.sa-custom");
  164. p.style.backgroundImage = "url(" + e.imageUrl + ")", s.show(p); var m = 80,
  165. v = 80; if (e.imageSize) { var y = e.imageSize.toString().split("x"),
  166. h = y[0],
  167. b = y[1];
  168. h && b ? (m = h, v = b) : logStr("Parameter imageSize expects value with format WIDTHxHEIGHT, got " + e.imageSize) }
  169. p.setAttribute("style", p.getAttribute("style") + "width:" + m + "px; height:" + v + "px") }
  170. t.setAttribute("data-has-cancel-button", e.showCancelButton), e.showCancelButton ? u.style.display = "inline-block" : s.hide(u), t.setAttribute("data-has-confirm-button", e.showConfirmButton), e.showConfirmButton ? c.style.display = "inline-block" : s.hide(c), e.cancelButtonText && (u.innerHTML = s.escapeHtml(e.cancelButtonText)), e.confirmButtonText && (c.innerHTML = s.escapeHtml(e.confirmButtonText)), e.confirmButtonColor && (c.style.backgroundColor = e.confirmButtonColor, c.style.borderLeftColor = e.confirmLoadingButtonColor, c.style.borderRightColor = e.confirmLoadingButtonColor, r.setFocusStyle(c, e.confirmButtonColor)), t.setAttribute("data-allow-outside-click", e.allowOutsideClick); var g = e.doneFunction ? !0 : !1;
  171. t.setAttribute("data-has-done-function", g), e.animation ? "string" == typeof e.animation ? t.setAttribute("data-animation", e.animation) : t.setAttribute("data-animation", "pop") : t.setAttribute("data-animation", "none"), t.setAttribute("data-timer", e.timer) };
  172. o["default"] = i, t.exports = o["default"] }, { "./handle-dom": 4, "./handle-swal-dom": 6, "./utils": 9 }], 9: [function(t, n, o) { Object.defineProperty(o, "__esModule", { value: !0 }); var a = function(e, t) { for (var n in t) t.hasOwnProperty(n) && (e[n] = t[n]); return e },
  173. r = function(e) { var t = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e); return t ? parseInt(t[1], 16) + ", " + parseInt(t[2], 16) + ", " + parseInt(t[3], 16) : null },
  174. s = function() { return e.attachEvent && !e.addEventListener },
  175. l = function(t) { e.console && e.console.log("SweetAlert: " + t) },
  176. i = function(e, t) { e = String(e).replace(/[^0-9a-f]/gi, ""), e.length < 6 && (e = e[0] + e[0] + e[1] + e[1] + e[2] + e[2]), t = t || 0; var n, o, a = "#"; for (o = 0; 3 > o; o++) n = parseInt(e.substr(2 * o, 2), 16), n = Math.round(Math.min(Math.max(0, n + n * t), 255)).toString(16), a += ("00" + n).substr(n.length); return a };
  177. o.extend = a, o.hexToRgb = r, o.isIE8 = s, o.logStr = l, o.colorLuminance = i }, {}] }, {}, [1]), "function" == typeof define && define.amd ? define(function() { return sweetAlert }) : "undefined" != typeof module && module.exports && (module.exports = sweetAlert) }(window, document);