text: !function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Calendar=t()}("undefined"!=typeof self?self:this,function(){"use strict";var a="calendar-input",n="calendar-wrapper",d="calendar-btn-prev",i="calendar-btn-next",l="calendar-btn",o="calendar-day",c={addEvent:function(e,t,a){e.addEventListener?e.addEventListener(t,a,!1):e.attachEvent?e.attachEvent("on"+t,a):e["on"+t]=a},stopPropagation:function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},extend:function(e){for(var t=1,a=arguments.length;t<a;t++)for(var n in arguments[t])arguments[t].hasOwnProperty(n)&&(e[n]=arguments[t][n]);return e},isValidListener:function(e){return"function"==typeof e||!(!e||"object"!=typeof e)&&c.isValidListener(e.listener)},indexOf:function(e,t){if(e.indexOf)return e.indexOf(t);for(var a=-1,n=0,r=e.length;n<r;n++)if(e[n]===t){a=n;break}return a},isLastDate:function(e,t){return e===new Date(this.calendarMax).getFullYear()&&t===new Date(this.calendarMax).getMonth()+1},getFirstDateInMonth:function(e){return new Date(e.getFullYear(),e.getMonth(),1)},getLastDateInPrevMonth:function(e){return new Date(e.getFullYear(),e.getMonth(),0)},getLastDateInMonth:function(e){return new Date(e.getFullYear(),e.getMonth()+1,0)},daysInMonth:function(e,t){var a=new Date;return a.setFullYear(e,12==t?1:t,0),a.getDate()},formatDate:function(e,t){function a(e){return((e="string"==typeof e?parseInt(e):e)<10?"0":"")+e}var n=a((e="string"==typeof e?new Date(e):e).getFullYear()),r=a(e.getMonth()+1),s=a(e.getDate()),d=a(e.getDay());return{getFullYear:parseInt(n),getMonth:parseInt(r),getDate:parseInt(s),getDay:parseInt(d),date:t.replace(/yyyy|MM|dd/g,function(e){switch(e){case"yyyy":return n;case"MM":return r;case"dd":return s}})}}};function e(){this.__events={}}function t(e,t){this.options=c.extend({},this.constructor.calendarOptions,t,!0),this._initCalendar(e),this.calendarTime=c.formatDate(this.options.time,"yyyy-MM-dd").date,this.calendarShowTime=c.formatDate(this.options.time,"yyyy-MM").date,this._refreshCalendar(new Date(this.options.time)),this._getCalendar(),this._bindCalendar()}e.prototype.on=function(e,t){if(e&&t){if(!c.isValidListener(t))throw new TypeError("listener must be a function");var a=this.__events,n=a[e]=a[e]||[],r="object"==typeof t;return-1===c.indexOf(n,t)&&n.push(r?t:{listener:t,once:!1}),this}},e.prototype.once=function(e,t){return this.on(e,{listener:t,once:!0})},e.prototype.off=function(e,t){var a=this.__events[e];if(a){for(var n,r=0,s=a.length;r<s;r++)if(a[r]&&a[r].listener===t){n=r;break}return void 0!==n&&a.splice(n,1,null),this}},e.prototype.emit=function(e,t){var a=this.__events[e];if(a){for(var n=0;n<a.length;n++){var r=a[n];r&&(r.listener.apply(this,t||[]),r.once&&this.off(e,r.listener))}return this}},t.calendarOptions={time:new Date};var r=t.prototype=new e;return r.constructor=t,r._initCalendar=function(e){this.calendar=document.querySelector(e),this.calendar.onselectstart=function(){return!1},this.calendarWeeks=["Su","Mo","Tu","We","Th","Fr","Sa"],this.calendarMaxDay=31,this.calendarMax=c.formatDate(new Date(864e13),"yyyy-MM-dd").date,this.calendarMin="100-01-01",this.calendarRow=Math.floor(this.calendarMaxDay/this.calendarWeeks.length)+2,this.calendarDaysCount=this.calendarWeeks.length*this.calendarRow},r._refreshCalendar=function(e){this._setCalendarDays(e),this._renderCalendar()},r._getCalendar=function(){},r._setCalendarDays=function(e){this.calendarDays=[],this._setCalendarDaysInPrevMonth(e),this._setCalendarDaysInCurrentMonth(e),this._setCalendarDaysInNextMonth(e)},r._setCalendarDaysInPrevMonth=function(e){var t=c.getFirstDateInMonth(e).getDay(),a=c.getLastDateInPrevMonth(e).getDate(),n=0===t?a-this.calendarWeeks.length+1:a-t+1;this._setCalendarDaysInMonth(e.getMonth()<1?e.getFullYear()-1:e.getFullYear(),e.getMonth()<1?12:e.getMonth(),n,a,!1)},r._setCalendarDaysInCurrentMonth=function(e){var t;t=c.isLastDate(e.getFullYear(),e.getMonth()+1)?new Date(this.calendarMax).getDate():c.getLastDateInMonth(e).getDate(),this._setCalendarDaysInMonth(e.getFullYear(),e.getMonth()+1,1,t,!0)},r._setCalendarDaysInNextMonth=function(e){c.isLastDate(e.getFullYear(),e.getMonth()+1)||this.calendarDays.length!=this.calendarDaysCount&&this._setCalendarDaysInMonth(12<e.getMonth()+2?e.getFullYear()+1:e.getFullYear(),12<e.getMonth()+2?1:e.getMonth()+2,1,this.calendarDaysCount-this.calendarDays.length,!1)},r._setCalendarDaysInMonth=function(e,t,a,n,r){for(var s=a,d=n;s<=d;s++)this.calendarDays.push({year:e,month:t,day:s,isCurrent:r})},r._renderCalendar=function(){var e=document.querySelector("."+a);e||(e='<input type="text" class="calendar-input" readonly placeholder="点击选择日期" />',this.calendar.innerHTML=e);var t=document.querySelector("."+n);t||(t=document.createElement("div"),this.calendar.appendChild(t),t.className=n),t.innerHTML='{{calendarShowTime}}<table class="calendar-content">{{calendarWeeks}}{{calendarDays}}</table>'.replace("{{calendarShowTime}}",this._renderCalendarTitle()).replace("{{calendarWeeks}}",this._renderCalendarWeeks()).replace("{{calendarDays}}",this._renderCalendarDays())},r._renderCalendarTitle=function(){return'<div class="calendar-title"><a href="javascript:;" class="calendar-btn calendar-btn-prev" id="calendarDatePrev">&lt;</a><span class="calendar-time" id="calendarDateTime">'+this.calendarShowTime+'</span><a href="javascript:;" class="calendar-btn calendar-btn-next" id="calendarDateNext">&gt;</a></div>'},r._renderCalendarWeeks=function(){for(var e="",t=0;t<this.calendarWeeks.length;t++)e+='<th class="calendar-week">'+this.calendarWeeks[t]+"</th>";return'<thead><tr class="calendar-weeks">'+e+"</tr></thead>"},r._renderCalendarDays=function(){for(var e="",t=[],a=[],n=this.calendarWeeks.length,r=0;r<this.calendarRow;r++){e="",e+='<tr class="calendar-days">',a=this.calendarDays.slice(r*n,r*n+n);for(var s=0;s<a.length;s++)a[s].isCurrent?c.formatDate(new Date(a[s].year,a[s].month-1,a[s].day),"yyyy-MM-dd").date===this.calendarTime?e+='<td class="calendar-day select" data-date="'+a[s].day+'">'+a[s].day+"</td>":e+='<td class="calendar-day current" data-date="'+a[s].day+'">'+a[s].day+"</td>":e+='<td class="calendar-day" data-date="'+a[s].day+'">'+a[s].day+"</td>";e+="</tr>",t.push(e)}return t.join("")},r._bindCalendar=function(){this._bindCalendarInput(),this._bindCalendarContent(),this._bindCalendarBtn()},r._bindCalendarInput=function(){var s=this,d=document.querySelector("."+a),i=document.querySelector("."+n);this.calendarIsOpen=!1,c.addEvent(d,"click",function(e){var t=e||window.event;t.target||t.srcElement;if(s.calendarIsOpen)i.classList.remove("calendar-wrapper-show"),s.calendarIsOpen=!1;else{i.classList.add("calendar-wrapper-show");var a=s.calendar.offsetLeft,n=s.calendar.offsetTop,r=d.offsetHeight;i.style.top=n+r+2+"px",i.style.left=a+"px",s.calendarIsOpen=!0}})},r._bindCalendarContent=function(){var s=this,d=document.querySelector("."+a),i=document.querySelector("."+n);c.addEvent(i,"click",function(e){var t=e||window.event,a=t.target||t.srcElement,n=document.querySelectorAll("."+o);if("td"===a.tagName.toLowerCase()){for(var r=0;r<n.length;r++)if(n[r]===a){s.calendarTime=c.formatDate(new Date(s.calendarDays[r].year,s.calendarDays[r].month-1,s.calendarDays[r].day),"yyyy-MM-dd").date,s.calendarShowTime=c.formatDate(new Date(s.calendarDays[r].year,s.calendarDays[r].month-1,s.calendarDays[r].day),"yyyy-MM").date,s._refreshCalendar(new Date(s.calendarTime));break}s.emit("click",[s.calendarTime]),d.value=s.calendarTime,i.classList.remove("calendar-wrapper-show"),s.calendarIsOpen=!1}})},r._bindCalendarBtn=function(){var s=this,e=document.querySelector("."+n);c.addEvent(e,"click",function(e){var t=e||window.event,a=t.target||t.srcElement,n=new Date(s.calendarShowTime).getFullYear(),r=new Date(s.calendarShowTime).getMonth()+1;a.classList.contains(l)&&(a.classList.contains(d)?s._bindCalendarPrev(n,r):a.classList.contains(i)&&s._bindCalendarNext(n,r))})},r._bindCalendarPrev=function(e,t){--t<1&&(t=12,e--),this.calendarShowTime=c.formatDate(new Date(e,t-1),"yyyy-MM").date,this._refreshCalendar(new Date(this.calendarShowTime))},r._bindCalendarNext=function(e,t){c.isLastDate(e,t)||(12<++t&&(t=1,e++),this.calendarShowTime=c.formatDate(new Date(e,t-1),"yyyy-MM").date,this._refreshCalendar(new Date(this.calendarShowTime)))},t});