util.dev.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. "use strict";
  2. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. /** layui-v2.5.6 MIT License By https://www.layui.com */
  4. ;
  5. layui.define("jquery", function (e) {
  6. "use strict";
  7. var t = layui.$,
  8. i = {
  9. fixbar: function fixbar(e) {
  10. var i,
  11. n,
  12. a = "layui-fixbar",
  13. o = "layui-fixbar-top",
  14. r = t(document),
  15. l = t("body");
  16. e = t.extend({
  17. showHeight: 200
  18. }, e), e.bar1 = e.bar1 === !0 ? "" : e.bar1, e.bar2 = e.bar2 === !0 ? "" : e.bar2, e.bgcolor = e.bgcolor ? "background-color:" + e.bgcolor : "";
  19. var c = [e.bar1, e.bar2, ""],
  20. u = t(['<ul class="' + a + '">', e.bar1 ? '<li class="layui-icon" lay-type="bar1" style="' + e.bgcolor + '">' + c[0] + "</li>" : "", e.bar2 ? '<li class="layui-icon" lay-type="bar2" style="' + e.bgcolor + '">' + c[1] + "</li>" : "", '<li class="layui-icon ' + o + '" lay-type="top" style="' + e.bgcolor + '">' + c[2] + "</li>", "</ul>"].join("")),
  21. g = u.find("." + o),
  22. s = function s() {
  23. var t = r.scrollTop();
  24. t >= e.showHeight ? i || (g.show(), i = 1) : i && (g.hide(), i = 0);
  25. };
  26. t("." + a)[0] || ("object" == _typeof(e.css) && u.css(e.css), l.append(u), s(), u.find("li").on("click", function () {
  27. var i = t(this),
  28. n = i.attr("lay-type");
  29. "top" === n && t("html,body").animate({
  30. scrollTop: 0
  31. }, 200), e.click && e.click.call(this, n);
  32. }), r.on("scroll", function () {
  33. clearTimeout(n), n = setTimeout(function () {
  34. s();
  35. }, 100);
  36. }));
  37. },
  38. countdown: function countdown(e, t, i) {
  39. var n = this,
  40. a = "function" == typeof t,
  41. o = new Date(e).getTime(),
  42. r = new Date(!t || a ? new Date().getTime() : t).getTime(),
  43. l = o - r,
  44. c = [Math.floor(l / 864e5), Math.floor(l / 36e5) % 24, Math.floor(l / 6e4) % 60, Math.floor(l / 1e3) % 60];
  45. a && (i = t);
  46. var u = setTimeout(function () {
  47. n.countdown(e, r + 1e3, i);
  48. }, 1e3);
  49. return i && i(l > 0 ? c : [0, 0, 0, 0], t, u), l <= 0 && clearTimeout(u), u;
  50. },
  51. timeAgo: function timeAgo(e, t) {
  52. var i = this,
  53. n = [[], []],
  54. a = new Date().getTime() - new Date(e).getTime();
  55. return a > 26784e5 ? (a = new Date(e), n[0][0] = i.digit(a.getFullYear(), 4), n[0][1] = i.digit(a.getMonth() + 1), n[0][2] = i.digit(a.getDate()), t || (n[1][0] = i.digit(a.getHours()), n[1][1] = i.digit(a.getMinutes()), n[1][2] = i.digit(a.getSeconds())), n[0].join("-") + " " + n[1].join(":")) : a >= 864e5 ? (a / 1e3 / 60 / 60 / 24 | 0) + "天前" : a >= 36e5 ? (a / 1e3 / 60 / 60 | 0) + "小时前" : a >= 18e4 ? (a / 1e3 / 60 | 0) + "分钟前" : a < 0 ? "未来" : "刚刚";
  56. },
  57. digit: function digit(e, t) {
  58. var i = "";
  59. e = String(e), t = t || 2;
  60. for (var n = e.length; n < t; n++) {
  61. i += "0";
  62. }
  63. return e < Math.pow(10, t) ? i + (0 | e) : e;
  64. },
  65. toDateString: function toDateString(e, t) {
  66. var i = this,
  67. n = new Date(e || new Date()),
  68. a = [i.digit(n.getFullYear(), 4), i.digit(n.getMonth() + 1), i.digit(n.getDate())],
  69. o = [i.digit(n.getHours()), i.digit(n.getMinutes()), i.digit(n.getSeconds())];
  70. return t = t || "yyyy-MM-dd HH:mm:ss", t.replace(/yyyy/g, a[0]).replace(/MM/g, a[1]).replace(/dd/g, a[2]).replace(/HH/g, o[0]).replace(/mm/g, o[1]).replace(/ss/g, o[2]);
  71. },
  72. escape: function escape(e) {
  73. return String(e || "").replace(/&(?!#?[a-zA-Z0-9]+;)/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, "&#39;").replace(/"/g, "&quot;");
  74. },
  75. event: function event(e, n, a) {
  76. var o = t("body");
  77. return a = a || "click", n = i.event[e] = t.extend(!0, i.event[e], n) || {}, i.event.UTIL_EVENT_CALLBACK = i.event.UTIL_EVENT_CALLBACK || {}, o.off(a, "*[" + e + "]", i.event.UTIL_EVENT_CALLBACK[e]), i.event.UTIL_EVENT_CALLBACK[e] = function () {
  78. var i = t(this),
  79. a = i.attr(e);
  80. "function" == typeof n[a] && n[a].call(this, i);
  81. }, o.on(a, "*[" + e + "]", i.event.UTIL_EVENT_CALLBACK[e]), n;
  82. }
  83. };
  84. !function (e, t, i) {
  85. "$:nomunge";
  86. function n() {
  87. a = t[l](function () {
  88. o.each(function () {
  89. var t = e(this),
  90. i = t.width(),
  91. n = t.height(),
  92. a = e.data(this, u);
  93. (i !== a.w || n !== a.h) && t.trigger(c, [a.w = i, a.h = n]);
  94. }), n();
  95. }, r[g]);
  96. }
  97. var a,
  98. o = e([]),
  99. r = e.resize = e.extend(e.resize, {}),
  100. l = "setTimeout",
  101. c = "resize",
  102. u = c + "-special-event",
  103. g = "delay",
  104. s = "throttleWindow";
  105. r[g] = 250, r[s] = !0, e.event.special[c] = {
  106. setup: function setup() {
  107. if (!r[s] && this[l]) return !1;
  108. var t = e(this);
  109. o = o.add(t), e.data(this, u, {
  110. w: t.width(),
  111. h: t.height()
  112. }), 1 === o.length && n();
  113. },
  114. teardown: function teardown() {
  115. if (!r[s] && this[l]) return !1;
  116. var t = e(this);
  117. o = o.not(t), t.removeData(u), o.length || clearTimeout(a);
  118. },
  119. add: function add(t) {
  120. function n(t, n, o) {
  121. var r = e(this),
  122. l = e.data(this, u) || {};
  123. l.w = n !== i ? n : r.width(), l.h = o !== i ? o : r.height(), a.apply(this, arguments);
  124. }
  125. if (!r[s] && this[l]) return !1;
  126. var a;
  127. return e.isFunction(t) ? (a = t, n) : (a = t.handler, void (t.handler = n));
  128. }
  129. };
  130. }(t, window), e("util", i);
  131. });