📄 stcalendar.js
字号:
//* File:stCalendar.js
//* Author: zhuangtai
//* E-mail: zhuangtaizzt@gmail.com
//* Date:2008/01/31
if(typeof _STNS != "undefined" && _STNS.TIME && _STNS.UI)
{
with(_STNS.UI)
{
//* Class: _STNS.UI.CCalendar
_STNS.UI.CCalendar=_STNS.Class(CUIObj);
CCalendar.register("UI/CUIObj>CCalendar");
CCalendar.construct=function()
{
//this.aWeeks=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
this.aWeeks=["日","一","二","三","四","五","六"];
this.aGrids=[];
this.aWeekNO=[];
this.bShowWeek=true;
this.bShowTip=true;
this.bShowInfo=true;
this.bShowLoad=true;
this.bShowSummary=true;
this.bShowTopRow=true;
this.bShowBottomRow=true;
this.iCurYear=0;
this.iCurMonth=0;
this.iCurDate=0;
this.iCurDay=0;
this.sCurInfo="";
this.iCurTime=0;
this.iInfoMod=1;
this.aInfos=[];
this.aCals=[];
this.oLoad=new _STNS.UI.CCalendarLoadView;
this.oLoad.oCalendar=this;
this.oInfo=new _STNS.UI.CCalendarInfoView;
this.oInfo.oCalendar=this;
this.oTip=new _STNS.UI.CCalendarTipView;
this.oTip.oCalendar=this;
this.oDay=new _STNS.UI.CCalendarDayView;
this.oDay.oCalendar=this;
this.oSelect=new _STNS.UI.CCalendarSelectView;
this.oSelect.oCalendar=this;
with(_STNS.UI.CCalendar)
{
this.fsGetHTML=fsGetHTML;
this.fbGetEnt=fbGetEnt;
this.fvDestroy=fvDestroy;
this.fvShow=fvShow;
this.fbSetDate=fbSetDate;
this.fbUpDate=fbUpDate;
this.fbPreviousYear=fbPreviousYear;
this.fbNextYear=fbNextYear;
this.fbPreviousMonth=fbPreviousMonth;
this.fbNextMonth=fbNextMonth;
this.fbPreviousDay=fbPreviousDay;
this.fbNextDay=fbNextDay;
this.fbSelectToday=fbSelectToday;
this.fbSelectGrid=fbSelectGrid;
this.fsGetInfo=fsGetInfo;
this.fbLoadInfo=fbLoadInfo;
this.fbAddInfo=fbAddInfo;
this.fbDelInfo=fbDelInfo;
this.fbAddCal=fbAddCal;
this.fbAttachEnt("clickpreviousyear",fbPreviousYear);
this.fbAttachEnt("mouseoverpreviousyear",fbOverPY);
this.fbAttachEnt("mouseoutpreviousyear",fbOutPY);
this.fbAttachEnt("clicknextyear",fbNextYear);
this.fbAttachEnt("mouseovernextyear",fbOverNY);
this.fbAttachEnt("mouseoutnextyear",fbOutNY);
this.fbAttachEnt("clickpreviousmonth",fbPreviousMonth);
this.fbAttachEnt("mouseoverpreviousmonth",fbOverPM);
this.fbAttachEnt("mouseoutpreviousmonth",fbOutPM);
this.fbAttachEnt("clicknextmonth",fbNextMonth);
this.fbAttachEnt("mouseovernextmonth",fbOverNM);
this.fbAttachEnt("mouseoutnextmonth",fbOutNM);
this.fbAttachEnt("clickpreviousday",fbPreviousDay);
this.fbAttachEnt("mouseoverpreviousday",fbOverPD);
this.fbAttachEnt("mouseoutpreviousday",fbOutPD);
this.fbAttachEnt("clicknextday",fbNextDay);
this.fbAttachEnt("mouseovernextday",fbOverND);
this.fbAttachEnt("mouseoutnextday",fbOutND);
this.fbAttachEnt("clicktoday",fbSelectToday);
this.fbAttachEnt("mouseovertoday",fbOverTDG);
this.fbAttachEnt("mouseouttoday",fbOutTDG);
this.fbAttachEnt("clickday",fbSelectGrid);
this.fbAttachEnt("mouseoverday",fbOverGrid);
this.fbAttachEnt("mouseoutday",fbOutGrid);
}
var td=_STNS.TIME.fiGetNow();
_STNS.dTime.setTime(td);
this.fbSetDate(_STNS.dTime.getFullYear(),_STNS.dTime.getMonth()+1,_STNS.dTime.getDate());
};
CCalendar.fsGetHTML=function()
{
var s="",_r=_STNS,_u=_r.UI,_t=_r.TIME;
s+="<table cellpadding=0 cellspacing=0 class='calendar'>";
if(this.bShowTopRow)
s+="<tr>"+
"<td colspan="+(this.bShowWeek?8:7)+" align='center'>"+
"<table collpadding=0 cellspacing=0>"+
"<tr>"+
"<td class='calendarTLGrid calendarTPreviousYear' align='center'" +
" id='"+this.sUid+"_toppy' title='上一年'"+
" "+
_u.fsGetEnt(this,"mouseover","previousyear")+
" "+
_u.fsGetEnt(this,"mouseout","previousyear")+
" "+
_u.fsGetEnt(this,"click","previousyear")+
"> </td>"+
"<td class='calendarTGrid calendarTPreviousMonth' align='center'" +
" id='"+this.sUid+"_toppm' title='上一月'"+
" "+
_u.fsGetEnt(this,"mouseover","previousmonth")+
" "+
_u.fsGetEnt(this,"mouseout","previousmonth")+
" "+
_u.fsGetEnt(this,"click","previousmonth")+
"> </td>"+
"<td class='calendarTGrid calendarTMonthYear' align='center'"+
" id='"+this.sUid+"_showmy'"+
">"+this.iCurMonth+"/"+this.iCurYear+"</td>"+
"<td class='calendarTGrid calendarTNextMonth' align='center'" +
" id='"+this.sUid+"_topnm' title='下一月'"+
" "+
_u.fsGetEnt(this,"mouseover","nextmonth")+
" "+
_u.fsGetEnt(this,"mouseout","nextmonth")+
" "+
_u.fsGetEnt(this,"click","nextmonth")+
"> </td>"+
"<td class='calendarTRGrid calendarTNextYear' align='center'" +
" id='"+this.sUid+"_topny' title='下一年'"+
" "+
_u.fsGetEnt(this,"mouseover","nextyear")+
" "+
_u.fsGetEnt(this,"mouseout","nextyear")+
" "+
_u.fsGetEnt(this,"click","nextyear")+
"> </td>" +
"</table>"+
"</td>"+
"</tr>";
s+="<tr>"+
(this.bShowWeek?
"<td class='calendarLGrid calendarWeek'> </td>":
"")+
"<td class='"+
(this.bShowWeek?"calendarGrid":"calendarLGrid")+
" calendarWeek calendarRest' >"+this.aWeeks[0]+"</td>"+
"<td class='calendarGrid calendarWeek'>"+this.aWeeks[1]+"</td>"+
"<td class='calendarGrid calendarWeek'>"+this.aWeeks[2]+"</td>"+
"<td class='calendarGrid calendarWeek'>"+this.aWeeks[3]+"</td>"+
"<td class='calendarGrid calendarWeek'>"+this.aWeeks[4]+"</td>"+
"<td class='calendarGrid calendarWeek'>"+this.aWeeks[5]+"</td>"+
"<td class='calendarRGrid calendarWeek calendarRest'>"+this.aWeeks[6]+"</td>"+
"</tr>";
for(var i=0;i<6;i++)
{
s+= "<tr>";
if(this.bShowWeek)
s+= "<td valign='top' class='calendarLGrid calendarWeek'" +
" id='"+this.sUid+"_w"+i+"'"+
">" +
this.aWeekNO[i] +
"</td>";
for(var j=0;j<7;j++)
{
s+="<td valign='top' class='calendarDay"+
(j==6?" calendarRGrid":" calendarGrid")+
(j==6||j==0?" calendarRest":"")+
(j==0&&!this.bShowWeek?" calendarLGrid":" calendarGrid")+
"'" +
" id='"+this.sUid+"_d"+(i*7+j)+"'"+
" "+
_u.fsGetEnt(this,"mouseover","day")+
" "+
_u.fsGetEnt(this,"mouseout","day")+
" "+
_u.fsGetEnt(this,"click","day")+
">" +
"<span>"+
this.aGrids[i*7+j] +
"</span>";
if(this.bShowSummary)
{
s+= "<div style='position:relative;overflow:hidden;' class='calendarSummary'" +
" id='"+this.sUid+"_c"+(i*7+j)+"'" +
">"+
"<div>"+
"</div>"+
"</div>";
}
s+="</td>";
}
s+="</tr>";
}
if(this.bShowBottomRow)
s+= "<tr>"+
"<td colspan="+(this.bShowWeek?8:7)+" align='center'>"+
"<table cellpadding=0 cellspacing=0>"+
"<td class='calendarBPreviousYear' align='center'" +
" id='"+this.sUid+"_bottompy' title='上一年'"+
" "+
_u.fsGetEnt(this,"mouseover","previousyear")+
" "+
_u.fsGetEnt(this,"mouseout","previousyear")+
" "+
_u.fsGetEnt(this,"click","previousyear")+
"> </td>"+
"<td class='calendarBPreviousMonth' align='center'" +
" id='"+this.sUid+"_bottompm' title='上一月'"+
" "+
_u.fsGetEnt(this,"mouseover","previousmonth")+
" "+
_u.fsGetEnt(this,"mouseout","previousmonth")+
" "+
_u.fsGetEnt(this,"click","previousmonth")+
"> </td>"+
"<td class='calendarBPreviousDay' align='center'" +
" id='"+this.sUid+"_bottompd' title='上一天'"+
" "+
_u.fsGetEnt(this,"mouseover","previousday")+
" "+
_u.fsGetEnt(this,"mouseout","previousday")+
" "+
_u.fsGetEnt(this,"click","previousday")+
"> </td>"+
"<td class='calendarTodayGrid' colspan="+(this.bShowWeek?2:1)+" align='center'" +
" id='"+this.sUid+"_today' title='今天'" +
" "+
_u.fsGetEnt(this,"click","today")+
" "+
_u.fsGetEnt(this,"mouseover","today")+
" "+
_u.fsGetEnt(this,"mouseout","today")+
">" +
" " +
"</td>"+
"<td class='calendarBNextDay' align='center'" +
" id='"+this.sUid+"_bottomnd' title='下一天'"+
" "+
_u.fsGetEnt(this,"mouseover","nextday")+
" "+
_u.fsGetEnt(this,"mouseout","nextday")+
" "+
_u.fsGetEnt(this,"click","nextday")+
"> </td>"+
"<td class='calendarBNextMonth' align='center'" +
" id='"+this.sUid+"_bottomnm' title='下一月'"+
" "+
_u.fsGetEnt(this,"mouseover","nextmonth")+
" "+
_u.fsGetEnt(this,"mouseout","nextmonth")+
" "+
_u.fsGetEnt(this,"click","nextmonth")+
"> </td>"+
"<td class='calendarBNextYear' align='center'" +
" id='"+this.sUid+"_bottomny' title='下一年'"+
" "+
_u.fsGetEnt(this,"mouseover","nextyear")+
" "+
_u.fsGetEnt(this,"mouseout","nextyear")+
" "+
_u.fsGetEnt(this,"click","nextyear")+
"> </td></table>"+
"</td>"
"</tr>";
if(this.bShowInfo)
{
s+= "<tr>"+
"<td colspan="+(this.bShowWeek?8:7)+" class='calendarLRGrid'>" +
this.oInfo.fsGetHTML()+
"</td>"+
"</tr>";
}
if(this.bShowLoad)
{
s+="<tr>"+
"<td colspan="+(this.bShowWeek?8:7)+" class='calendarBLRGrid'>" +
this.oLoad.fsGetHTML()+
"</td>"+
"</tr>";
}
s+="</table>";
return s;
};
CCalendar.fbSetDate=function(y,m,d)
{
var _r=_STNS,_t=_STNS.TIME,dt=Date.UTC(y,m-1,d);
_r.dTime.setTime(dt);
var cy=_r.dTime.getFullYear(),cm=_r.dTime.getMonth()+1,cd=_r.dTime.getDate();
this.iCurTime=dt;
this.iCurYear=cy;
this.iCurMonth=cm;
this.iCurDate=cd;
this.iCurDay=_r.dTime.getDay();
var st=_t.fiGetFirstDay(cy,cm),l=_t.fiGetMonthLen(cy,cm);
if(st!=0)
var ll=_t.fiGetMonthLen(cy,cm-1);
for(var i=0;i<42;i++)
{
if(i>=st && i<l+st)
this.aGrids[i]=i-st+1;
else if(i<st)
this.aGrids[i]=ll-st+i+1;
else
this.aGrids[i]=i-l-st+1;
};
for(var i=0;i<6;i++)
{
switch(i)
{
case 0:
this.aWeekNO[i]=_t.fiGetWeek(cy,cm,this.aGrids[6]);
if(cy==1 && st!=0)
this.aWeekNO[i]=(cy-1)+"."+_t.fiGetWeek(cy-1,12,this.aGrids[0])+
"<br>"+
cy+"."+this.aWeekNO[i];
break;
case 1:case 2:case 3:
this.aWeekNO[i]=_t.fiGetWeek(cy,cm,this.aGrids[7*i]);
break;
case 4:case 5:
if( 7*i > l+st )
{
if(cm!=12)
this.aWeekNO[i]=_t.fiGetWeek(cy,cm+1,this.aGrids[7*i]);
else
{
this.aWeekNO[i]=_t.fiGetWeek(cy+1,1,this.aGrids[7*i]);
if(7*i <= l+st+7)
this.aWeekNO[i-1]=cy+"."+this.aWeekNO[i-1]+
"<br>"+
(cy+1)+"."+_t.fiGetWeek(cy+1,1,this.aGrids[7*i-1]);
}
}
else
this.aWeekNO[i]=_t.fiGetWeek(cy,cm,this.aGrids[7*i]);
break;
}
}
return true
};
CCalendar.fvShow=function()
{
document.write(this.fsGetHTML());
_STNS.fbAddLoad(new Function(this.sSelf+".fbUpDate()"));
};
CCalendar.fbGetEnt=function(e,o)
{
var et=e.type || e,oid=o.id,_r=_STNS;
with(this)
{
switch(et)
{
case "mouseover":
if(!o._ov && ((_r.bIsIE && e.srcElement && _r.fbIsPar(o,e.srcElement)) || (!_r.bIsIE &&e.target && _r.fbIsPar(o,e.target))))
{
o._ov=1;
if(oid==this.sUid+"_toppy" || oid==this.sUid+"_bottompy")
{
return fbFireEnt("mouseoverpreviousyear",[oid]);
};
if(oid==this.sUid+"_topny" || oid==this.sUid+"_bottomny")
{
return fbFireEnt("mouseovernextyear",[oid]);
};
if(oid==this.sUid+"_toppm" || oid==this.sUid+"_bottompm")
{
return fbFireEnt("mouseoverpreviousmonth",[oid]);
};
if(oid==this.sUid+"_topnm" || oid==this.sUid+"_bottomnm")
{
return fbFireEnt("mouseovernextmonth",[oid]);
};
if(oid==this.sUid+"_bottompd")
{
return fbFireEnt("mouseoverpreviousday",[oid]);
};
if(oid==this.sUid+"_bottomnd")
{
return fbFireEnt("mouseovernextday",[oid]);
};
if(oid==this.sUid+"_today")
{
return fbFireEnt("mouseovertoday",[oid]);
};
if(oid.indexOf(this.sUid+"_d")!=-1)
{
return fbFireEnt("mouseoverday",[oid]);
};
return fbFireEnt("mouseover");
}
break;
case "mouseout":
if(o._ov &&((_r.bIsIE && (!e.toElement || !_r.fbIsPar(o,e.toElement))) || !_r.bIsIE &&(!e.relatedTarget || !_r.fbIsPar(o,e.relatedTarget))))
{
o._ov=0;
if(oid==this.sUid+"_toppy" || oid==this.sUid+"_bottompy")
{
return fbFireEnt("mouseoutpreviousyear",[oid]);
};
if(oid==this.sUid+"_topny" || oid==this.sUid+"_bottomny")
{
return fbFireEnt("mouseoutnextyear",[oid]);
};
if(oid==this.sUid+"_toppm" || oid==this.sUid+"_bottompm")
{
return fbFireEnt("mouseoutpreviousmonth",[oid]);
};
if(oid==this.sUid+"_topnm" || oid==this.sUid+"_bottomnm")
{
return fbFireEnt("mouseoutnextmonth",[oid]);
};
if(oid==this.sUid+"_bottompd")
{
return fbFireEnt("mouseoutpreviousday",[oid]);
};
if(oid==this.sUid+"_bottomnd")
{
return fbFireEnt("mouseoutnextday",[oid]);
};
if(oid==this.sUid+"_today")
{
return fbFireEnt("mouseouttoday",[oid]);
};
if(oid.indexOf(this.sUid+"_d")!=-1)
{
return fbFireEnt("mouseoutday",[oid]);
};
return fbFireEnt("mouseout");
}
break;
case "click":
if(oid==this.sUid+"_toppy" || oid==this.sUid+"_bottompy")
{
return fbFireEnt("clickpreviousyear");
};
if(oid==this.sUid+"_topny" || oid==this.sUid+"_bottomny")
{
return fbFireEnt("clicknextyear");
};
if(oid==this.sUid+"_toppm" || oid==this.sUid+"_bottompm")
{
return fbFireEnt("clickpreviousmonth");
};
if(oid==this.sUid+"_topnm" || oid==this.sUid+"_bottomnm")
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -