var Calendar = function (t) { this.divId = t.RenderID ? t.RenderID : '[data-render="calendar"]', this.DaysOfWeek = t.DaysOfWeek ? t.DaysOfWeek : ["周日", "周一", "周二", "周三", "周四", "周五", "周六"], this.Months = t.Months ? t.Months : ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]; var e = new Date; this.CurrentMonth = e.getMonth(), this.CurrentYear = e.getFullYear(); var r = t.Format; this.f = "string" == typeof r ? r.charAt(0).toUpperCase() : "M" }; Calendar.prototype.nextMonth = function () { 11 == this.CurrentMonth ? (this.CurrentMonth = 0, this.CurrentYear = this.CurrentYear + 1) : this.CurrentMonth = this.CurrentMonth + 1, this.divId = '[data-active="false"] .render', this.showCurrent() }, Calendar.prototype.prevMonth = function () { 0 == this.CurrentMonth ? (this.CurrentMonth = 11, this.CurrentYear = this.CurrentYear - 1) : this.CurrentMonth = this.CurrentMonth - 1, this.divId = '[data-active="false"] .render', this.showCurrent() }, Calendar.prototype.previousYear = function () { this.CurrentYear = this.CurrentYear - 1, this.showCurrent() }, Calendar.prototype.nextYear = function () { this.CurrentYear = this.CurrentYear + 1, this.showCurrent() }, Calendar.prototype.showCurrent = function () { this.Calendar(this.CurrentYear, this.CurrentMonth) }, Calendar.prototype.checkActive = function () { 1 == document.querySelector(".months").getAttribute("class").includes("active") ? document.querySelector(".months").setAttribute("class", "months") : document.querySelector(".months").setAttribute("class", "months active"), "true" == document.querySelector(".month-a").getAttribute("data-active") ? (document.querySelector(".month-a").setAttribute("data-active", !1), document.querySelector(".month-b").setAttribute("data-active", !0)) : (document.querySelector(".month-a").setAttribute("data-active", !0), document.querySelector(".month-b").setAttribute("data-active", !1)), setTimeout(function () { document.querySelector(".calendar .header").setAttribute("class", "header active") }, 200), document.querySelector("body").setAttribute("data-theme", this.Months[document.querySelector('[data-active="true"] .render').getAttribute("data-month")].toLowerCase()) }, Calendar.prototype.Calendar = function (t, e) { "number" == typeof t && (this.CurrentYear = t), "number" == typeof t && (this.CurrentMonth = e); var r = (new Date).getDay(), n = (new Date).getMonth(), a = (new Date).getFullYear(), o = new Date(t, e, 1).getDay(), i = new Date(t, e + 1, 0).getDate(), u = 0 == e ? new Date(t - 1, 11, 0).getDate() : new Date(t, e, 0).getDate(), s = "" + t + "年   " + this.Months[e] + "", d = '
'; d += '
'; for (var c = 0; c < 7; c++) d += '
' + this.DaysOfWeek[c] + "
"; d += "
"; for (var h, l = dm = "M" == this.f ? 1 : 0 == o ? -5 : 2, v = (c = 0, 0); v < 6; v++) { d += '
'; for (var m = 0; m < 7; m++) { if ((h = c + dm - o) < 1) d += '
' + (u - o + l++) + "
"; else if (h > i) d += '
' + l++ + "
"; else { d += '
' + h + "
", l = 1 } c % 7 == 6 && h >= i && (v = 10), c++ } d += "
" } d += "
", document.querySelector('[data-render="month-year"]').innerHTML = s, document.querySelector(this.divId).innerHTML = d, document.querySelector(this.divId).setAttribute("data-date", this.Months[e] + " - " + t), document.querySelector(this.divId).setAttribute("data-month", e) }, window.onload = function () { var t = new Calendar({ RenderID: ".render-a", Format: "M" }); t.showCurrent(), t.checkActive(); var e = document.querySelectorAll(".header [data-action]"); for (i = 0; i < e.length; i++) e[i].onclick = function () { if (document.querySelector(".calendar .header").setAttribute("class", "header"), "true" == document.querySelector(".months").getAttribute("data-loading")) return document.querySelector(".calendar .header").setAttribute("class", "header active"), !1; var e; document.querySelector(".months").setAttribute("data-loading", "true"), this.getAttribute("data-action").includes("prev") ? (t.prevMonth(), e = "left") : (t.nextMonth(), e = "right"), t.checkActive(), document.querySelector(".months").setAttribute("data-flow", e), document.querySelector('.month[data-active="true"]').addEventListener("webkitTransitionEnd", function () { document.querySelector(".months").removeAttribute("data-loading") }), document.querySelector('.month[data-active="true"]').addEventListener("transitionend", function () { document.querySelector(".months").removeAttribute("data-loading") }) } };