nprogress.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /** kit_admin-v1.0.5 MIT License By http://kit/zhengjinfan.cn e-mail:zheng_jinfan@126.com */
  2. ;
  3. layui.define(function(n) { !
  4. function(e, t) {
  5. "function" == typeof define && define.amd ? define(t) : "object" == typeof n ? module.exports = t() : e.NProgress = t()
  6. } (this,
  7. function() {
  8. function n(n, e, t) {
  9. return n < e ? e: n > t ? t: n
  10. }
  11. function e(n) {
  12. return 100 * ( - 1 + n)
  13. }
  14. function t(n, t, r) {
  15. var i;
  16. return i = "translate3d" === c.positionUsing ? {
  17. transform: "translate3d(" + e(n) + "%,0,0)"
  18. }: "translate" === c.positionUsing ? {
  19. transform: "translate(" + e(n) + "%,0)"
  20. }: {
  21. "margin-left": e(n) + "%"
  22. },
  23. i.transition = "all " + t + "ms " + r,
  24. i
  25. }
  26. function r(n, e) {
  27. return ("string" == typeof n ? n: o(n)).indexOf(" " + e + " ") >= 0
  28. }
  29. function i(n, e) {
  30. var t = o(n),
  31. i = t + e;
  32. r(t, e) || (n.className = i.substring(1))
  33. }
  34. function s(n, e) {
  35. var t, i = o(n);
  36. r(n, e) && (t = i.replace(" " + e + " ", " "), n.className = t.substring(1, t.length - 1))
  37. }
  38. function o(n) {
  39. return (" " + (n.className || "") + " ").replace(/\s+/gi, " ")
  40. }
  41. function a(n) {
  42. n && n.parentNode && n.parentNode.removeChild(n)
  43. }
  44. var u = {};
  45. u.version = "0.2.0";
  46. var c = u.settings = {
  47. minimum: .08,
  48. easing: "ease",
  49. positionUsing: "",
  50. speed: 200,
  51. trickle: !0,
  52. trickleRate: .02,
  53. trickleSpeed: 800,
  54. showSpinner: !0,
  55. barSelector: '[role="bar"]',
  56. spinnerSelector: '[role="spinner"]',
  57. parent: "body",
  58. template: '<div class="bar" role="bar"><div class="peg"></div></div><div class="spinner" role="spinner"><div class="spinner-icon"></div></div>'
  59. };
  60. u.configure = function(n) {
  61. var e, t;
  62. for (e in n) void 0 !== (t = n[e]) && n.hasOwnProperty(e) && (c[e] = t);
  63. return this
  64. },
  65. u.status = null,
  66. u.set = function(e) {
  67. var r = u.isStarted();
  68. e = n(e, c.minimum, 1),
  69. u.status = 1 === e ? null: e;
  70. var i = u.render(!r),
  71. s = i.querySelector(c.barSelector),
  72. o = c.speed,
  73. a = c.easing;
  74. return i.offsetWidth,
  75. l(function(n) {
  76. "" === c.positionUsing && (c.positionUsing = u.getPositioningCSS()),
  77. f(s, t(e, o, a)),
  78. 1 === e ? (f(i, {
  79. transition: "none",
  80. opacity: 1
  81. }), i.offsetWidth, setTimeout(function() {
  82. f(i, {
  83. transition: "all " + o + "ms linear",
  84. opacity: 0
  85. }),
  86. setTimeout(function() {
  87. u.remove(),
  88. n()
  89. },
  90. o)
  91. },
  92. o)) : setTimeout(n, o)
  93. }),
  94. this
  95. },
  96. u.isStarted = function() {
  97. return "number" == typeof u.status
  98. },
  99. u.start = function() {
  100. u.status || u.set(0);
  101. var n = function() {
  102. setTimeout(function() {
  103. u.status && (u.trickle(), n())
  104. },
  105. c.trickleSpeed)
  106. };
  107. return c.trickle && n(),
  108. this
  109. },
  110. u.done = function(n) {
  111. return n || u.status ? u.inc(.3 + .5 * Math.random()).set(1) : this
  112. },
  113. u.inc = function(e) {
  114. var t = u.status;
  115. return t ? ("number" != typeof e && (e = (1 - t) * n(Math.random() * t, .1, .95)), t = n(t + e, 0, .994), u.set(t)) : u.start()
  116. },
  117. u.trickle = function() {
  118. return u.inc(Math.random() * c.trickleRate)
  119. },
  120. function() {
  121. var n = 0,
  122. e = 0;
  123. u.promise = function(t) {
  124. return t && "resolved" !== t.state() ? (0 === e && u.start(), n++, e++, t.always(function() {
  125. 0 === --e ? (n = 0, u.done()) : u.set((n - e) / n)
  126. }), this) : this
  127. }
  128. } (),
  129. u.render = function(n) {
  130. if (u.isRendered()) return document.getElementById("nprogress");
  131. i(document.documentElement, "nprogress-busy");
  132. var t = document.createElement("div");
  133. t.id = "nprogress",
  134. t.innerHTML = c.template;
  135. var r, s = t.querySelector(c.barSelector),
  136. o = n ? "-100": e(u.status || 0),
  137. l = document.querySelector(c.parent);
  138. return f(s, {
  139. transition: "all 0 linear",
  140. transform: "translate3d(" + o + "%,0,0)"
  141. }),
  142. c.showSpinner || (r = t.querySelector(c.spinnerSelector)) && a(r),
  143. l != document.body && i(l, "nprogress-custom-parent"),
  144. l.appendChild(t),
  145. t
  146. },
  147. u.remove = function() {
  148. s(document.documentElement, "nprogress-busy"),
  149. s(document.querySelector(c.parent), "nprogress-custom-parent");
  150. var n = document.getElementById("nprogress");
  151. n && a(n)
  152. },
  153. u.isRendered = function() {
  154. return !! document.getElementById("nprogress")
  155. },
  156. u.getPositioningCSS = function() {
  157. var n = document.body.style,
  158. e = "WebkitTransform" in n ? "Webkit": "MozTransform" in n ? "Moz": "msTransform" in n ? "ms": "OTransform" in n ? "O": "";
  159. return e + "Perspective" in n ? "translate3d": e + "Transform" in n ? "translate": "margin"
  160. };
  161. var l = function() {
  162. function n() {
  163. var t = e.shift();
  164. t && t(n)
  165. }
  166. var e = [];
  167. return function(t) {
  168. e.push(t),
  169. 1 == e.length && n()
  170. }
  171. } (),
  172. f = function() {
  173. function n(n) {
  174. return n.replace(/^-ms-/, "ms-").replace(/-([\da-z])/gi,
  175. function(n, e) {
  176. return e.toUpperCase()
  177. })
  178. }
  179. function e(n) {
  180. var e = document.body.style;
  181. if (n in e) return n;
  182. for (var t, r = i.length,
  183. s = n.charAt(0).toUpperCase() + n.slice(1); r--;) if ((t = i[r] + s) in e) return t;
  184. return n
  185. }
  186. function t(t) {
  187. return t = n(t),
  188. s[t] || (s[t] = e(t))
  189. }
  190. function r(n, e, r) {
  191. e = t(e),
  192. n.style[e] = r
  193. }
  194. var i = ["Webkit", "O", "Moz", "ms"],
  195. s = {};
  196. return function(n, e) {
  197. var t, i, s = arguments;
  198. if (2 == s.length) for (t in e) void 0 !== (i = e[t]) && e.hasOwnProperty(t) && r(n, t, i);
  199. else r(n, s[1], s[2])
  200. }
  201. } ();
  202. return u
  203. }),
  204. layui.link("/static/css/nprogress.css"),
  205. n("nprogress")
  206. });