layui.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /** layui-v2.5.4 MIT License By https://www.layui.com */
  2. !(function (e) {
  3. "use strict";
  4. var t = document,
  5. o = { modules: {}, status: {}, timeout: 10, event: {} },
  6. n = function () {
  7. this.v = "2.5.4";
  8. },
  9. r = (function () {
  10. var e = t.currentScript
  11. ? t.currentScript.src
  12. : (function () {
  13. for (var e, o = t.scripts, n = o.length - 1, r = n; r > 0; r--)
  14. if ("interactive" === o[r].readyState) {
  15. e = o[r].src;
  16. break;
  17. }
  18. return e || o[n].src;
  19. })();
  20. return e.substring(0, e.lastIndexOf("/") + 1);
  21. })(),
  22. i = function (t) {
  23. e.console && console.error && console.error("Layui hint: " + t);
  24. },
  25. a = "undefined" != typeof opera && "[object Opera]" === opera.toString(),
  26. u = {
  27. layer: "modules/layer",
  28. laydate: "modules/laydate",
  29. laypage: "modules/laypage",
  30. laytpl: "modules/laytpl",
  31. layim: "modules/layim",
  32. layedit: "modules/layedit",
  33. form: "modules/form",
  34. upload: "modules/upload",
  35. transfer: "modules/transfer",
  36. tree: "modules/tree",
  37. table: "modules/table",
  38. element: "modules/element",
  39. rate: "modules/rate",
  40. colorpicker: "modules/colorpicker",
  41. slider: "modules/slider",
  42. carousel: "modules/carousel",
  43. flow: "modules/flow",
  44. util: "modules/util",
  45. code: "modules/code",
  46. jquery: "modules/jquery",
  47. mobile: "modules/mobile",
  48. "layui.all": "../layui.all"
  49. };
  50. (n.prototype.cache = o),
  51. (n.prototype.define = function (e, t) {
  52. var n = this,
  53. r = "function" == typeof e,
  54. i = function () {
  55. var e = function (e, t) {
  56. (layui[e] = t), (o.status[e] = !0);
  57. };
  58. return (
  59. "function" == typeof t &&
  60. t(function (n, r) {
  61. e(n, r),
  62. (o.callback[n] = function () {
  63. t(e);
  64. });
  65. }),
  66. this
  67. );
  68. };
  69. return (
  70. r && ((t = e), (e = [])),
  71. !layui["layui.all"] && layui["layui.mobile"]
  72. ? i.call(n)
  73. : (n.use(e, i), n)
  74. );
  75. }),
  76. (n.prototype.use = function (e, n, l) {
  77. function s(e, t) {
  78. var n =
  79. "PLaySTATION 3" === navigator.platform
  80. ? /^complete$/
  81. : /^(complete|loaded)$/;
  82. ("load" === e.type ||
  83. n.test((e.currentTarget || e.srcElement).readyState)) &&
  84. ((o.modules[f] = t),
  85. d.removeChild(v),
  86. (function r() {
  87. return ++m > (1e3 * o.timeout) / 4
  88. ? i(f + " is not a valid module")
  89. : void (o.status[f] ? c() : setTimeout(r, 4));
  90. })());
  91. }
  92. function c() {
  93. l.push(layui[f]),
  94. e.length > 1
  95. ? y.use(e.slice(1), n, l)
  96. : "function" == typeof n && n.apply(layui, l);
  97. }
  98. var y = this,
  99. p = (o.dir = o.dir ? o.dir : r),
  100. d = t.getElementsByTagName("head")[0];
  101. (e = "string" == typeof e ? [e] : e),
  102. window.jQuery &&
  103. jQuery.fn.on &&
  104. (y.each(e, function (t, o) {
  105. "jquery" === o && e.splice(t, 1);
  106. }),
  107. (layui.jquery = layui.$ = jQuery));
  108. var f = e[0],
  109. m = 0;
  110. if (
  111. ((l = l || []),
  112. (o.host =
  113. o.host ||
  114. (p.match(/\/\/([\s\S]+?)\//) || ["//" + location.host + "/"])[0]),
  115. 0 === e.length ||
  116. (layui["layui.all"] && u[f]) ||
  117. (!layui["layui.all"] && layui["layui.mobile"] && u[f]))
  118. )
  119. return c(), y;
  120. if (o.modules[f])
  121. !(function g() {
  122. return ++m > (1e3 * o.timeout) / 4
  123. ? i(f + " is not a valid module")
  124. : void ("string" == typeof o.modules[f] && o.status[f]
  125. ? c()
  126. : setTimeout(g, 4));
  127. })();
  128. else {
  129. var v = t.createElement("script"),
  130. h =
  131. (u[f]
  132. ? p + "lay/"
  133. : /^\{\/\}/.test(y.modules[f])
  134. ? ""
  135. : o.base || "") +
  136. (y.modules[f] || f) +
  137. ".js";
  138. (h = h.replace(/^\{\/\}/, "")),
  139. (v.async = !0),
  140. (v.charset = "utf-8"),
  141. (v.src =
  142. h +
  143. (function () {
  144. var e =
  145. o.version === !0
  146. ? o.v || new Date().getTime()
  147. : o.version || "";
  148. return e ? "?v=" + e : "";
  149. })()),
  150. d.appendChild(v),
  151. !v.attachEvent ||
  152. (v.attachEvent.toString &&
  153. v.attachEvent.toString().indexOf("[native code") < 0) ||
  154. a
  155. ? v.addEventListener(
  156. "load",
  157. function (e) {
  158. s(e, h);
  159. },
  160. !1
  161. )
  162. : v.attachEvent("onreadystatechange", function (e) {
  163. s(e, h);
  164. }),
  165. (o.modules[f] = h);
  166. }
  167. return y;
  168. }),
  169. (n.prototype.getStyle = function (t, o) {
  170. var n = t.currentStyle ? t.currentStyle : e.getComputedStyle(t, null);
  171. return n[n.getPropertyValue ? "getPropertyValue" : "getAttribute"](o);
  172. }),
  173. (n.prototype.link = function (e, n, r) {
  174. var a = this,
  175. u = t.createElement("link"),
  176. l = t.getElementsByTagName("head")[0];
  177. "string" == typeof n && (r = n);
  178. var s = (r || e).replace(/\.|\//g, ""),
  179. c = (u.id = "layuicss-" + s),
  180. y = 0;
  181. return (
  182. (u.rel = "stylesheet"),
  183. (u.href = e + (o.debug ? "?v=" + new Date().getTime() : "")),
  184. (u.media = "all"),
  185. t.getElementById(c) || l.appendChild(u),
  186. "function" != typeof n
  187. ? a
  188. : ((function p() {
  189. return ++y > (1e3 * o.timeout) / 100
  190. ? i(e + " timeout")
  191. : void (1989 ===
  192. parseInt(a.getStyle(t.getElementById(c), "width"))
  193. ? (function () {
  194. n();
  195. })()
  196. : setTimeout(p, 100));
  197. })(),
  198. a)
  199. );
  200. }),
  201. (o.callback = {}),
  202. (n.prototype.factory = function (e) {
  203. if (layui[e])
  204. return "function" == typeof o.callback[e] ? o.callback[e] : null;
  205. }),
  206. (n.prototype.addcss = function (e, t, n) {
  207. return layui.link(o.dir + "css/" + e, t, n);
  208. }),
  209. (n.prototype.img = function (e, t, o) {
  210. var n = new Image();
  211. return (
  212. (n.src = e),
  213. n.complete
  214. ? t(n)
  215. : ((n.onload = function () {
  216. (n.onload = null), "function" == typeof t && t(n);
  217. }),
  218. void (n.onerror = function (e) {
  219. (n.onerror = null), "function" == typeof o && o(e);
  220. }))
  221. );
  222. }),
  223. (n.prototype.config = function (e) {
  224. e = e || {};
  225. for (var t in e) o[t] = e[t];
  226. return this;
  227. }),
  228. (n.prototype.modules = (function () {
  229. var e = {};
  230. for (var t in u) e[t] = u[t];
  231. return e;
  232. })()),
  233. (n.prototype.extend = function (e) {
  234. var t = this;
  235. e = e || {};
  236. for (var o in e)
  237. t[o] || t.modules[o]
  238. ? i("模块名 " + o + " 已被占用")
  239. : (t.modules[o] = e[o]);
  240. return t;
  241. }),
  242. (n.prototype.router = function (e) {
  243. var t = this,
  244. e = e || location.hash,
  245. o = {
  246. path: [],
  247. search: {},
  248. hash: (e.match(/[^#](#.*$)/) || [])[1] || ""
  249. };
  250. return /^#\//.test(e)
  251. ? ((e = e.replace(/^#\//, "")),
  252. (o.href = "/" + e),
  253. (e = e.replace(/([^#])(#.*$)/, "$1").split("/") || []),
  254. t.each(e, function (e, t) {
  255. /^\w+=/.test(t)
  256. ? (function () {
  257. (t = t.split("=")), (o.search[t[0]] = t[1]);
  258. })()
  259. : o.path.push(t);
  260. }),
  261. o)
  262. : o;
  263. }),
  264. (n.prototype.data = function (t, o, n) {
  265. if (
  266. ((t = t || "layui"), (n = n || localStorage), e.JSON && e.JSON.parse)
  267. ) {
  268. if (null === o) return delete n[t];
  269. o = "object" == typeof o ? o : { key: o };
  270. try {
  271. var r = JSON.parse(n[t]);
  272. } catch (i) {
  273. var r = {};
  274. }
  275. return (
  276. "value" in o && (r[o.key] = o.value),
  277. o.remove && delete r[o.key],
  278. (n[t] = JSON.stringify(r)),
  279. o.key ? r[o.key] : r
  280. );
  281. }
  282. }),
  283. (n.prototype.sessionData = function (e, t) {
  284. return this.data(e, t, sessionStorage);
  285. }),
  286. (n.prototype.device = function (t) {
  287. var o = navigator.userAgent.toLowerCase(),
  288. n = function (e) {
  289. var t = new RegExp(e + "/([^\\s\\_\\-]+)");
  290. return (e = (o.match(t) || [])[1]), e || !1;
  291. },
  292. r = {
  293. os: (function () {
  294. return /windows/.test(o)
  295. ? "windows"
  296. : /linux/.test(o)
  297. ? "linux"
  298. : /iphone|ipod|ipad|ios/.test(o)
  299. ? "ios"
  300. : /mac/.test(o)
  301. ? "mac"
  302. : void 0;
  303. })(),
  304. ie: (function () {
  305. return (
  306. !!(e.ActiveXObject || "ActiveXObject" in e) &&
  307. ((o.match(/msie\s(\d+)/) || [])[1] || "11")
  308. );
  309. })(),
  310. weixin: n("micromessenger")
  311. };
  312. return (
  313. t && !r[t] && (r[t] = n(t)),
  314. (r.android = /android/.test(o)),
  315. (r.ios = "ios" === r.os),
  316. r
  317. );
  318. }),
  319. (n.prototype.hint = function () {
  320. return { error: i };
  321. }),
  322. (n.prototype.each = function (e, t) {
  323. var o,
  324. n = this;
  325. if ("function" != typeof t) return n;
  326. if (((e = e || []), e.constructor === Object)) {
  327. for (o in e) if (t.call(e[o], o, e[o])) break;
  328. } else for (o = 0; o < e.length && !t.call(e[o], o, e[o]); o++);
  329. return n;
  330. }),
  331. (n.prototype.sort = function (e, t, o) {
  332. var n = JSON.parse(JSON.stringify(e || []));
  333. return t
  334. ? (n.sort(function (e, o) {
  335. var n = /^-?\d+$/,
  336. r = e[t],
  337. i = o[t];
  338. return (
  339. n.test(r) && (r = parseFloat(r)),
  340. n.test(i) && (i = parseFloat(i)),
  341. r && !i ? 1 : !r && i ? -1 : r > i ? 1 : r < i ? -1 : 0
  342. );
  343. }),
  344. o && n.reverse(),
  345. n)
  346. : n;
  347. }),
  348. (n.prototype.stope = function (t) {
  349. t = t || e.event;
  350. try {
  351. t.stopPropagation();
  352. } catch (o) {
  353. t.cancelBubble = !0;
  354. }
  355. }),
  356. (n.prototype.onevent = function (e, t, o) {
  357. return "string" != typeof e || "function" != typeof o
  358. ? this
  359. : n.event(e, t, null, o);
  360. }),
  361. (n.prototype.event = n.event =
  362. function (e, t, n, r) {
  363. var i = this,
  364. a = null,
  365. u = t.match(/\((.*)\)$/) || [],
  366. l = (e + "." + t).replace(u[0], ""),
  367. s = u[1] || "",
  368. c = function (e, t) {
  369. var o = t && t.call(i, n);
  370. o === !1 && null === a && (a = !1);
  371. };
  372. return r
  373. ? ((o.event[l] = o.event[l] || {}), (o.event[l][s] = [r]), this)
  374. : (layui.each(o.event[l], function (e, t) {
  375. return "{*}" === s
  376. ? void layui.each(t, c)
  377. : ("" === e && layui.each(t, c),
  378. void (s && e === s && layui.each(t, c)));
  379. }),
  380. a);
  381. }),
  382. (e.layui = new n());
  383. })(window);