layui.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /** layui-v2.5.4 MIT License By https://www.layui.com */
  2. ;!function (e) {
  3. "use strict";
  4. var t = document, o = {modules: {}, status: {}, timeout: 10, event: {}}, n = function () {
  5. this.v = "2.5.4"
  6. }, r = function () {
  7. var e = t.currentScript ? t.currentScript.src : function () {
  8. for (var e, o = t.scripts, n = o.length - 1, r = n; r > 0; r--) if ("interactive" === o[r].readyState) {
  9. e = o[r].src;
  10. break
  11. }
  12. return e || o[n].src
  13. }();
  14. return e.substring(0, e.lastIndexOf("/") + 1)
  15. }(), i = function (t) {
  16. e.console && console.error && console.error("Layui hint: " + t)
  17. }, a = "undefined" != typeof opera && "[object Opera]" === opera.toString(), u = {
  18. layer: "modules/layer",
  19. laydate: "modules/laydate",
  20. laypage: "modules/laypage",
  21. laytpl: "modules/laytpl",
  22. layim: "modules/layim",
  23. layedit: "modules/layedit",
  24. form: "modules/form",
  25. upload: "modules/upload",
  26. transfer: "modules/transfer",
  27. tree: "modules/tree",
  28. table: "modules/table",
  29. element: "modules/element",
  30. rate: "modules/rate",
  31. colorpicker: "modules/colorpicker",
  32. slider: "modules/slider",
  33. carousel: "modules/carousel",
  34. flow: "modules/flow",
  35. util: "modules/util",
  36. code: "modules/code",
  37. jquery: "modules/jquery",
  38. mobile: "modules/mobile",
  39. "layui.all": "../layui.all"
  40. };
  41. n.prototype.cache = o, n.prototype.define = function (e, t) {
  42. var n = this, r = "function" == typeof e, i = function () {
  43. var e = function (e, t) {
  44. layui[e] = t, o.status[e] = !0
  45. };
  46. return "function" == typeof t && t(function (n, r) {
  47. e(n, r), o.callback[n] = function () {
  48. t(e)
  49. }
  50. }), this
  51. };
  52. return r && (t = e, e = []), !layui["layui.all"] && layui["layui.mobile"] ? i.call(n) : (n.use(e, i), n)
  53. }, n.prototype.use = function (e, n, l) {
  54. function s(e, t) {
  55. var n = "PLaySTATION 3" === navigator.platform ? /^complete$/ : /^(complete|loaded)$/;
  56. ("load" === e.type || n.test((e.currentTarget || e.srcElement).readyState)) && (o.modules[f] = t, d.removeChild(v), function r() {
  57. return ++m > 1e3 * o.timeout / 4 ? i(f + " is not a valid module") : void (o.status[f] ? c() : setTimeout(r, 4))
  58. }())
  59. }
  60. function c() {
  61. l.push(layui[f]), e.length > 1 ? y.use(e.slice(1), n, l) : "function" == typeof n && n.apply(layui, l)
  62. }
  63. var y = this, p = o.dir = o.dir ? o.dir : r, d = t.getElementsByTagName("head")[0];
  64. e = "string" == typeof e ? [e] : e, window.jQuery && jQuery.fn.on && (y.each(e, function (t, o) {
  65. "jquery" === o && e.splice(t, 1)
  66. }), layui.jquery = layui.$ = jQuery);
  67. var f = e[0], m = 0;
  68. if (l = l || [], o.host = o.host || (p.match(/\/\/([\s\S]+?)\//) || ["//" + location.host + "/"])[0], 0 === e.length || layui["layui.all"] && u[f] || !layui["layui.all"] && layui["layui.mobile"] && u[f]) return c(), y;
  69. if (o.modules[f]) !function g() {
  70. return ++m > 1e3 * o.timeout / 4 ? i(f + " is not a valid module") : void ("string" == typeof o.modules[f] && o.status[f] ? c() : setTimeout(g, 4))
  71. }(); else {
  72. var v = t.createElement("script"),
  73. h = (u[f] ? p + "lay/" : /^\{\/\}/.test(y.modules[f]) ? "" : o.base || "") + (y.modules[f] || f) + ".js";
  74. h = h.replace(/^\{\/\}/, ""), v.async = !0, v.charset = "utf-8", v.src = h + function () {
  75. var e = o.version === !0 ? o.v || (new Date).getTime() : o.version || "";
  76. return e ? "?v=" + e : ""
  77. }(), d.appendChild(v), !v.attachEvent || v.attachEvent.toString && v.attachEvent.toString().indexOf("[native code") < 0 || a ? v.addEventListener("load", function (e) {
  78. s(e, h)
  79. }, !1) : v.attachEvent("onreadystatechange", function (e) {
  80. s(e, h)
  81. }), o.modules[f] = h
  82. }
  83. return y
  84. }, n.prototype.getStyle = function (t, o) {
  85. var n = t.currentStyle ? t.currentStyle : e.getComputedStyle(t, null);
  86. return n[n.getPropertyValue ? "getPropertyValue" : "getAttribute"](o)
  87. }, n.prototype.link = function (e, n, r) {
  88. var a = this, u = t.createElement("link"), l = t.getElementsByTagName("head")[0];
  89. "string" == typeof n && (r = n);
  90. var s = (r || e).replace(/\.|\//g, ""), c = u.id = "layuicss-" + s, y = 0;
  91. return u.rel = "stylesheet", u.href = e + (o.debug ? "?v=" + (new Date).getTime() : ""), u.media = "all", t.getElementById(c) || l.appendChild(u), "function" != typeof n ? a : (function p() {
  92. return ++y > 1e3 * o.timeout / 100 ? i(e + " timeout") : void (1989 === parseInt(a.getStyle(t.getElementById(c), "width")) ? function () {
  93. n()
  94. }() : setTimeout(p, 100))
  95. }(), a)
  96. }, o.callback = {}, n.prototype.factory = function (e) {
  97. if (layui[e]) return "function" == typeof o.callback[e] ? o.callback[e] : null
  98. }, n.prototype.addcss = function (e, t, n) {
  99. return layui.link(o.dir + "css/" + e, t, n)
  100. }, n.prototype.img = function (e, t, o) {
  101. var n = new Image;
  102. return n.src = e, n.complete ? t(n) : (n.onload = function () {
  103. n.onload = null, "function" == typeof t && t(n)
  104. }, void (n.onerror = function (e) {
  105. n.onerror = null, "function" == typeof o && o(e)
  106. }))
  107. }, n.prototype.config = function (e) {
  108. e = e || {};
  109. for (var t in e) o[t] = e[t];
  110. return this
  111. }, n.prototype.modules = function () {
  112. var e = {};
  113. for (var t in u) e[t] = u[t];
  114. return e
  115. }(), n.prototype.extend = function (e) {
  116. var t = this;
  117. e = e || {};
  118. for (var o in e) t[o] || t.modules[o] ? i("模块名 " + o + " 已被占用") : t.modules[o] = e[o];
  119. return t
  120. }, n.prototype.router = function (e) {
  121. var t = this, e = e || location.hash, o = {path: [], search: {}, hash: (e.match(/[^#](#.*$)/) || [])[1] || ""};
  122. return /^#\//.test(e) ? (e = e.replace(/^#\//, ""), o.href = "/" + e, e = e.replace(/([^#])(#.*$)/, "$1").split("/") || [], t.each(e, function (e, t) {
  123. /^\w+=/.test(t) ? function () {
  124. t = t.split("="), o.search[t[0]] = t[1]
  125. }() : o.path.push(t)
  126. }), o) : o
  127. }, n.prototype.data = function (t, o, n) {
  128. if (t = t || "layui", n = n || localStorage, e.JSON && e.JSON.parse) {
  129. if (null === o) return delete n[t];
  130. o = "object" == typeof o ? o : {key: o};
  131. try {
  132. var r = JSON.parse(n[t])
  133. } catch (i) {
  134. var r = {}
  135. }
  136. return "value" in o && (r[o.key] = o.value), o.remove && delete r[o.key], n[t] = JSON.stringify(r), o.key ? r[o.key] : r
  137. }
  138. }, n.prototype.sessionData = function (e, t) {
  139. return this.data(e, t, sessionStorage)
  140. }, n.prototype.device = function (t) {
  141. var o = navigator.userAgent.toLowerCase(), n = function (e) {
  142. var t = new RegExp(e + "/([^\\s\\_\\-]+)");
  143. return e = (o.match(t) || [])[1], e || !1
  144. }, r = {
  145. os: function () {
  146. return /windows/.test(o) ? "windows" : /linux/.test(o) ? "linux" : /iphone|ipod|ipad|ios/.test(o) ? "ios" : /mac/.test(o) ? "mac" : void 0
  147. }(), ie: function () {
  148. return !!(e.ActiveXObject || "ActiveXObject" in e) && ((o.match(/msie\s(\d+)/) || [])[1] || "11")
  149. }(), weixin: n("micromessenger")
  150. };
  151. return t && !r[t] && (r[t] = n(t)), r.android = /android/.test(o), r.ios = "ios" === r.os, r
  152. }, n.prototype.hint = function () {
  153. return {error: i}
  154. }, n.prototype.each = function (e, t) {
  155. var o, n = this;
  156. if ("function" != typeof t) return n;
  157. if (e = e || [], e.constructor === Object) {
  158. for (o in e) if (t.call(e[o], o, e[o])) break
  159. } else for (o = 0; o < e.length && !t.call(e[o], o, e[o]); o++) ;
  160. return n
  161. }, n.prototype.sort = function (e, t, o) {
  162. var n = JSON.parse(JSON.stringify(e || []));
  163. return t ? (n.sort(function (e, o) {
  164. var n = /^-?\d+$/, r = e[t], i = o[t];
  165. return n.test(r) && (r = parseFloat(r)), n.test(i) && (i = parseFloat(i)), r && !i ? 1 : !r && i ? -1 : r > i ? 1 : r < i ? -1 : 0
  166. }), o && n.reverse(), n) : n
  167. }, n.prototype.stope = function (t) {
  168. t = t || e.event;
  169. try {
  170. t.stopPropagation()
  171. } catch (o) {
  172. t.cancelBubble = !0
  173. }
  174. }, n.prototype.onevent = function (e, t, o) {
  175. return "string" != typeof e || "function" != typeof o ? this : n.event(e, t, null, o)
  176. }, n.prototype.event = n.event = function (e, t, n, r) {
  177. var i = this, a = null, u = t.match(/\((.*)\)$/) || [], l = (e + "." + t).replace(u[0], ""), s = u[1] || "",
  178. c = function (e, t) {
  179. var o = t && t.call(i, n);
  180. o === !1 && null === a && (a = !1)
  181. };
  182. return r ? (o.event[l] = o.event[l] || {}, o.event[l][s] = [r], this) : (layui.each(o.event[l], function (e, t) {
  183. return "{*}" === s ? void layui.each(t, c) : ("" === e && layui.each(t, c), void (s && e === s && layui.each(t, c)))
  184. }), a)
  185. }, e.layui = new n
  186. }(window);