1 window
.HuangLi
= window
.HuangLi
|| {};
8 return this.platform
=== 'Android';
11 return this.platform
=== 'iOS';
14 var ua
= navigator
.userAgent
;
15 if (ua
.match(/Android/i)) {
16 this.platform
= 'Android';
17 this.version
= parseFloat(ua
.slice(ua
.indexOf("Android") + 8));
19 else if (ua
.match(/iPhone|iPad|iPod/i)) {
20 this.platform
= 'iOS';
21 this.version
= parseFloat(ua
.slice(ua
.indexOf("OS") + 3));
32 * @param {string} url js文件的url地址
33 * @param {Function} callback 加载完成后的回调函数
35 var _getScript
= function(url
, callback
) {
36 var head
= document
.getElementsByTagName('head')[0],
37 js
= document
.createElement('script');
39 js
.setAttribute('type', 'text/javascript');
40 js
.setAttribute('src', url
);
45 var callbackFn
= function(){
46 if(typeof callback
=== 'function'){
51 if (document
.all
) { //IE
52 js
.onreadystatechange
= function() {
53 if (js
.readyState
== 'loaded' || js
.readyState
== 'complete') {
58 js
.onload
= function() {
66 $.getScript
= _getScript
;
72 var Footprint
= function () {};
73 // Default template settings, uses ASP/PHP
/JSP delimiters
, change the
74 // following template settings to use alternative delimiters.
75 var templateSettings
= {
76 evaluate
: /<%([\s\S]+?)%>/g,
77 interpolate
: /<%=([\s\S]+?)%>/g
80 // JavaScript micro-templating, similar to John Resig's implementation.
81 // Underscore templating handles arbitrary delimiters, preserves whitespace,
82 // and correctly escapes quotes within interpolated code.
83 Footprint
.compile
= function(str
, settings
) {
84 var c
= settings
|| templateSettings
;
85 var tmpl
= 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
86 'with(obj||{}){__p.push(\'' +
87 str
.replace(/\\/g, '\\\\')
89 .replace(c
.interpolate
, function(match
, code
) {
90 return "'," + code
.replace(/\\'/g, "'") + ",'";
92 .replace(c
.evaluate
|| null, function(match
, code
) {
93 return "');" + code
.replace(/\\'/g, "'")
94 .replace(/[\r\n\t]/g, ' ') + "__p.push('";
96 .replace(/\r/g, '\\r')
97 .replace(/\n/g, '\\n')
98 .replace(/\t/g, '\\t')
99 + "');}return __p.join('');";
100 return new Function('obj', tmpl
);
103 // Preserves template method for compatible with legacy call.
104 Footprint
.template
= function (str
, data
) {
105 var compilied
= Footprint
.compile(str
);
106 return compilied(data
);
109 if (typeof exports
!== "undefined") {
110 exports
.Footprint
= Footprint
;
112 window
.Footprint
= Footprint
;
115 //如果使用的是zepto,就添加扩展函数
117 $.template
= Footprint
.template
;
121 var Calendar
= (function(){
122 var hlurl
= 'http://cdn.tuijs.com/js/';
123 var hlMinYear
= 2008;
124 var hlMaxYear
= 2020;
125 var minYear
= 1891;//最小年限
126 var maxYear
= 2100;//最大年限
128 '<div class="date_item<%=itemCls%>" data-index="<%=index%>">',
129 ' <span class="date_icon<%=iconCls%>"><%=iconText%></span>',
130 ' <span class="date_day"><%=day%></span>',
131 ' <span class="date_lunar<%=fetvCls%>"><%=lunar%></span>',
135 var now
= new Date();
138 var panel
= [0,1]; //当前显示面板panel[0]
139 var pageWidth
= 0; //设备宽度
140 var slideIng
= false; //是否滑动中
143 var formateDayD4
= function(month
,day
){
145 month
= month
<10 ? '0'+month
: month
;
146 day
= day
<10 ? '0'+day
: day
;
147 return 'd'+month
+day
;
150 function formatDate(){
151 if(!current
)return '';
152 var year
= current
.year
;
153 var month
= current
.month
;
154 var day
= current
.day
;
155 month
= month
<10 ? '0'+month
: month
;
156 day
= day
<10 ? '0'+day
: day
;
157 return year
+'-'+month
+'-'+day
;
160 function setCurrentByNow(year
,month
,day
,pos
){
162 year
: year
|| now
.getFullYear(),
163 month
: month
|| now
.getMonth()+1,
164 day
: day
|| now
.getDate(),
171 if(HuangLi
['y'+current
.year
]){ //该年已有黄历数据
172 var hl
= HuangLi
['y'+current
.year
][formateDayD4(current
.month
,current
.day
)];
174 }else if(current
.year
>=hlMinYear
&& current
.year
<=hlMaxYear
){
175 $.getScript(hlurl
+'hl'+current
.year
+'.min.js',function(){
176 var hl
= HuangLi
['y'+current
.year
][formateDayD4(current
.month
,current
.day
)];
183 $('.hl_y_content').html(hl
.y
);
184 $('.hl_j_content').html(hl
.j
);
185 $('.date_hl').show();
187 $('.date_hl').hide();
191 function showInfo(_this
){
192 var currentLunar
= LunarCalendar
.solarToLunar(current
.year
,current
.month
,current
.day
);
193 var weekday
= new Date(current
.year
,current
.month
-1,current
.day
).getDay();
194 var weekList
= ['日','一','二','三','四','五','六'];
195 $('#toolbar h1').html(formatDate());
196 $('.date_lunar_info').html('农历'+currentLunar
.lunarMonthName
+currentLunar
.lunarDayName
+' 星期'+weekList
[weekday
]);
197 $('.date_gan_zhi').html(currentLunar
.GanZhiYear
+'年['+currentLunar
.zodiac
+'年] '+currentLunar
.GanZhiMonth
+'月 '+currentLunar
.GanZhiDay
+'日');
200 if(currentLunar
.term
) fetv
.push(currentLunar
.term
);
201 if(currentLunar
.lunarFestival
) fetv
.push(currentLunar
.lunarFestival
);
202 if(currentLunar
.solarFestival
) fetv
.push(currentLunar
.solarFestival
.split(' '));
203 $('.date_fetv').html(fetv
.length
>0 ? '节假日纪念日:'+fetv
.join(',') : '');
207 _this
.attr('class','date_item date_current');
215 function resetInfo(){
217 var oldObj
= $('#date_list_'+panel
[0]).find('.date_item').eq(current
.pos
);
218 if(now
.getFullYear()==current
.year
&& now
.getMonth()+1==current
.month
&& now
.getDate()==current
.day
){
219 oldObj
.attr('class','date_item date_today');
221 oldObj
.attr('class','date_item');
226 DATA
= LunarCalendar
.calendar(current
.year
,current
.month
,true);
229 var temp
= itemTemp
.join('');
231 for(var i
=0;i
<DATA
.monthData
.length
;i
++){
232 var itemData
= DATA
.monthData
[i
];
235 dateHtml
+='<div class="date_row">'
241 iconCls
: itemData
.worktime
? (itemData
.worktime
==1 ? ' worktime' : ' holiday') : '',
242 iconText
: itemData
.worktime
? (itemData
.worktime
==1 ? '班' : '休') : '',
243 fetvCls
: (itemData
.lunarFestival
|| itemData
.term
) ? ' lunar_fetv' : (itemData
.solarFestival
? ' solar_fetv' : ''),
248 if(now
.getFullYear()==itemData
.year
&& now
.getMonth()+1==itemData
.month
&& now
.getDate()==itemData
.day
){
249 itemCls
= ' date_today';
251 if(current
.year
==itemData
.year
&& current
.month
==itemData
.month
&& current
.day
==itemData
.day
){ //当前选中
252 itemCls
= ' date_current';
255 if(i
<DATA
.firstDay
|| i
>=DATA
.firstDay
+DATA
.monthDays
){ //非本月日期
256 itemCls
= ' date_other';
258 extendObj
.itemCls
= itemCls
;
260 var lunar
= itemData
.lunarDayName
;
262 if(itemData
.solarFestival
) lunar
= itemData
.solarFestival
;
263 if(itemData
.lunarFestival
) lunar
= itemData
.lunarFestival
;
264 if(itemData
.term
) lunar
= itemData
.term
;
265 extendObj
.lunar
= lunar
;
267 $.extend(itemData
,extendObj
);
269 dateHtml
+= $.template(temp
,itemData
);
276 $('#date_list_'+panel
[0]).html(dateHtml
);
282 function pageDate(offset
,_year
,_month
,_day
){
284 if(_year
&& _month
){ //直接指定
288 if(current
.month
+offset
<1){ //上一年
289 year
= current
.year
-1;
291 }else if(current
.month
+offset
>12){ //下一年
292 year
= current
.year
+1;
296 month
= current
.month
+offset
;
299 day
= _day
? _day
: (current
.day
> LunarCalendar
.getSolarMonthDays
[month
-1] ? LunarCalendar
.getSolarMonthDays
[month
-1] : current
.day
);
300 if(year
<minYear
|| year
>maxYear
)return; //超过范围
302 setCurrentByNow(year
,month
,day
);
308 function changePanel(){
309 var first
= panel
.shift();
313 function slide(offset
){
314 timer
&& clearTimeout(timer
);
315 setSlidePos({time
:0,pos
:0});
316 $('#date_list_'+panel
[0]).css({left
:offset
* pageWidth
}); //将要显示
317 $('#date_list_'+panel
[1]).css({left
:0}); //当前显示
320 timer
= setTimeout(function(){
321 setSlidePos({time
:300,pos
:pageWidth
* -1});
324 timer
= setTimeout(function(){
325 setSlidePos({time
:300,pos
:pageWidth
});
329 function setSlidePos(opt
){
330 var slide
= $('.date_slide')[0];
331 slide
.style
.webkitTransitionDuration
= opt
.time
+'ms';
332 setTranslate(slide
,opt
.pos
);
334 function setTranslate(obj
,pos
){
335 if(mobile
.platform
=='iOS'){//iOS下启用3d加速,安卓下有BUG,使用2d
336 obj
.style
.webkitTransform
= 'translate3d('+pos
+'px,0px,0px)';
338 obj
.style
.webkitTransform
= 'translate('+pos
+'px,0px)';
342 function addEvent(){ //base hammer.js
343 $('.date_list').hammer().on('tap','.date_item',function(){
344 var index
= $(this).attr('data-index');
345 index
= parseInt(index
,10);
346 var itemData
= DATA
.monthData
[index
];
348 if(index
<DATA
.firstDay
){ //上一个月
349 pageDate(-1,itemData
.year
,itemData
.month
,itemData
.day
);
350 }else if(index
>=DATA
.firstDay
+DATA
.monthDays
){//下一个月
351 pageDate(1,itemData
.year
,itemData
.month
,itemData
.day
);
354 setCurrentByNow(itemData
.year
,itemData
.month
,itemData
.day
,index
);
359 $('.today').hammer().on('tap',function(event
){
360 pageDate(1,now
.getFullYear(),now
.getMonth()+1,now
.getDate());
364 $('.slide_wrap').hammer().on('swipeleft',function(event
){
366 event
.preventDefault();
367 event
.gesture
.preventDefault();
371 $('.slide_wrap').hammer().on('swiperight',function(event
){
373 event
.preventDefault();
374 event
.gesture
.preventDefault();
379 function initPageElm(){
380 pageWidth
= $(document
).width();
381 $('.date_list').eq(0).css('width',pageWidth
);
382 $('.date_list').eq(1).css({'width':pageWidth
,'left':pageWidth
});
383 if(mobile
.platform
=='iOS'){//iOS启用3d,同时将子元素也设置一下,防止BUG
384 setTranslate(document
.getElementById('date_list_0'),0);
385 setTranslate(document
.getElementById('date_list_1'),0);