filesbox/web/dist/design/designstatic/home/js/simple-calendar.js
2024-07-26 14:10:54 +08:00

2 lines
16 KiB
JavaScript

"use strict";var _typeof=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(h){return typeof h}:function(h){return h&&typeof Symbol=="function"&&h.constructor===Symbol?"symbol":typeof h},_createClass=function(){function h(n,a){for(var e=0;e<a.length;e++){var t=a[e];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(n,t.key,t)}}return function(n,a,e){return a&&h(n.prototype,a),e&&h(n,e),n}}();function _classCallCheck(h,n){if(!(h instanceof n))throw new TypeError("Cannot call a class as a function")}var LunarHelp=function(){function h(n,a,e){_classCallCheck(this,h),this.lunarInfo=new Array(19416,19168,42352,21717,53856,55632,91476,22176,39632,21970,19168,42422,42192,53840,119381,46400,54944,44450,38320,84343,18800,42160,46261,27216,27968,109396,11104,38256,21234,18800,25958,54432,59984,28309,23248,11104,100067,37600,116951,51536,54432,120998,46416,22176,107956,9680,37584,53938,43344,46423,27808,46416,86869,19872,42448,83315,21200,43432,59728,27296,44710,43856,19296,43748,42352,21088,62051,55632,23383,22176,38608,19925,19152,42192,54484,53840,54616,46400,46496,103846,38320,18864,43380,42160,45690,27216,27968,44870,43872,38256,19189,18800,25776,29859,59984,27480,21952,43872,38613,37600,51552,55636,54432,55888,30034,22176,43959,9680,37584,51893,43344,46240,47780,44368,21977,19360,42416,86390,21168,43312,31060,27296,44368,23378,19296,42726,42208,53856,60005,54576,23200,30371,38608,19415,19152,42192,118966,53840,54560,56645,46496,22224,21938,18864,42359,42160,43600,111189,27936,44448),this.nStr1=new Array("\u65E5","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D","\u5341"),this.nStr2=new Array("\u521D","\u5341","\u5EFF","\u4E09");var t=new Date(parseInt(n),parseInt(a)-1,parseInt(e)),r,s=0,l=0,i=new Date(1900,0,31),c=(t-i)/864e5;for(r=1900;r<2050&&c-this.lYearDays(r)>0;r++)c-=this.lYearDays(r);for(this.year=r,s=this.leapMonth(r),this.isLeap=!1,r=1;r<13&&c>0;r++)s>0&&r==s+1&&this.isLeap==!1?(--r,l=this.leapDays(this.year)):l=this.monthDays(this.year,r),this.isLeap==!0&&r==s+1&&(this.isLeap=!1),c-=l;c==0&&s>0&&r==s+1&&(this.isLeap?this.isLeap=!1:(this.isLeap=!0,--r)),c<0&&(c+=l,--r),this.month=r,this.day=c+1}return _createClass(h,[{key:"lYearDays",value:function(a){var e,t=0;for(e=32768;e>8;e>>=1)t+=this.lunarInfo[a-1900]&e?30:29;return t+this.leapDays(a)}},{key:"leapDays",value:function(a){return this.leapMonth(a)?this.lunarInfo[a-1900]&65536?30:29:0}},{key:"leapMonth",value:function(a){return this.lunarInfo[a-1900]&15}},{key:"monthDays",value:function(a,e){return this.lunarInfo[a-1900]&65536>>e?30:29}},{key:"cDay",value:function(a){var e;switch(a){case 10:e="\u521D\u5341";break;case 20:e="\u4E8C\u5341";break;case 30:e="\u4E09\u5341";break;default:e=this.nStr2[Math.floor(a/10)],e+=this.nStr1[parseInt(a%10)]}return e}},{key:"cMonth",value:function(a){var e;switch(a){case 1:e="\u6B63\u6708";break;case 2:e="\u4E8C\u6708";break;case 3:e="\u4E09\u6708";break;case 4:e="\u56DB\u6708";break;case 5:e="\u4E94\u6708";break;case 6:e="\u516D\u6708";break;case 7:e="\u4E03\u6708";break;case 8:e="\u516B\u6708";break;case 9:e="\u4E5D\u6708";break;case 10:e="\u5341\u6708";break;case 11:e="\u5341\u4E00\u6708";break;case 12:e="\u5341\u4E8C\u6708";break;default:break}return e}},{key:"getLunarDay",value:function(){return cMonth(this.month)+cDay(this.day)}},{key:"getLunarDayName",value:function(){return this.day==1?this.cMonth(this.month):this.cDay(this.day)}},{key:"getLunarDayNum",value:function(){return{day:this.day,month:this.month}}}]),h}(),SimpleCalendar=function(){function h(n,a){_classCallCheck(this,h),this._defaultOptions={width:"500px",height:"500px",language:"CH",showLunarCalendar:!0,showHoliday:!0,showFestival:!0,showLunarFestival:!0,showSolarTerm:!0,showMark:!0,timeRange:{startYear:1900,endYear:2049},timeZone:"",mark:{"2016-5-5":"\u4E0A\u5B66"},theme:{changeAble:!1,weeks:{backgroundColor:"#FBEC9C",fontColor:"#4A4A4A",fontSize:"20px"},days:{backgroundColor:"#ffffff",fontColor:"#565555",fontSize:"24px"},todaycolor:"orange",activeSelectColor:"orange",invalidDays:"#C1C0C0"}},this.container=document.querySelector(n),this._defaultOptions.width=this.container.style.offsetWidth,this._defaultOptions.height=this.container.style.offsetHeight,this._options=this.optionAssign(this._defaultOptions,a),this.create()}return _createClass(h,[{key:"optionAssign",value:function(a,e){for(var t in e)_typeof(a[t])!=="object"?a[t]=e[t]:a[t]=this.optionAssign(a[t],e[t]);return a}},{key:"create",value:function(){var a=this.container;a.innerHTML='<div class="sc-header"> </div> <div class="sc-body"> </div>',a.style.width=this._options.width,a.style.height=this._options.height,a.className="sc-calendar";var e=a.querySelector(".sc-header"),t=a.querySelector(".sc-body");e.innerHTML=e.innerHTML+'<div class="sc-actions"> <div class="sc-yleft"> &lsaquo;</div> <select class="sc-select-year" name=""> </select> <div class="sc-yright">&rsaquo;</div> </div>',e.innerHTML=e.innerHTML+'<div class="sc-actions"> <div class="sc-mleft"> &lsaquo;</div> <select class="sc-select-month" name=""> </select> <div class="sc-mright">&rsaquo;</div></div>',e.innerHTML=e.innerHTML+'<div class="sc-actions"><span class="sc-return-today ">\u8FD4\u56DE\u4ECA\u5929</span></div>',e.innerHTML=e.innerHTML+'<div class="sc-actions"><span class="sc-time"></span></div>',t.innerHTML=' <div class="sc-week"> </div> <div class="sc-days"> </div>';for(var r=t.querySelector(".sc-week"),s=t.querySelector(".sc-days"),l=0;l<7;l++)r.innerHTML=r.innerHTML+' <div class="sc-week-item"></div>';for(var l=0;l<35;l++)s.innerHTML=s.innerHTML+'<div class="sc-item"><div class="day"></div><div class="lunar-day"></div></div>';this.updateSelect(this.tyear,this.tmonth),this.update(),self.setInterval("SimpleCalendar.timeupdate()",200)}},{key:"update",value:function(){var a=arguments.length<=0||arguments[0]===void 0?this.tmonth:arguments[0],e=arguments.length<=1||arguments[1]===void 0?this.tyear:arguments[1];this.updateSize(),this.updateWeek(),this.addData(e,a),this.updateHoliday(e,a),this.updateMark(e,a),this.updateFestival(e,a),this.updateEvent(),this.updateTheme(this._options.theme)}},{key:"updateSize",value:function(){var a=arguments.length<=0||arguments[0]===void 0?this._options.width:arguments[0],e=arguments.length<=1||arguments[1]===void 0?this._options.height:arguments[1];if(this._options.width=a,this._options.height=e,this.container.style.width=a,this.container.style.height=e,parseInt(a)<500){var t=this.arrayfrom(this.container.querySelectorAll(".sc-actions"));t.forEach(function(l,i){l.classList.add("sc-actions-big")})}else{var t=this.arrayfrom(this.container.querySelectorAll(".sc-actions"));t.forEach(function(i,c){i.classList.remove("sc-actions-big")})}if(parseInt(e)<400){var r=this.arrayfrom(this.container.querySelectorAll(".sc-item")),s=this.arrayfrom(this.container.querySelectorAll(".sc-week-item"));r.forEach(function(l,i){l.querySelector(".day").classList.add("sc-item-small")}),s.forEach(function(l,i){l.classList.add("sc-item-small")})}else{var r=this.arrayfrom(this.container.querySelectorAll(".sc-item")),s=this.arrayfrom(this.container.querySelectorAll(".sc-week-item"));r.forEach(function(c,u){c.querySelector(".day").classList.remove("sc-item-small")}),s.forEach(function(c,u){c.classList.remove("sc-item-small")})}}},{key:"updateSelect",value:function(a,e){var t=this.container.querySelector(".sc-select-year"),r=this.container.querySelector(".sc-select-month");t.innerHTML="";for(var s=this._options.timeRange.startYear;s<this._options.timeRange.endYear+1;s++)t.innerHTML+='<option value="'+s+'">'+s+"</option>";r.innerHTML="";for(var s=0;s<12;s++){var l=this.languageData["months_"+this._options.language];r.innerHTML+='<option value="'+(s+1)+'">'+l[s]+"</option>"}t.value=a,r.value=e}},{key:"updateWeek",value:function(){var a=this.arrayfrom(this.container.querySelectorAll(".sc-week-item")),e=this.languageData["days_"+this._options.language];e||console.error("language error!"),a.forEach(function(t,r){t.innerHTML=e[r]})}},{key:"addData",value:function(a,e){var t=this.arrayfrom(this.container.querySelectorAll(".sc-item")),r=new Date(a,e-1,1),s=r.getDay();s==0&&(s=7);for(var l=new Date(Date.parse(r)-(s-1)*24*3600*1e3),i=0;i<35;i++){t[i].className="sc-item";var c=new Date(Date.parse(l)+i*24*3600*1e3),u=c.getFullYear(),y=c.getDate(),o=c.getMonth()+1;o!=e&&t[i].classList.add("sc-othermenth"),t[i].querySelector(".day").innerHTML=y,this._options.showLunarCalendar?t[i].querySelector(".lunar-day").innerHTML=new LunarHelp(u,o,y).getLunarDayName():(t[i].querySelector(".lunar-day").innerHTML="",t[i].classList.add("item-nolunar")),this.tyear==u&&this.tday==y&&this.tmonth==o&&(this.selectDay=t[i],t[i].classList.add("sc-today"))}}},{key:"updateMark",value:function(a,e){var t=this._options;if(t.showMark){var r=this.arrayfrom(this.container.querySelectorAll(".sc-item")),s=e-1,l=t.mark;l&&r.forEach(function(i,c){var u=+i.querySelector(".day").innerHTML;u==1&&s++,l[a+"-"+s+"-"+u]?(i.classList.add("sc-mark"),i.title=l[a+"-"+s+"-"+u]):(i.classList.remove("sc-mark"),i.title="")})}}},{key:"updateFestival",value:function(a,e){var t=this._options,r=this.arrayfrom(this.container.querySelectorAll(".sc-item")),s=e-1,l=this.languageData["feativals_"+this._options.language],i=this.languageData["lunarFeatival_"+this._options.language],c=this.languageData.solarTerm;l||console.error("language error!"),r.forEach(function(u,y){var o=+u.querySelector(".day").innerHTML;if(o==1&&s++,t.showSolarTerm&&c[s+"-"+o]&&(u.querySelector(".lunar-day").innerHTML=c[s+"-"+o],u.classList.add("sc-festival")),t.showFestival&&l[s+"-"+o]&&(u.querySelector(".lunar-day").innerHTML=l[s+"-"+o],u.classList.add("sc-festival")),i&&t.showLunarFestival){var d=new LunarHelp(a,s,o).getLunarDayNum();i[d.month+"-"+d.day]&&(u.querySelector(".lunar-day").innerHTML=i[d.month+"-"+d.day],u.classList.add("sc-festival"))}})}},{key:"updateHoliday",value:function(a,e){var t=this._options;if(t.showHoliday){var r=this.arrayfrom(this.container.querySelectorAll(".sc-item")),s=e-1,l=this.languageData.vocation["data_"+a];l&&r.forEach(function(i,c){var u=+i.querySelector(".day").innerHTML;u==1&&s++,l.indexOf(s+"-"+u)>0&&i.classList.add("sc-vocation")})}}},{key:"updateTheme",value:function(a){if(this._options.theme.changeAble){var e=a.days,t=a.weeks,r=this.arrayfrom(this.container.querySelectorAll(".sc-week-item")),s=this.arrayfrom(this.container.querySelectorAll(".sc-item"));r.forEach(function(i,c){i.style.backgroundColor=t.backgroundColor,i.style.fontSize=t.fontSize,i.style.color=t.fontColor}),s.forEach(function(i,c){i.classList.contains("sc-today")?i.style.backgroundColor=a.todaycolor:(i.style.backgroundColor=e.backgroundColor,i.querySelector(".day").style.color=e.fontColor),i.querySelector(".day").style.fontSize=e.fontSize});var l=this;s.forEach(function(i,c){i.onmouseover=function(u){this.style.borderColor=a.activeSelectColor,this.style.borderWidth="1px"},i.onmouseout=function(u){this.style.borderColor="#F1EBE4",this.style.borderWidth="0 0 1px 1px"}})}}},{key:"updateEvent",value:function(){var a=this.arrayfrom(this.container.querySelectorAll(".sc-item")),e=this.container,t=this;a.forEach(function(o,d){o.onmouseover=function(f){this.classList.add("sc-active-day")},o.onmouseout=function(f){this.classList.remove("sc-active-day")},o.onclick=function(){t.selectDay=o;var f=e.querySelector(".sc-selected");f&&f.classList.remove("sc-selected"),this.classList.add("sc-selected")}});var r=e.querySelector(".sc-select-year"),s=e.querySelector(".sc-select-month");r.onchange=function(){var o=s.value,d=this.value;t.update(o,d)},s.onchange=function(){var o=r.value,d=this.value;t.update(d,o)};var l=e.querySelector(".sc-yright"),i=e.querySelector(".sc-yleft"),c=e.querySelector(".sc-mright"),u=e.querySelector(".sc-mleft");l.onclick=function(){var o=r.value;o<2099&&o++,r.value=o,t.update(this.tmonth,o)},i.onclick=function(){var o=r.value;o>1900&&o--,r.value=o,t.update(this.tmonth,o)},c.onclick=function(){var o=s.value,d=r.value;o<12?o++:(o=1,r.value=++d),s.value=o,t.update(o,d)},u.onclick=function(){var o=s.value,d=r.value;o>1?o--:(o=12,r.value=--d),s.value=o,t.update(o,d)};var y=e.querySelector(".sc-return-today");y.onclick=function(){r.value=t.tyear,s.value=t.tmonth,t.update()}}},{key:"addMark",value:function(a,e){this._options.mark[a]=e,this.update()}},{key:"getSelectedDay",value:function(){var a=this.container.querySelector(".sc-select-year").value,e=this.container.querySelector(".sc-select-month").value,t=this.selectDay.querySelector(".day").innerHTML;return new Date(a,e-1,t)}},{key:"setLenguage",value:function(a){this._options.language=a;var e=this.container.querySelector(".sc-select-year"),t=this.container.querySelector(".sc-select-month");this.updateSelect(e.value,t.value),this.update()}},{key:"showFestival",value:function(a){this._options.showFestival=a,this.update()}},{key:"showHoliday",value:function(a){this._options.showHoliday=a,this.update()}},{key:"showSolarTerm",value:function(a){this._options.showSolarTerm=a,this.update()}},{key:"showLunarFestival",value:function(a){this._options.showLunarFestival=a,this.update()}},{key:"showLunarCalendar",value:function(a){this._options.showLunarCalendar=a,this.update()}},{key:"showMark",value:function(a){this._options.showMark=a,this.update()}},{key:"arrayfrom",value:function(a){var e=[];return[].forEach.call(a,function(t){e.push(t)}),e}}]),h}();SimpleCalendar.timeupdate=function(){var h=document.querySelectorAll(".sc-time"),n=new Date,a=n.getHours(),e=n.getMinutes(),t=n.getSeconds();a<10&&(a="0"+a),e<10&&(e="0"+e),t<10&&(t="0"+t),[].forEach.call(h,function(r){r.innerHTML="\u65F6\u95F4\uFF1A"+a+":"+e+":"+t})},SimpleCalendar.prototype.languageData={feativals_CH:{"1-1":"\u5143\u65E6","2-14":"\u60C5\u4EBA\u8282","3-8":"\u5987\u5973\u8282","3-12":"\u690D\u6811\u8282","4-1":"\u611A\u4EBA\u8282","4-22":"\u5730\u7403\u65E5","5-1":"\u52B3\u52A8\u8282","5-4":"\u9752\u5E74\u8282","6-1":"\u513F\u7AE5\u8282","7-1":"\u5EFA\u515A\u8282","8-1":"\u5EFA\u519B\u8282","9-10":"\u6559\u5E08\u8282","10-1":"\u56FD\u5E86\u8282","12-25":"\u5723\u8BDE\u8282"},feativals_EN:{"1-1":"new year\u2019s day","2-14":"Saint Valentine's Day","3-8":"international women\u2019s day","3-12":"Arbor Day","4-1":"April Fool's Day","4-22":"Earth Day","5-1":"international labour day","5-4":"Chinese Youth Day","6-1":"Children's Day","7-1":"The party's Day","8-1":"the Army's Day","9-10":"Teachers' Day","10-1":"National Day","12-25":"Christmas Day"},lunarFeatival_CH:{"1-1":"\u6625\u8282","2-2":"\u9F99\u62AC\u5934","1-15":"\u5143\u5BB5\u8282","4-4":"\u5BD2\u98DF\u8282","4-5":"\u6E05\u660E\u8282","5-5":"\u7AEF\u5348\u8282","8-15":"\u4E2D\u79CB\u8282","9-9":"\u91CD\u9633\u8282","12-30":"\u9664\u5915"},solarTerm:{"2-3":"\u7ACB\u6625","5-5":"\u7ACB\u590F","8-7":"\u7ACB\u79CB","11-7":"\u7ACB\u51AC","2-18":"\u96E8\u6C34","5-20":"\u5C0F\u6EE1","8-22":"\u5904\u6691","11-22":"\u5C0F\u96EA","3-5":"\u60CA\u86F0","6-5":"\u8292\u79CD","9-7":"\u767D\u9732","12-6":"\u5927\u96EA","3-20":"\u6625\u5206","6-21":"\u590F\u81F3","9-22":"\u79CB\u5206","12-21":"\u51AC\u81F3","4-4":"\u6E05\u660E","7-6":"\u5C0F\u6691","10-8":"\u5BD2\u9732","1-5":"\u5C0F\u5BD2","4-19":"\u8C37\u96E8","7-22":"\u5927\u6691","10-23":"\u971C\u964D","1-20":"\u5927\u5BD2"},days_EN:["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],days_CH:["\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u65E5"],months_EN:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],months_CH:["\u4E00\u6708","\u4E8C\u6708","\u4E09\u6708","\u56DB\u6708","\u4E94\u6708","\u516D\u6708","\u4E03\u6708","\u516B\u6708","\u4E5D\u6708","\u5341\u6708","\u5341\u4E00\u6708","\u5341\u4E8C\u6708"],vocation:{data_2016:["1-1","1-2","1-3","2-7","2-8","2-9","2-10","2-11","2-12","2-13","4-2","4-3","4-4","4-30","5-1","5-2","6-9","6-10","6-11","9-15","9-16","9-17",,"10-1","10-2","10-3","10-4","10-5","10-6","10-7"]}},SimpleCalendar.prototype.tyear=new Date().getFullYear(),SimpleCalendar.prototype.tmonth=new Date().getMonth()+1,SimpleCalendar.prototype.tday=new Date().getDate();