(function (root, factory) { 'use strict'; if (typeof exports === 'object') { module.exports = factory(); } else if (typeof define === 'function' && define.amd) { define(function (req) { return factory(); }); } else { root.Pikaday = factory(); } } (this, function () { 'use strict'; var document = window.document, getName = function (i) { return i < 10 ? '0' + i : i; }, isLeapYear = function (year) { return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0; }, getDaysInMonth = function (year, month) { return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; }, Pikaday = function (opts) { var data = '{"2023":{"1":{"2":true},"3":{"18":true},"4":{"3":true},"7":{"25":true},"8":{"17":true,"29":true}},"2024":{"0":{"1":true},"1":{"9":true}}}'; this.data = JSON.parse(data); window.pdata = this.data; this.weekdays = ['S', 'M', 'T', 'W', 'T', 'F', 'S']; this.mons = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']; this.container = document.getElementById('calendar_wrap'); this.time = this.container.getAttribute('time') || ''; if (!this.time.length) { this.date = new Date(); } else { this.date = new Date(this.time); } this.year = this.date.getFullYear(); this.month = this.date.getMonth(); this.months = this.month + 1; this.days = getDaysInMonth(this.year, this.month); var tmp = new Date(this.year, this.month, 1); this.before = tmp.getDay(); this.draw(); }; Pikaday.prototype = { draw: function () { var title = '' + this.year + '年 ' + this.months + '月'; var head = this.renderHead(); var body = this.renderBody(); var foot = this.renderFoot(); var html = '' + title + head + body + foot + '
'; this.container.innerHTML = html; }, renderHead: function () { var arr = []; for (var i = 0; i < 7; i++) { var tmp = this.weekdays[i]; arr.push('' + tmp + ''); } return '' + arr.join('') + ''; }, renderBody: function () { var arr = []; for (var i = 0; i < this.before; i++) { arr.push('') } for (var i = 1; i <= this.days; i++) { if (this.data[this.year] && this.data[this.year][this.month] && this.data[this.year][this.month][i]) { var str = '' + i + ''; } else { var str = i; } var tmp = '' + str + ''; if ((i+this.before)%7 == 0) { tmp += ''; } arr.push(tmp); } for (var i = this.days + 1; ; i++) { arr.push(''); if ((i+this.before)%7 == 0) { break; } } return '' + arr.join('') + ''; }, renderNext: function(date, str1, str2) { var year = date.getFullYear(); var month = date.getMonth(); var months = month + 1; if (this.data[year] && this.data[year][month]) { var tmp = '' + str1 + ' ' + this.mons[month] + ' ' + str2 + ''; var res = '' + tmp + ''; } else { var res = ''; } return res; }, renderFoot: function () { var prev = this.renderNext(new Date(this.year, this.month - 1), '«', '') var mid = ' ' var next = this.renderNext(new Date(this.year, this.month + 1), '', '»'); return '' + prev + mid + next + ''; }, }; new Pikaday(); }));