Built files from Bizgaze WebServer
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

jquery.toast.min.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "function" != typeof Object.create && (Object.create = function (t) {
  2. function o() { }
  3. return o.prototype = t, new o
  4. }),
  5. function (t, o, i, s) {
  6. "use strict";
  7. var n = {
  8. _positionClasses: ["bottom-left", "bottom-right", "top-right", "top-left", "bottom-center", "top-center", "mid-center"],
  9. _defaultIcons: ["success", "error", "info", "warning"],
  10. init: function (o, i) {
  11. this.prepareOptions(o, t.toast.options), this.process()
  12. },
  13. prepareOptions: function (o, i) {
  14. var s = {};
  15. "string" == typeof o || o instanceof Array ? s.text = o : s = o, this.options = t.extend({}, i, s)
  16. },
  17. process: function () {
  18. this.setup(), this.addToDom(), this.position(), this.bindToast(), this.animate()
  19. },
  20. setup: function () {
  21. var o = "";
  22. if (this._toastEl = this._toastEl || t("<div></div>", {
  23. "class": "jq-toast-single shadow"
  24. }), o += '<span class="jq-toast-loader"></span>', this.options.allowToastClose && (o += '<span class="close-jq-toast-single text-danger">&times;</span>'), this.options.text instanceof Array) {
  25. this.options.heading && (o += '<div class="d-flex list-inline"><div><i class="la la-check-circle text-success font-30"></i> </div><div class=""><h2 class="jq-toast-heading text-success">' + this.options.heading + '</h2> </div></div>'), o += '<ul class="jq-toast-ul">';
  26. for (var i = 0; i < this.options.text.length; i++) o += '<li class="jq-toast-li" id="jq-toast-item-' + i + '">' + this.options.text[i] + "</li>";
  27. o += "</ul>"
  28. } else this.options.heading && (o += '<div class="d-flex list-inline"><div class="mr-4"><i class="la la-check-circle text-success font-40"></i> </div><div><h3 class="jq-toast-heading text-success">' + this.options.heading + '</h3> <h3 class="font-14 font-weight-400 mt-1"> ' + this.options.text + ' <h3> </div></div>');
  29. this._toastEl.html(o), this.options.bgColor !== !1 && this._toastEl.css("background-color", this.options.bgColor), this.options.textColor !== !1 && this._toastEl.css("color", this.options.textColor), this.options.textAlign && this._toastEl.css("text-align", this.options.textAlign), this.options.icon !== !1 && (this._toastEl.addClass("jq-has-icon"), -1 !== t.inArray(this.options.icon, this._defaultIcons) && this._toastEl.addClass("jq-icon-" + this.options.icon)), this.options["class"] !== !1 && this._toastEl.addClass(this.options["class"])
  30. },
  31. position: function () {
  32. "string" == typeof this.options.position && -1 !== t.inArray(this.options.position, this._positionClasses) ? "bottom-center" === this.options.position ? this._container.css({
  33. left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2,
  34. bottom: 20
  35. }) : "top-center" === this.options.position ? this._container.css({
  36. left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2,
  37. top: 20
  38. }) : "mid-center" === this.options.position ? this._container.css({
  39. left: t(o).outerWidth() / 2 - this._container.outerWidth() / 2,
  40. top: t(o).outerHeight() / 2 - this._container.outerHeight() / 2
  41. }) : this._container.addClass(this.options.position) : "object" == typeof this.options.position ? this._container.css({
  42. top: this.options.position.top ? this.options.position.top : "auto",
  43. bottom: this.options.position.bottom ? this.options.position.bottom : "auto",
  44. left: this.options.position.left ? this.options.position.left : "auto",
  45. right: this.options.position.right ? this.options.position.right : "auto"
  46. }) : this._container.addClass("bottom-left")
  47. },
  48. bindToast: function () {
  49. var t = this;
  50. this._toastEl.on("afterShown", function () {
  51. t.processLoader()
  52. }), this._toastEl.find(".close-jq-toast-single").on("click", function (o) {
  53. o.preventDefault(), "fade" === t.options.showHideTransition ? (t._toastEl.trigger("beforeHide"), t._toastEl.fadeOut(function () {
  54. t._toastEl.trigger("afterHidden")
  55. })) : "slide" === t.options.showHideTransition ? (t._toastEl.trigger("beforeHide"), t._toastEl.slideUp(function () {
  56. t._toastEl.trigger("afterHidden")
  57. })) : (t._toastEl.trigger("beforeHide"), t._toastEl.hide(function () {
  58. t._toastEl.trigger("afterHidden")
  59. }))
  60. }), "function" == typeof this.options.beforeShow && this._toastEl.on("beforeShow", function () {
  61. t.options.beforeShow()
  62. }), "function" == typeof this.options.afterShown && this._toastEl.on("afterShown", function () {
  63. t.options.afterShown()
  64. }), "function" == typeof this.options.beforeHide && this._toastEl.on("beforeHide", function () {
  65. t.options.beforeHide()
  66. }), "function" == typeof this.options.afterHidden && this._toastEl.on("afterHidden", function () {
  67. t.options.afterHidden()
  68. })
  69. },
  70. addToDom: function () {
  71. var o = t(".jq-toast-wrap");
  72. if (0 === o.length ? (o = t("<div></div>", {
  73. "class": "jq-toast-wrap"
  74. }), t("body").append(o)) : (!this.options.stack || isNaN(parseInt(this.options.stack, 10))) && o.empty(), o.find(".jq-toast-single:hidden").remove(), o.append(this._toastEl), this.options.stack && !isNaN(parseInt(this.options.stack), 10)) {
  75. var i = o.find(".jq-toast-single").length,
  76. s = i - this.options.stack;
  77. s > 0 && t(".jq-toast-wrap").find(".jq-toast-single").slice(0, s).remove()
  78. }
  79. this._container = o
  80. },
  81. canAutoHide: function () {
  82. return this.options.hideAfter !== !1 && !isNaN(parseInt(this.options.hideAfter, 10))
  83. },
  84. processLoader: function () {
  85. if (!this.canAutoHide() || this.options.loader === !1) return !1;
  86. var t = this._toastEl.find(".jq-toast-loader"),
  87. o = (this.options.hideAfter - 400) / 1e3 + "s",
  88. i = this.options.loaderBg,
  89. s = t.attr("style") || "";
  90. s = s.substring(0, s.indexOf("-webkit-transition")), s += "-webkit-transition: width " + o + " ease-in; -o-transition: width " + o + " ease-in; transition: width " + o + " ease-in; background-color: " + i + ";", t.attr("style", s).addClass("jq-toast-loaded")
  91. },
  92. animate: function () {
  93. var t = this;
  94. if (this._toastEl.hide(), this._toastEl.trigger("beforeShow"), "fade" === this.options.showHideTransition.toLowerCase() ? this._toastEl.fadeIn(function () {
  95. t._toastEl.trigger("afterShown")
  96. }) : "slide" === this.options.showHideTransition.toLowerCase() ? this._toastEl.slideDown(function () {
  97. t._toastEl.trigger("afterShown")
  98. }) : this._toastEl.show(function () {
  99. t._toastEl.trigger("afterShown")
  100. }), this.canAutoHide()) {
  101. var t = this;
  102. o.setTimeout(function () {
  103. "fade" === t.options.showHideTransition.toLowerCase() ? (t._toastEl.trigger("beforeHide"), t._toastEl.fadeOut(function () {
  104. t._toastEl.trigger("afterHidden")
  105. })) : "slide" === t.options.showHideTransition.toLowerCase() ? (t._toastEl.trigger("beforeHide"), t._toastEl.slideUp(function () {
  106. t._toastEl.trigger("afterHidden")
  107. })) : (t._toastEl.trigger("beforeHide"), t._toastEl.hide(function () {
  108. t._toastEl.trigger("afterHidden")
  109. }))
  110. }, this.options.hideAfter)
  111. }
  112. },
  113. reset: function (o) {
  114. "all" === o ? t(".jq-toast-wrap").remove() : this._toastEl.remove()
  115. },
  116. update: function (t) {
  117. this.prepareOptions(t, this.options), this.setup(), this.bindToast()
  118. }
  119. };
  120. t.toast = function (t) {
  121. var o = Object.create(n);
  122. return o.init(t, this), {
  123. reset: function (t) {
  124. o.reset(t)
  125. },
  126. update: function (t) {
  127. o.update(t)
  128. }
  129. }
  130. }, t.toast.options = {
  131. text: "",
  132. heading: "",
  133. showHideTransition: "fade",
  134. allowToastClose: !0,
  135. hideAfter: 3e3,
  136. loader: !0,
  137. loaderBg: "#75FFA3",
  138. stack: 5,
  139. position: "bottom-left",
  140. bgColor: !1,
  141. textColor: !1,
  142. textAlign: "left",
  143. icon: !1,
  144. beforeShow: function () { },
  145. afterShown: function () { },
  146. beforeHide: function () { },
  147. afterHidden: function () { }
  148. }
  149. }(jQuery, window, document);