lunar-calendar-fix
Version:
农历(阴历)万年历,是一款支持Node.js和浏览器端使用的全功能农历和公历日历类库。支持农历与公历之间相互转换,含有二十四节气,天干地支纪年纪月纪日,生肖属相,公历节假日及农历传统节假日信息等功能。自带2013-2014节假日安排数据,并可自行配置。带有黄历数据,可自行选择配置。支持1891-2100年。
11 lines (10 loc) • 5.96 kB
JavaScript
/**
* 农历(阴历)万年历
* LunarCalendar;NPM NAME:lunar-calendar
* vervison : v0.1.5
* Github : https://github.com/zzyss86/LunarCalendar
* HomePage : http://www.tuijs.com/
* Author : JasonZhou
* Email : zzyss86@qq.com
*/
window.HuangLi=window.HuangLi||{},function(){var t={platform:"",version:0,Android:function(){return"Android"===this.platform},iOS:function(){return"iOS"===this.platform},init:function(){var t=navigator.userAgent;t.match(/Android/i)?(this.platform="Android",this.version=parseFloat(t.slice(t.indexOf("Android")+8))):t.match(/iPhone|iPad|iPod/i)&&(this.platform="iOS",this.version=parseFloat(t.slice(t.indexOf("OS")+3)))}};t.init(),this.mobile=t}(),Zepto&&($.getScript=function(t,e){var a=document.getElementsByTagName("head")[0],n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("src",t),a.appendChild(n);function r(){"function"==typeof e&&e()}document.all?n.onreadystatechange=function(){"loaded"!=n.readyState&&"complete"!=n.readyState||r()}:n.onload=function(){r()}}),function(){function a(){}var r={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g};a.compile=function(t,e){var a=e||r,n="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+t.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(a.interpolate,function(t,e){return"',"+e.replace(/\\'/g,"'")+",'"}).replace(a.evaluate||null,function(t,e){return"');"+e.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+"__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');";return new Function("obj",n)},a.template=function(t,e){return a.compile(t)(e)},"undefined"!=typeof exports?exports.Footprint=a:window.Footprint=a,Zepto&&($.template=a.template)}();var Calendar=function(){var r="http://cdn.tuijs.com/js/",i=2008,o=2020,d=1891,u=2100,l=['<div class="date_item<%=itemCls%>" data-index="<%=index%>">','\t<span class="date_icon<%=iconCls%>"><%=iconText%></span>','\t<span class="date_day"><%=day%></span>','\t<span class="date_lunar<%=fetvCls%>"><%=lunar%></span>',"</div>"],s=new Date,m=null,c=null,p=[0,1],h=0,f=-1,y=function(t,e){return"d"+(t=(t+=1)<10?"0"+t:t)+(e=e<10?"0"+e:e)};function _(t,e,a,n){m={year:t||s.getFullYear(),month:e||s.getMonth()+1,day:a||s.getDate(),pos:n||0}}function v(t){t?($(".hl_y_content").html(t.y),$(".hl_j_content").html(t.j),$(".date_hl").show()):$(".date_hl").hide()}function g(t){var e=LunarCalendar.solarToLunar(m.year,m.month,m.day),a=new Date(m.year,m.month-1,m.day).getDay();$("#toolbar h1").html(function(){if(!m)return"";var t=m.year,e=m.month,a=m.day;return t+"-"+(e=e<10?"0"+e:e)+"-"+(a=a<10?"0"+a:a)}()),$(".date_lunar_info").html("农历"+e.lunarMonthName+e.lunarDayName+" 星期"+["日","一","二","三","四","五","六"][a]),$(".date_gan_zhi").html(e.GanZhiYear+"年["+e.zodiac+"年] "+e.GanZhiMonth+"月 "+e.GanZhiDay+"日");var n=[];e.term&&n.push(e.term),e.lunarFestival&&n.push(e.lunarFestival),e.solarFestival&&n.push(e.solarFestival.split(" ")),$(".date_fetv").html(0<n.length?"节假日纪念日:"+n.join(","):""),t&&t.attr("class","date_item date_current"),HuangLi["y"+m.year]?v(HuangLi["y"+m.year][y(m.month,m.day)]):m.year>=i&&m.year<=o&&$.getScript(r+"hl"+m.year+".min.js",function(){v(HuangLi["y"+m.year][y(m.month,m.day)])})}function w(){c=LunarCalendar.calendar(m.year,m.month,!0);for(var t="",e=l.join(""),a=0;a<c.monthData.length;a++){var n=c.monthData[a];a%7==0&&(t+='<div class="date_row">');var r={index:a,itemCls:"",iconCls:n.worktime?1==n.worktime?" worktime":" holiday":"",iconText:n.worktime?1==n.worktime?"班":"休":"",fetvCls:n.lunarFestival||n.term?" lunar_fetv":n.solarFestival?" solar_fetv":"",lunar:""},i="";s.getFullYear()==n.year&&s.getMonth()+1==n.month&&s.getDate()==n.day&&(i=" date_today"),m.year==n.year&&m.month==n.month&&m.day==n.day&&(i=" date_current",m.pos=a),(a<c.firstDay||a>=c.firstDay+c.monthDays)&&(i=" date_other"),r.itemCls=i;var o=n.lunarDayName;n.solarFestival&&(o=n.solarFestival),n.lunarFestival&&(o=n.lunarFestival),n.term&&(o=n.term),r.lunar=o,$.extend(n,r),t+=$.template(e,n),a%7==6&&(t+="</div>")}$("#date_list_"+p[0]).html(t),g()}function n(t,e,a,n){var r,i,o,l=e&&a?(r=e,a):m.month+t<1?(r=m.year-1,12):12<m.month+t?(r=m.year+1,1):(r=m.year,m.month+t),s=n||(m.day>LunarCalendar.getSolarMonthDays[l-1]?LunarCalendar.getSolarMonthDays[l-1]:m.day);r<d||u<r||(_(r,l,s),i=p.shift(),p.push(i),w(),o=t,f&&clearTimeout(f),D({time:0,pos:0}),$("#date_list_"+p[0]).css({left:o*h}),$("#date_list_"+p[1]).css({left:0}),f=0<o?setTimeout(function(){D({time:300,pos:-1*h})},50):setTimeout(function(){D({time:300,pos:h})},50))}function D(t){var e=$(".date_slide")[0];e.style.webkitTransitionDuration=t.time+"ms",a(e,t.pos)}function a(t,e){"iOS"==mobile.platform?t.style.webkitTransform="translate3d("+e+"px,0px,0px)":t.style.webkitTransform="translate("+e+"px,0px)"}function t(){$(".date_list").hammer().on("tap",".date_item",function(){var t,e=$(this).attr("data-index"),e=parseInt(e,10),a=c.monthData[e];e<c.firstDay?n(-1,a.year,a.month,a.day):e>=c.firstDay+c.monthDays?n(1,a.year,a.month,a.day):(t=$("#date_list_"+p[0]).find(".date_item").eq(m.pos),s.getFullYear()==m.year&&s.getMonth()+1==m.month&&s.getDate()==m.day?t.attr("class","date_item date_today"):t.attr("class","date_item"),_(a.year,a.month,a.day,e),g($(this)))}),$(".today").hammer().on("tap",function(t){return n(1,s.getFullYear(),s.getMonth()+1,s.getDate()),!1}),$(".slide_wrap").hammer().on("swipeleft",function(t){return n(1),t.preventDefault(),t.gesture.preventDefault(),!1}),$(".slide_wrap").hammer().on("swiperight",function(t){return n(-1),t.preventDefault(),t.gesture.preventDefault(),!1})}return{init:function(){h=$(document).width(),$(".date_list").eq(0).css("width",h),$(".date_list").eq(1).css({width:h,left:h}),"iOS"==mobile.platform&&(a(document.getElementById("date_list_0"),0),a(document.getElementById("date_list_1"),0)),t(),_(),w()}}}();$(function(){Calendar.init()});