laydate.dev.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. !function () {
  6. "use strict";
  7. var e = window.layui && layui.define,
  8. t = {
  9. getPath: function () {
  10. var e = document.currentScript ? document.currentScript.src : function () {
  11. for (var e, t = document.scripts, n = t.length - 1, a = n; a > 0; a--) {
  12. if ("interactive" === t[a].readyState) {
  13. e = t[a].src;
  14. break;
  15. }
  16. }
  17. return e || t[n].src;
  18. }();
  19. return e.substring(0, e.lastIndexOf("/") + 1);
  20. }(),
  21. getStyle: function getStyle(e, t) {
  22. var n = e.currentStyle ? e.currentStyle : window.getComputedStyle(e, null);
  23. return n[n.getPropertyValue ? "getPropertyValue" : "getAttribute"](t);
  24. },
  25. link: function link(e, a, i) {
  26. if (n.path) {
  27. var r = document.getElementsByTagName("head")[0],
  28. o = document.createElement("link");
  29. "string" == typeof a && (i = a);
  30. var s = (i || e).replace(/\.|\//g, ""),
  31. l = "layuicss-" + s,
  32. d = 0;
  33. o.rel = "stylesheet", o.href = n.path + e, o.id = l, document.getElementById(l) || r.appendChild(o), "function" == typeof a && !function c() {
  34. return ++d > 80 ? window.console && console.error("laydate.css: Invalid") : void (1989 === parseInt(t.getStyle(document.getElementById(l), "width")) ? a() : setTimeout(c, 100));
  35. }();
  36. }
  37. }
  38. },
  39. n = {
  40. v: "5.0.9",
  41. config: {},
  42. index: window.laydate && window.laydate.v ? 1e5 : 0,
  43. path: t.getPath,
  44. set: function set(e) {
  45. var t = this;
  46. return t.config = w.extend({}, t.config, e), t;
  47. },
  48. ready: function ready(a) {
  49. var i = "laydate",
  50. r = "",
  51. o = (e ? "modules/laydate/" : "theme/") + "default/laydate.css?v=" + n.v + r;
  52. return e ? layui.addcss(o, a, i) : t.link(o, a, i), this;
  53. }
  54. },
  55. a = function a() {
  56. var e = this;
  57. return {
  58. hint: function hint(t) {
  59. e.hint.call(e, t);
  60. },
  61. config: e.config
  62. };
  63. },
  64. i = "laydate",
  65. r = ".layui-laydate",
  66. o = "layui-this",
  67. s = "laydate-disabled",
  68. l = "开始日期超出了结束日期<br>建议重新选择",
  69. d = [100, 2e5],
  70. c = "layui-laydate-static",
  71. m = "layui-laydate-list",
  72. u = "laydate-selected",
  73. h = "layui-laydate-hint",
  74. y = "laydate-day-prev",
  75. f = "laydate-day-next",
  76. p = "layui-laydate-footer",
  77. g = ".laydate-btns-confirm",
  78. v = "laydate-time-text",
  79. D = ".laydate-btns-time",
  80. T = function T(e) {
  81. var t = this;
  82. t.index = ++n.index, t.config = w.extend({}, t.config, n.config, e), n.ready(function () {
  83. t.init();
  84. });
  85. },
  86. w = function w(e) {
  87. return new C(e);
  88. },
  89. C = function C(e) {
  90. for (var t = 0, n = "object" == _typeof(e) ? [e] : (this.selector = e, document.querySelectorAll(e || null)); t < n.length; t++) {
  91. this.push(n[t]);
  92. }
  93. };
  94. C.prototype = [], C.prototype.constructor = C, w.extend = function () {
  95. var e = 1,
  96. t = arguments,
  97. n = function n(e, t) {
  98. e = e || (t.constructor === Array ? [] : {});
  99. for (var a in t) {
  100. e[a] = t[a] && t[a].constructor === Object ? n(e[a], t[a]) : t[a];
  101. }
  102. return e;
  103. };
  104. for (t[0] = "object" == _typeof(t[0]) ? t[0] : {}; e < t.length; e++) {
  105. "object" == _typeof(t[e]) && n(t[0], t[e]);
  106. }
  107. return t[0];
  108. }, w.ie = function () {
  109. var e = navigator.userAgent.toLowerCase();
  110. return !!(window.ActiveXObject || "ActiveXObject" in window) && ((e.match(/msie\s(\d+)/) || [])[1] || "11");
  111. }(), w.stope = function (e) {
  112. e = e || window.event, e.stopPropagation ? e.stopPropagation() : e.cancelBubble = !0;
  113. }, w.each = function (e, t) {
  114. var n,
  115. a = this;
  116. if ("function" != typeof t) return a;
  117. if (e = e || [], e.constructor === Object) {
  118. for (n in e) {
  119. if (t.call(e[n], n, e[n])) break;
  120. }
  121. } else for (n = 0; n < e.length && !t.call(e[n], n, e[n]); n++) {
  122. ;
  123. }
  124. return a;
  125. }, w.digit = function (e, t, n) {
  126. var a = "";
  127. e = String(e), t = t || 2;
  128. for (var i = e.length; i < t; i++) {
  129. a += "0";
  130. }
  131. return e < Math.pow(10, t) ? a + (0 | e) : e;
  132. }, w.elem = function (e, t) {
  133. var n = document.createElement(e);
  134. return w.each(t || {}, function (e, t) {
  135. n.setAttribute(e, t);
  136. }), n;
  137. }, C.addStr = function (e, t) {
  138. return e = e.replace(/\s+/, " "), t = t.replace(/\s+/, " ").split(" "), w.each(t, function (t, n) {
  139. new RegExp("\\b" + n + "\\b").test(e) || (e = e + " " + n);
  140. }), e.replace(/^\s|\s$/, "");
  141. }, C.removeStr = function (e, t) {
  142. return e = e.replace(/\s+/, " "), t = t.replace(/\s+/, " ").split(" "), w.each(t, function (t, n) {
  143. var a = new RegExp("\\b" + n + "\\b");
  144. a.test(e) && (e = e.replace(a, ""));
  145. }), e.replace(/\s+/, " ").replace(/^\s|\s$/, "");
  146. }, C.prototype.find = function (e) {
  147. var t = this,
  148. n = 0,
  149. a = [],
  150. i = "object" == _typeof(e);
  151. return this.each(function (r, o) {
  152. for (var s = i ? [e] : o.querySelectorAll(e || null); n < s.length; n++) {
  153. a.push(s[n]);
  154. }
  155. t.shift();
  156. }), i || (t.selector = (t.selector ? t.selector + " " : "") + e), w.each(a, function (e, n) {
  157. t.push(n);
  158. }), t;
  159. }, C.prototype.each = function (e) {
  160. return w.each.call(this, this, e);
  161. }, C.prototype.addClass = function (e, t) {
  162. return this.each(function (n, a) {
  163. a.className = C[t ? "removeStr" : "addStr"](a.className, e);
  164. });
  165. }, C.prototype.removeClass = function (e) {
  166. return this.addClass(e, !0);
  167. }, C.prototype.hasClass = function (e) {
  168. var t = !1;
  169. return this.each(function (n, a) {
  170. new RegExp("\\b" + e + "\\b").test(a.className) && (t = !0);
  171. }), t;
  172. }, C.prototype.attr = function (e, t) {
  173. var n = this;
  174. return void 0 === t ? function () {
  175. if (n.length > 0) return n[0].getAttribute(e);
  176. }() : n.each(function (n, a) {
  177. a.setAttribute(e, t);
  178. });
  179. }, C.prototype.removeAttr = function (e) {
  180. return this.each(function (t, n) {
  181. n.removeAttribute(e);
  182. });
  183. }, C.prototype.html = function (e) {
  184. return this.each(function (t, n) {
  185. n.innerHTML = e;
  186. });
  187. }, C.prototype.val = function (e) {
  188. return this.each(function (t, n) {
  189. n.value = e;
  190. });
  191. }, C.prototype.append = function (e) {
  192. return this.each(function (t, n) {
  193. "object" == _typeof(e) ? n.appendChild(e) : n.innerHTML = n.innerHTML + e;
  194. });
  195. }, C.prototype.remove = function (e) {
  196. return this.each(function (t, n) {
  197. e ? n.removeChild(e) : n.parentNode.removeChild(n);
  198. });
  199. }, C.prototype.on = function (e, t) {
  200. return this.each(function (n, a) {
  201. a.attachEvent ? a.attachEvent("on" + e, function (e) {
  202. e.target = e.srcElement, t.call(a, e);
  203. }) : a.addEventListener(e, t, !1);
  204. });
  205. }, C.prototype.off = function (e, t) {
  206. return this.each(function (n, a) {
  207. a.detachEvent ? a.detachEvent("on" + e, t) : a.removeEventListener(e, t, !1);
  208. });
  209. }, T.isLeapYear = function (e) {
  210. return e % 4 === 0 && e % 100 !== 0 || e % 400 === 0;
  211. }, T.prototype.config = {
  212. type: "date",
  213. range: !1,
  214. format: "yyyy-MM-dd",
  215. value: null,
  216. isInitValue: !0,
  217. min: "1900-1-1",
  218. max: "2099-12-31",
  219. trigger: "focus",
  220. show: !1,
  221. showBottom: !0,
  222. btns: ["clear", "now", "confirm"],
  223. lang: "cn",
  224. theme: "default",
  225. position: null,
  226. calendar: !1,
  227. mark: {},
  228. zIndex: null,
  229. done: null,
  230. change: null
  231. }, T.prototype.lang = function () {
  232. var e = this,
  233. t = e.config,
  234. n = {
  235. cn: {
  236. weeks: ["日", "一", "二", "三", "四", "五", "六"],
  237. time: ["时", "分", "秒"],
  238. timeTips: "选择时间",
  239. startTime: "开始时间",
  240. endTime: "结束时间",
  241. dateTips: "返回日期",
  242. month: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"],
  243. tools: {
  244. confirm: "确定",
  245. clear: "清空",
  246. now: "现在"
  247. }
  248. },
  249. en: {
  250. weeks: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
  251. time: ["Hours", "Minutes", "Seconds"],
  252. timeTips: "Select Time",
  253. startTime: "Start Time",
  254. endTime: "End Time",
  255. dateTips: "Select Date",
  256. month: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  257. tools: {
  258. confirm: "Confirm",
  259. clear: "Clear",
  260. now: "Now"
  261. }
  262. }
  263. };
  264. return n[t.lang] || n.cn;
  265. }, T.prototype.init = function () {
  266. var e = this,
  267. t = e.config,
  268. n = "yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s",
  269. a = "static" === t.position,
  270. i = {
  271. year: "yyyy",
  272. month: "yyyy-MM",
  273. date: "yyyy-MM-dd",
  274. time: "HH:mm:ss",
  275. datetime: "yyyy-MM-dd HH:mm:ss"
  276. };
  277. t.elem = w(t.elem), t.eventElem = w(t.eventElem), t.elem[0] && (t.range === !0 && (t.range = "-"), t.format === i.date && (t.format = i[t.type]), e.format = t.format.match(new RegExp(n + "|.", "g")) || [], e.EXP_IF = "", e.EXP_SPLIT = "", w.each(e.format, function (t, a) {
  278. var i = new RegExp(n).test(a) ? "\\d{" + function () {
  279. return new RegExp(n).test(e.format[0 === t ? t + 1 : t - 1] || "") ? /^yyyy|y$/.test(a) ? 4 : a.length : /^yyyy$/.test(a) ? "1,4" : /^y$/.test(a) ? "1,308" : "1,2";
  280. }() + "}" : "\\" + a;
  281. e.EXP_IF = e.EXP_IF + i, e.EXP_SPLIT = e.EXP_SPLIT + "(" + i + ")";
  282. }), e.EXP_IF = new RegExp("^" + (t.range ? e.EXP_IF + "\\s\\" + t.range + "\\s" + e.EXP_IF : e.EXP_IF) + "$"), e.EXP_SPLIT = new RegExp("^" + e.EXP_SPLIT + "$", ""), e.isInput(t.elem[0]) || "focus" === t.trigger && (t.trigger = "click"), t.elem.attr("lay-key") || (t.elem.attr("lay-key", e.index), t.eventElem.attr("lay-key", e.index)), t.mark = w.extend({}, t.calendar && "cn" === t.lang ? {
  283. "0-1-1": "元旦",
  284. "0-2-14": "情人",
  285. "0-3-8": "妇女",
  286. "0-3-12": "植树",
  287. "0-4-1": "愚人",
  288. "0-5-1": "劳动",
  289. "0-5-4": "青年",
  290. "0-6-1": "儿童",
  291. "0-9-10": "教师",
  292. "0-9-18": "国耻",
  293. "0-10-1": "国庆",
  294. "0-12-25": "圣诞"
  295. } : {}, t.mark), w.each(["min", "max"], function (e, n) {
  296. var a = [],
  297. i = [];
  298. if ("number" == typeof t[n]) {
  299. var r = t[n],
  300. o = new Date().getTime(),
  301. s = 864e5,
  302. l = new Date(r ? r < s ? o + r * s : r : o);
  303. a = [l.getFullYear(), l.getMonth() + 1, l.getDate()], r < s || (i = [l.getHours(), l.getMinutes(), l.getSeconds()]);
  304. } else a = (t[n].match(/\d+-\d+-\d+/) || [""])[0].split("-"), i = (t[n].match(/\d+:\d+:\d+/) || [""])[0].split(":");
  305. t[n] = {
  306. year: 0 | a[0] || new Date().getFullYear(),
  307. month: a[1] ? (0 | a[1]) - 1 : new Date().getMonth(),
  308. date: 0 | a[2] || new Date().getDate(),
  309. hours: 0 | i[0],
  310. minutes: 0 | i[1],
  311. seconds: 0 | i[2]
  312. };
  313. }), e.elemID = "layui-laydate" + t.elem.attr("lay-key"), (t.show || a) && e.render(), a || e.events(), t.value && t.isInitValue && (t.value.constructor === Date ? e.setValue(e.parse(0, e.systemDate(t.value))) : e.setValue(t.value)));
  314. }, T.prototype.render = function () {
  315. var e = this,
  316. t = e.config,
  317. n = e.lang(),
  318. a = "static" === t.position,
  319. i = e.elem = w.elem("div", {
  320. id: e.elemID,
  321. "class": ["layui-laydate", t.range ? " layui-laydate-range" : "", a ? " " + c : "", t.theme && "default" !== t.theme && !/^#/.test(t.theme) ? " laydate-theme-" + t.theme : ""].join("")
  322. }),
  323. r = e.elemMain = [],
  324. o = e.elemHeader = [],
  325. s = e.elemCont = [],
  326. l = e.table = [],
  327. d = e.footer = w.elem("div", {
  328. "class": p
  329. });
  330. if (t.zIndex && (i.style.zIndex = t.zIndex), w.each(new Array(2), function (e) {
  331. if (!t.range && e > 0) return !0;
  332. var a = w.elem("div", {
  333. "class": "layui-laydate-header"
  334. }),
  335. i = [function () {
  336. var e = w.elem("i", {
  337. "class": "layui-icon laydate-icon laydate-prev-y"
  338. });
  339. return e.innerHTML = "&#xe65a;", e;
  340. }(), function () {
  341. var e = w.elem("i", {
  342. "class": "layui-icon laydate-icon laydate-prev-m"
  343. });
  344. return e.innerHTML = "&#xe603;", e;
  345. }(), function () {
  346. var e = w.elem("div", {
  347. "class": "laydate-set-ym"
  348. }),
  349. t = w.elem("span"),
  350. n = w.elem("span");
  351. return e.appendChild(t), e.appendChild(n), e;
  352. }(), function () {
  353. var e = w.elem("i", {
  354. "class": "layui-icon laydate-icon laydate-next-m"
  355. });
  356. return e.innerHTML = "&#xe602;", e;
  357. }(), function () {
  358. var e = w.elem("i", {
  359. "class": "layui-icon laydate-icon laydate-next-y"
  360. });
  361. return e.innerHTML = "&#xe65b;", e;
  362. }()],
  363. d = w.elem("div", {
  364. "class": "layui-laydate-content"
  365. }),
  366. c = w.elem("table"),
  367. m = w.elem("thead"),
  368. u = w.elem("tr");
  369. w.each(i, function (e, t) {
  370. a.appendChild(t);
  371. }), m.appendChild(u), w.each(new Array(6), function (e) {
  372. var t = c.insertRow(0);
  373. w.each(new Array(7), function (a) {
  374. if (0 === e) {
  375. var i = w.elem("th");
  376. i.innerHTML = n.weeks[a], u.appendChild(i);
  377. }
  378. t.insertCell(a);
  379. });
  380. }), c.insertBefore(m, c.children[0]), d.appendChild(c), r[e] = w.elem("div", {
  381. "class": "layui-laydate-main laydate-main-list-" + e
  382. }), r[e].appendChild(a), r[e].appendChild(d), o.push(i), s.push(d), l.push(c);
  383. }), w(d).html(function () {
  384. var e = [],
  385. i = [];
  386. return "datetime" === t.type && e.push('<span lay-type="datetime" class="laydate-btns-time">' + n.timeTips + "</span>"), w.each(t.btns, function (e, r) {
  387. var o = n.tools[r] || "btn";
  388. t.range && "now" === r || (a && "clear" === r && (o = "cn" === t.lang ? "重置" : "Reset"), i.push('<span lay-type="' + r + '" class="laydate-btns-' + r + '">' + o + "</span>"));
  389. }), e.push('<div class="laydate-footer-btns">' + i.join("") + "</div>"), e.join("");
  390. }()), w.each(r, function (e, t) {
  391. i.appendChild(t);
  392. }), t.showBottom && i.appendChild(d), /^#/.test(t.theme)) {
  393. var m = w.elem("style"),
  394. u = ["#{{id}} .layui-laydate-header{background-color:{{theme}};}", "#{{id}} .layui-this{background-color:{{theme}} !important;}"].join("").replace(/{{id}}/g, e.elemID).replace(/{{theme}}/g, t.theme);
  395. "styleSheet" in m ? (m.setAttribute("type", "text/css"), m.styleSheet.cssText = u) : m.innerHTML = u, w(i).addClass("laydate-theme-molv"), i.appendChild(m);
  396. }
  397. e.remove(T.thisElemDate), a ? t.elem.append(i) : (document.body.appendChild(i), e.position()), e.checkDate().calendar(), e.changeEvent(), T.thisElemDate = e.elemID, "function" == typeof t.ready && t.ready(w.extend({}, t.dateTime, {
  398. month: t.dateTime.month + 1
  399. }));
  400. }, T.prototype.remove = function (e) {
  401. var t = this,
  402. n = (t.config, w("#" + (e || t.elemID)));
  403. return n.hasClass(c) || t.checkDate(function () {
  404. n.remove();
  405. }), t;
  406. }, T.prototype.position = function () {
  407. var e = this,
  408. t = e.config,
  409. n = e.bindElem || t.elem[0],
  410. a = n.getBoundingClientRect(),
  411. i = e.elem.offsetWidth,
  412. r = e.elem.offsetHeight,
  413. o = function o(e) {
  414. return e = e ? "scrollLeft" : "scrollTop", document.body[e] | document.documentElement[e];
  415. },
  416. s = function s(e) {
  417. return document.documentElement[e ? "clientWidth" : "clientHeight"];
  418. },
  419. l = 5,
  420. d = a.left,
  421. c = a.bottom;
  422. d + i + l > s("width") && (d = s("width") - i - l), c + r + l > s() && (c = a.top > r ? a.top - r : s() - r, c -= 2 * l), t.position && (e.elem.style.position = t.position), e.elem.style.left = d + ("fixed" === t.position ? 0 : o(1)) + "px", e.elem.style.top = c + ("fixed" === t.position ? 0 : o()) + "px";
  423. }, T.prototype.hint = function (e) {
  424. var t = this,
  425. n = (t.config, w.elem("div", {
  426. "class": h
  427. }));
  428. t.elem && (n.innerHTML = e || "", w(t.elem).find("." + h).remove(), t.elem.appendChild(n), clearTimeout(t.hinTimer), t.hinTimer = setTimeout(function () {
  429. w(t.elem).find("." + h).remove();
  430. }, 3e3));
  431. }, T.prototype.getAsYM = function (e, t, n) {
  432. return n ? t-- : t++, t < 0 && (t = 11, e--), t > 11 && (t = 0, e++), [e, t];
  433. }, T.prototype.systemDate = function (e) {
  434. var t = e || new Date();
  435. return {
  436. year: t.getFullYear(),
  437. month: t.getMonth(),
  438. date: t.getDate(),
  439. hours: e ? e.getHours() : 0,
  440. minutes: e ? e.getMinutes() : 0,
  441. seconds: e ? e.getSeconds() : 0
  442. };
  443. }, T.prototype.checkDate = function (e) {
  444. var t,
  445. a,
  446. i = this,
  447. r = (new Date(), i.config),
  448. o = r.dateTime = r.dateTime || i.systemDate(),
  449. s = i.bindElem || r.elem[0],
  450. l = (i.isInput(s) ? "val" : "html", i.isInput(s) ? s.value : "static" === r.position ? "" : s.innerHTML),
  451. c = function c(e) {
  452. e.year > d[1] && (e.year = d[1], a = !0), e.month > 11 && (e.month = 11, a = !0), e.hours > 23 && (e.hours = 0, a = !0), e.minutes > 59 && (e.minutes = 0, e.hours++, a = !0), e.seconds > 59 && (e.seconds = 0, e.minutes++, a = !0), t = n.getEndDate(e.month + 1, e.year), e.date > t && (e.date = t, a = !0);
  453. },
  454. m = function m(e, t, n) {
  455. var o = ["startTime", "endTime"];
  456. t = (t.match(i.EXP_SPLIT) || []).slice(1), n = n || 0, r.range && (i[o[n]] = i[o[n]] || {}), w.each(i.format, function (s, l) {
  457. var c = parseFloat(t[s]);
  458. t[s].length < l.length && (a = !0), /yyyy|y/.test(l) ? (c < d[0] && (c = d[0], a = !0), e.year = c) : /MM|M/.test(l) ? (c < 1 && (c = 1, a = !0), e.month = c - 1) : /dd|d/.test(l) ? (c < 1 && (c = 1, a = !0), e.date = c) : /HH|H/.test(l) ? (c < 1 && (c = 0, a = !0), e.hours = c, r.range && (i[o[n]].hours = c)) : /mm|m/.test(l) ? (c < 1 && (c = 0, a = !0), e.minutes = c, r.range && (i[o[n]].minutes = c)) : /ss|s/.test(l) && (c < 1 && (c = 0, a = !0), e.seconds = c, r.range && (i[o[n]].seconds = c));
  459. }), c(e);
  460. };
  461. return "limit" === e ? (c(o), i) : (l = l || r.value, "string" == typeof l && (l = l.replace(/\s+/g, " ").replace(/^\s|\s$/g, "")), i.startState && !i.endState && (delete i.startState, i.endState = !0), "string" == typeof l && l ? i.EXP_IF.test(l) ? r.range ? (l = l.split(" " + r.range + " "), i.startDate = i.startDate || i.systemDate(), i.endDate = i.endDate || i.systemDate(), r.dateTime = w.extend({}, i.startDate), w.each([i.startDate, i.endDate], function (e, t) {
  462. m(t, l[e], e);
  463. })) : m(o, l) : (i.hint("日期格式不合法<br>必须遵循下述格式:<br>" + (r.range ? r.format + " " + r.range + " " + r.format : r.format) + "<br>已为你重置"), a = !0) : l && l.constructor === Date ? r.dateTime = i.systemDate(l) : (r.dateTime = i.systemDate(), delete i.startState, delete i.endState, delete i.startDate, delete i.endDate, delete i.startTime, delete i.endTime), c(o), a && l && i.setValue(r.range ? i.endDate ? i.parse() : "" : i.parse()), e && e(), i);
  464. }, T.prototype.mark = function (e, t) {
  465. var n,
  466. a = this,
  467. i = a.config;
  468. return w.each(i.mark, function (e, a) {
  469. var i = e.split("-");
  470. i[0] != t[0] && 0 != i[0] || i[1] != t[1] && 0 != i[1] || i[2] != t[2] || (n = a || t[2]);
  471. }), n && e.html('<span class="laydate-day-mark">' + n + "</span>"), a;
  472. }, T.prototype.limit = function (e, t, n, a) {
  473. var i,
  474. r = this,
  475. o = r.config,
  476. l = {},
  477. d = o[n > 41 ? "endDate" : "dateTime"],
  478. c = w.extend({}, d, t || {});
  479. return w.each({
  480. now: c,
  481. min: o.min,
  482. max: o.max
  483. }, function (e, t) {
  484. l[e] = r.newDate(w.extend({
  485. year: t.year,
  486. month: t.month,
  487. date: t.date
  488. }, function () {
  489. var e = {};
  490. return w.each(a, function (n, a) {
  491. e[a] = t[a];
  492. }), e;
  493. }())).getTime();
  494. }), i = l.now < l.min || l.now > l.max, e && e[i ? "addClass" : "removeClass"](s), i;
  495. }, T.prototype.calendar = function (e) {
  496. var t,
  497. a,
  498. i,
  499. r = this,
  500. s = r.config,
  501. l = e || s.dateTime,
  502. c = new Date(),
  503. m = r.lang(),
  504. u = "date" !== s.type && "datetime" !== s.type,
  505. h = e ? 1 : 0,
  506. y = w(r.table[h]).find("td"),
  507. f = w(r.elemHeader[h][2]).find("span");
  508. if (l.year < d[0] && (l.year = d[0], r.hint("最低只能支持到公元" + d[0] + "年")), l.year > d[1] && (l.year = d[1], r.hint("最高只能支持到公元" + d[1] + "年")), r.firstDate || (r.firstDate = w.extend({}, l)), c.setFullYear(l.year, l.month, 1), t = c.getDay(), a = n.getEndDate(l.month || 12, l.year), i = n.getEndDate(l.month + 1, l.year), w.each(y, function (e, n) {
  509. var d = [l.year, l.month],
  510. c = 0;
  511. n = w(n), n.removeAttr("class"), e < t ? (c = a - t + e, n.addClass("laydate-day-prev"), d = r.getAsYM(l.year, l.month, "sub")) : e >= t && e < i + t ? (c = e - t, s.range || c + 1 === l.date && n.addClass(o)) : (c = e - i - t, n.addClass("laydate-day-next"), d = r.getAsYM(l.year, l.month)), d[1]++, d[2] = c + 1, n.attr("lay-ymd", d.join("-")).html(d[2]), r.mark(n, d).limit(n, {
  512. year: d[0],
  513. month: d[1] - 1,
  514. date: d[2]
  515. }, e);
  516. }), w(f[0]).attr("lay-ym", l.year + "-" + (l.month + 1)), w(f[1]).attr("lay-ym", l.year + "-" + (l.month + 1)), "cn" === s.lang ? (w(f[0]).attr("lay-type", "year").html(l.year + "年"), w(f[1]).attr("lay-type", "month").html(l.month + 1 + "月")) : (w(f[0]).attr("lay-type", "month").html(m.month[l.month]), w(f[1]).attr("lay-type", "year").html(l.year)), u && (s.range && (e ? r.endDate = r.endDate || {
  517. year: l.year + ("year" === s.type ? 1 : 0),
  518. month: l.month + ("month" === s.type ? 0 : -1)
  519. } : r.startDate = r.startDate || {
  520. year: l.year,
  521. month: l.month
  522. }, e && (r.listYM = [[r.startDate.year, r.startDate.month + 1], [r.endDate.year, r.endDate.month + 1]], r.list(s.type, 0).list(s.type, 1), "time" === s.type ? r.setBtnStatus("时间", w.extend({}, r.systemDate(), r.startTime), w.extend({}, r.systemDate(), r.endTime)) : r.setBtnStatus(!0))), s.range || (r.listYM = [[l.year, l.month + 1]], r.list(s.type, 0))), s.range && !e) {
  523. var p = r.getAsYM(l.year, l.month);
  524. r.calendar(w.extend({}, l, {
  525. year: p[0],
  526. month: p[1]
  527. }));
  528. }
  529. return s.range || r.limit(w(r.footer).find(g), null, 0, ["hours", "minutes", "seconds"]), s.range && e && !u && r.stampRange(), r;
  530. }, T.prototype.list = function (e, t) {
  531. var n = this,
  532. a = n.config,
  533. i = a.dateTime,
  534. r = n.lang(),
  535. l = a.range && "date" !== a.type && "datetime" !== a.type,
  536. d = w.elem("ul", {
  537. "class": m + " " + {
  538. year: "laydate-year-list",
  539. month: "laydate-month-list",
  540. time: "laydate-time-list"
  541. }[e]
  542. }),
  543. c = n.elemHeader[t],
  544. u = w(c[2]).find("span"),
  545. h = n.elemCont[t || 0],
  546. y = w(h).find("." + m)[0],
  547. f = "cn" === a.lang,
  548. p = f ? "年" : "",
  549. T = n.listYM[t] || {},
  550. C = ["hours", "minutes", "seconds"],
  551. x = ["startTime", "endTime"][t];
  552. if (T[0] < 1 && (T[0] = 1), "year" === e) {
  553. var M,
  554. b = M = T[0] - 7;
  555. b < 1 && (b = M = 1), w.each(new Array(15), function (e) {
  556. var i = w.elem("li", {
  557. "lay-ym": M
  558. }),
  559. r = {
  560. year: M
  561. };
  562. M == T[0] && w(i).addClass(o), i.innerHTML = M + p, d.appendChild(i), M < n.firstDate.year ? (r.month = a.min.month, r.date = a.min.date) : M >= n.firstDate.year && (r.month = a.max.month, r.date = a.max.date), n.limit(w(i), r, t), M++;
  563. }), w(u[f ? 0 : 1]).attr("lay-ym", M - 8 + "-" + T[1]).html(b + p + " - " + (M - 1 + p));
  564. } else if ("month" === e) w.each(new Array(12), function (e) {
  565. var i = w.elem("li", {
  566. "lay-ym": e
  567. }),
  568. s = {
  569. year: T[0],
  570. month: e
  571. };
  572. e + 1 == T[1] && w(i).addClass(o), i.innerHTML = r.month[e] + (f ? "月" : ""), d.appendChild(i), T[0] < n.firstDate.year ? s.date = a.min.date : T[0] >= n.firstDate.year && (s.date = a.max.date), n.limit(w(i), s, t);
  573. }), w(u[f ? 0 : 1]).attr("lay-ym", T[0] + "-" + T[1]).html(T[0] + p);else if ("time" === e) {
  574. var E = function E() {
  575. w(d).find("ol").each(function (e, a) {
  576. w(a).find("li").each(function (a, i) {
  577. n.limit(w(i), [{
  578. hours: a
  579. }, {
  580. hours: n[x].hours,
  581. minutes: a
  582. }, {
  583. hours: n[x].hours,
  584. minutes: n[x].minutes,
  585. seconds: a
  586. }][e], t, [["hours"], ["hours", "minutes"], ["hours", "minutes", "seconds"]][e]);
  587. });
  588. }), a.range || n.limit(w(n.footer).find(g), n[x], 0, ["hours", "minutes", "seconds"]);
  589. };
  590. a.range ? n[x] || (n[x] = {
  591. hours: 0,
  592. minutes: 0,
  593. seconds: 0
  594. }) : n[x] = i, w.each([24, 60, 60], function (e, t) {
  595. var a = w.elem("li"),
  596. i = ["<p>" + r.time[e] + "</p><ol>"];
  597. w.each(new Array(t), function (t) {
  598. i.push("<li" + (n[x][C[e]] === t ? ' class="' + o + '"' : "") + ">" + w.digit(t, 2) + "</li>");
  599. }), a.innerHTML = i.join("") + "</ol>", d.appendChild(a);
  600. }), E();
  601. }
  602. if (y && h.removeChild(y), h.appendChild(d), "year" === e || "month" === e) w(n.elemMain[t]).addClass("laydate-ym-show"), w(d).find("li").on("click", function () {
  603. var r = 0 | w(this).attr("lay-ym");
  604. if (!w(this).hasClass(s)) {
  605. if (0 === t) i[e] = r, l && (n.startDate[e] = r), n.limit(w(n.footer).find(g), null, 0);else if (l) n.endDate[e] = r;else {
  606. var c = "year" === e ? n.getAsYM(r, T[1] - 1, "sub") : n.getAsYM(T[0], r, "sub");
  607. w.extend(i, {
  608. year: c[0],
  609. month: c[1]
  610. });
  611. }
  612. "year" === a.type || "month" === a.type ? (w(d).find("." + o).removeClass(o), w(this).addClass(o), "month" === a.type && "year" === e && (n.listYM[t][0] = r, l && (n[["startDate", "endDate"][t]].year = r), n.list("month", t))) : (n.checkDate("limit").calendar(), n.closeList()), n.setBtnStatus(), a.range || n.done(null, "change"), w(n.footer).find(D).removeClass(s);
  613. }
  614. });else {
  615. var S = w.elem("span", {
  616. "class": v
  617. }),
  618. k = function k() {
  619. w(d).find("ol").each(function (e) {
  620. var t = this,
  621. a = w(t).find("li");
  622. t.scrollTop = 30 * (n[x][C[e]] - 2), t.scrollTop <= 0 && a.each(function (e, n) {
  623. if (!w(this).hasClass(s)) return t.scrollTop = 30 * (e - 2), !0;
  624. });
  625. });
  626. },
  627. H = w(c[2]).find("." + v);
  628. k(), S.innerHTML = a.range ? [r.startTime, r.endTime][t] : r.timeTips, w(n.elemMain[t]).addClass("laydate-time-show"), H[0] && H.remove(), c[2].appendChild(S), w(d).find("ol").each(function (e) {
  629. var t = this;
  630. w(t).find("li").on("click", function () {
  631. var r = 0 | this.innerHTML;
  632. w(this).hasClass(s) || (a.range ? n[x][C[e]] = r : i[C[e]] = r, w(t).find("." + o).removeClass(o), w(this).addClass(o), E(), k(), (n.endDate || "time" === a.type) && n.done(null, "change"), n.setBtnStatus());
  633. });
  634. });
  635. }
  636. return n;
  637. }, T.prototype.listYM = [], T.prototype.closeList = function () {
  638. var e = this;
  639. e.config;
  640. w.each(e.elemCont, function (t, n) {
  641. w(this).find("." + m).remove(), w(e.elemMain[t]).removeClass("laydate-ym-show laydate-time-show");
  642. }), w(e.elem).find("." + v).remove();
  643. }, T.prototype.setBtnStatus = function (e, t, n) {
  644. var a,
  645. i = this,
  646. r = i.config,
  647. o = w(i.footer).find(g),
  648. d = r.range && "date" !== r.type && "time" !== r.type;
  649. d && (t = t || i.startDate, n = n || i.endDate, a = i.newDate(t).getTime() > i.newDate(n).getTime(), i.limit(null, t) || i.limit(null, n) ? o.addClass(s) : o[a ? "addClass" : "removeClass"](s), e && a && i.hint("string" == typeof e ? l.replace(/日期/g, e) : l));
  650. }, T.prototype.parse = function (e, t) {
  651. var n = this,
  652. a = n.config,
  653. i = t || (e ? w.extend({}, n.endDate, n.endTime) : a.range ? w.extend({}, n.startDate, n.startTime) : a.dateTime),
  654. r = n.format.concat();
  655. return w.each(r, function (e, t) {
  656. /yyyy|y/.test(t) ? r[e] = w.digit(i.year, t.length) : /MM|M/.test(t) ? r[e] = w.digit(i.month + 1, t.length) : /dd|d/.test(t) ? r[e] = w.digit(i.date, t.length) : /HH|H/.test(t) ? r[e] = w.digit(i.hours, t.length) : /mm|m/.test(t) ? r[e] = w.digit(i.minutes, t.length) : /ss|s/.test(t) && (r[e] = w.digit(i.seconds, t.length));
  657. }), a.range && !e ? r.join("") + " " + a.range + " " + n.parse(1) : r.join("");
  658. }, T.prototype.newDate = function (e) {
  659. return e = e || {}, new Date(e.year || 1, e.month || 0, e.date || 1, e.hours || 0, e.minutes || 0, e.seconds || 0);
  660. }, T.prototype.setValue = function (e) {
  661. var t = this,
  662. n = t.config,
  663. a = t.bindElem || n.elem[0],
  664. i = t.isInput(a) ? "val" : "html";
  665. return "static" === n.position || w(a)[i](e || ""), this;
  666. }, T.prototype.stampRange = function () {
  667. var e,
  668. t,
  669. n = this,
  670. a = n.config,
  671. i = w(n.elem).find("td");
  672. if (a.range && !n.endDate && w(n.footer).find(g).addClass(s), n.endDate) return e = n.newDate({
  673. year: n.startDate.year,
  674. month: n.startDate.month,
  675. date: n.startDate.date
  676. }).getTime(), t = n.newDate({
  677. year: n.endDate.year,
  678. month: n.endDate.month,
  679. date: n.endDate.date
  680. }).getTime(), e > t ? n.hint(l) : void w.each(i, function (a, i) {
  681. var r = w(i).attr("lay-ymd").split("-"),
  682. s = n.newDate({
  683. year: r[0],
  684. month: r[1] - 1,
  685. date: r[2]
  686. }).getTime();
  687. w(i).removeClass(u + " " + o), s !== e && s !== t || w(i).addClass(w(i).hasClass(y) || w(i).hasClass(f) ? u : o), s > e && s < t && w(i).addClass(u);
  688. });
  689. }, T.prototype.done = function (e, t) {
  690. var n = this,
  691. a = n.config,
  692. i = w.extend({}, n.startDate ? w.extend(n.startDate, n.startTime) : a.dateTime),
  693. r = w.extend({}, w.extend(n.endDate, n.endTime));
  694. return w.each([i, r], function (e, t) {
  695. "month" in t && w.extend(t, {
  696. month: t.month + 1
  697. });
  698. }), e = e || [n.parse(), i, r], "function" == typeof a[t || "done"] && a[t || "done"].apply(a, e), n;
  699. }, T.prototype.choose = function (e) {
  700. var t = this,
  701. n = t.config,
  702. a = n.dateTime,
  703. i = w(t.elem).find("td"),
  704. r = e.attr("lay-ymd").split("-"),
  705. l = function l(e) {
  706. new Date();
  707. e && w.extend(a, r), n.range && (t.startDate ? w.extend(t.startDate, r) : t.startDate = w.extend({}, r, t.startTime), t.startYMD = r);
  708. };
  709. if (r = {
  710. year: 0 | r[0],
  711. month: (0 | r[1]) - 1,
  712. date: 0 | r[2]
  713. }, !e.hasClass(s)) if (n.range) {
  714. if (w.each(["startTime", "endTime"], function (e, n) {
  715. t[n] = t[n] || {
  716. hours: 0,
  717. minutes: 0,
  718. seconds: 0
  719. };
  720. }), t.endState) l(), delete t.endState, delete t.endDate, t.startState = !0, i.removeClass(o + " " + u), e.addClass(o);else if (t.startState) {
  721. if (e.addClass(o), t.endDate ? w.extend(t.endDate, r) : t.endDate = w.extend({}, r, t.endTime), t.newDate(r).getTime() < t.newDate(t.startYMD).getTime()) {
  722. var d = w.extend({}, t.endDate, {
  723. hours: t.startDate.hours,
  724. minutes: t.startDate.minutes,
  725. seconds: t.startDate.seconds
  726. });
  727. w.extend(t.endDate, t.startDate, {
  728. hours: t.endDate.hours,
  729. minutes: t.endDate.minutes,
  730. seconds: t.endDate.seconds
  731. }), t.startDate = d;
  732. }
  733. n.showBottom || t.done(), t.stampRange(), t.endState = !0, t.done(null, "change");
  734. } else e.addClass(o), l(), t.startState = !0;
  735. w(t.footer).find(g)[t.endDate ? "removeClass" : "addClass"](s);
  736. } else "static" === n.position ? (l(!0), t.calendar().done().done(null, "change")) : "date" === n.type ? (l(!0), t.setValue(t.parse()).remove().done()) : "datetime" === n.type && (l(!0), t.calendar().done(null, "change"));
  737. }, T.prototype.tool = function (e, t) {
  738. var n = this,
  739. a = n.config,
  740. i = a.dateTime,
  741. r = "static" === a.position,
  742. o = {
  743. datetime: function datetime() {
  744. w(e).hasClass(s) || (n.list("time", 0), a.range && n.list("time", 1), w(e).attr("lay-type", "date").html(n.lang().dateTips));
  745. },
  746. date: function date() {
  747. n.closeList(), w(e).attr("lay-type", "datetime").html(n.lang().timeTips);
  748. },
  749. clear: function clear() {
  750. n.setValue("").remove(), r && (w.extend(i, n.firstDate), n.calendar()), a.range && (delete n.startState, delete n.endState, delete n.endDate, delete n.startTime, delete n.endTime), n.done(["", {}, {}]);
  751. },
  752. now: function now() {
  753. var e = new Date();
  754. w.extend(i, n.systemDate(), {
  755. hours: e.getHours(),
  756. minutes: e.getMinutes(),
  757. seconds: e.getSeconds()
  758. }), n.setValue(n.parse()).remove(), r && n.calendar(), n.done();
  759. },
  760. confirm: function confirm() {
  761. if (a.range) {
  762. if (!n.endDate) return n.hint("请先选择日期范围");
  763. if (w(e).hasClass(s)) return n.hint("time" === a.type ? l.replace(/日期/g, "时间") : l);
  764. } else if (w(e).hasClass(s)) return n.hint("不在有效日期或时间范围内");
  765. n.done(), n.setValue(n.parse()).remove();
  766. }
  767. };
  768. o[t] && o[t]();
  769. }, T.prototype.change = function (e) {
  770. var t = this,
  771. n = t.config,
  772. a = n.dateTime,
  773. i = n.range && ("year" === n.type || "month" === n.type),
  774. r = t.elemCont[e || 0],
  775. o = t.listYM[e],
  776. s = function s(_s) {
  777. var l = ["startDate", "endDate"][e],
  778. d = w(r).find(".laydate-year-list")[0],
  779. c = w(r).find(".laydate-month-list")[0];
  780. return d && (o[0] = _s ? o[0] - 15 : o[0] + 15, t.list("year", e)), c && (_s ? o[0]-- : o[0]++, t.list("month", e)), (d || c) && (w.extend(a, {
  781. year: o[0]
  782. }), i && (t[l].year = o[0]), n.range || t.done(null, "change"), t.setBtnStatus(), n.range || t.limit(w(t.footer).find(g), {
  783. year: o[0]
  784. })), d || c;
  785. };
  786. return {
  787. prevYear: function prevYear() {
  788. s("sub") || (a.year--, t.checkDate("limit").calendar(), n.range || t.done(null, "change"));
  789. },
  790. prevMonth: function prevMonth() {
  791. var e = t.getAsYM(a.year, a.month, "sub");
  792. w.extend(a, {
  793. year: e[0],
  794. month: e[1]
  795. }), t.checkDate("limit").calendar(), n.range || t.done(null, "change");
  796. },
  797. nextMonth: function nextMonth() {
  798. var e = t.getAsYM(a.year, a.month);
  799. w.extend(a, {
  800. year: e[0],
  801. month: e[1]
  802. }), t.checkDate("limit").calendar(), n.range || t.done(null, "change");
  803. },
  804. nextYear: function nextYear() {
  805. s() || (a.year++, t.checkDate("limit").calendar(), n.range || t.done(null, "change"));
  806. }
  807. };
  808. }, T.prototype.changeEvent = function () {
  809. var e = this;
  810. e.config;
  811. w(e.elem).on("click", function (e) {
  812. w.stope(e);
  813. }), w.each(e.elemHeader, function (t, n) {
  814. w(n[0]).on("click", function (n) {
  815. e.change(t).prevYear();
  816. }), w(n[1]).on("click", function (n) {
  817. e.change(t).prevMonth();
  818. }), w(n[2]).find("span").on("click", function (n) {
  819. var a = w(this),
  820. i = a.attr("lay-ym"),
  821. r = a.attr("lay-type");
  822. i && (i = i.split("-"), e.listYM[t] = [0 | i[0], 0 | i[1]], e.list(r, t), w(e.footer).find(D).addClass(s));
  823. }), w(n[3]).on("click", function (n) {
  824. e.change(t).nextMonth();
  825. }), w(n[4]).on("click", function (n) {
  826. e.change(t).nextYear();
  827. });
  828. }), w.each(e.table, function (t, n) {
  829. var a = w(n).find("td");
  830. a.on("click", function () {
  831. e.choose(w(this));
  832. });
  833. }), w(e.footer).find("span").on("click", function () {
  834. var t = w(this).attr("lay-type");
  835. e.tool(this, t);
  836. });
  837. }, T.prototype.isInput = function (e) {
  838. return /input|textarea/.test(e.tagName.toLocaleLowerCase());
  839. }, T.prototype.events = function () {
  840. var e = this,
  841. t = e.config,
  842. n = function n(_n, a) {
  843. _n.on(t.trigger, function () {
  844. a && (e.bindElem = this), e.render();
  845. });
  846. };
  847. t.elem[0] && !t.elem[0].eventHandler && (n(t.elem, "bind"), n(t.eventElem), w(document).on("click", function (n) {
  848. n.target !== t.elem[0] && n.target !== t.eventElem[0] && n.target !== w(t.closeStop)[0] && e.remove();
  849. }).on("keydown", function (t) {
  850. 13 === t.keyCode && w("#" + e.elemID)[0] && e.elemID === T.thisElem && (t.preventDefault(), w(e.footer).find(g)[0].click());
  851. }), w(window).on("resize", function () {
  852. return !(!e.elem || !w(r)[0]) && void e.position();
  853. }), t.elem[0].eventHandler = !0);
  854. }, n.render = function (e) {
  855. var t = new T(e);
  856. return a.call(t);
  857. }, n.getEndDate = function (e, t) {
  858. var n = new Date();
  859. return n.setFullYear(t || n.getFullYear(), e || n.getMonth() + 1, 1), new Date(n.getTime() - 864e5).getDate();
  860. }, window.lay = window.lay || w, e ? (n.ready(), layui.define(function (e) {
  861. n.path = layui.cache.dir, e(i, n);
  862. })) : "function" == typeof define && define.amd ? define(function () {
  863. return n;
  864. }) : function () {
  865. n.ready(), window.laydate = n;
  866. }();
  867. }();