📄 calendarff.js
字号:
/* alin */
/* Email:caoailin111@sohu.com */
/* QQ:38062022 */
/* Creation date: 2004-6-13 */
/* author:star */
/* MSN: zdj_1226@hotmail.com */
/* Modify date: 2007-03-03 */
/* For example
var ele={};
ele.inputEle = "testTxt";
ele.eventEle = "btnC";
ele.eventType = "click";
//wmcClass._self.registerClickFor("testTxt");
wmcClass._self.registerClickFor("text2");
wmcClass._self.registerClickFor("dExecuteHistory");
wmcClass._self.bindEventFor(ele);
doc.prepare(function(){
wmcClass._self.init();
});
*/
//var WatermarkCalendar = {};
function wmcClass(){
var date = new Date();
this.today={};
this.today.Year=date.getFullYear();//getYear();
this.today.Month=date.getMonth()+1;
this.today.Day=date.getDate();
this.currentInput="";
this.currentEventEle="";
this.yearRange=5;/*-5,+5*/
this.selectedDate={Year:0,Month:0,Day:0};
this.regional = [];
this.regional[''] = {
allowDrag:false,
clearText: 'Clear',
closeText: '关闭',
prevMonthText: '‹',
nextMonthText: '›',
prevMonthTitle: "减少月份",
nextMonthTitle: "增加月份",
prevYearText:"«",
nextYearText:"»",
prevYearTitle: "减少年份",
nextYearTitle: "增加年份",
prevPageText:"上翻",
nextPageText:"下翻",
currentText: '今日',
yearText : "年",
monthText : "月",
weekNames:["日","一","二","三","四","五","六"],
//dayNames: ['Su','Mo','Tu','We','Th','Fr','Sa'],
monthNames: ['1','2','3','4','5','5',
'7','8','9','10','11','12'],
dateFormat: 'DMY/'
};
var wmcIDList={
wmcCSS:"wmc_css",
wmcMain:"wmc_main_div",
wmcShadowDiv :"wmc_shadow_div",
wmcTopTbl :"wmc_top_tbl",
wmcWeekTbl:"wmc_week_tbl",
wmcDateTbl:"wmc_date_tbl",
wmcBottomTbl:"wmc_bottom_tbl",
wmcLayerIfrm:"wmc_layer_ifrm" ,
wmcTopYearTd:"wmc_top_year_td",
wmcTopMonthTd:"wmc_top_month_td",
wmcYearMonthLayerDiv:"wmc_yearmonth_layer_div",
wmcYearMonthLayerTbl:"wmc_yearmonth_layer_tbl"
};
this.defaults = {
};
this.extend(this.defaults, this.regional['']);
this.extend(this, wmcIDList);
wmcClass._self = this;
}
wmcClass._self=null;
wmcClass.isReady = false;
wmcClass.readyList = [];
wmcClass.prototype = {
init:function(){
wmcClass.isReady = true;
this.createElement();
this.renderHTML();
this.setDateFromField();
this.noCheckHide=false;
//this.renderStyle();
try{
this.addEventHandler(document,"click",function(){var evt= arguments[0]||window.event;wmcClass._self.checkExternalClick(evt)});
if(wmcClass.readyList){
for(var i=0,lenght=wmcClass.readyList.length;i<lenght;i++){
this.bindEventFor(wmcClass.readyList[i]);
}
wmcClass.readyList = null;
}
if(this.allowDrag){
var temp = this.$(this.wmcTopTbl);
this.registerEventHandler(temp,"mousedown",function(){var evt= arguments[0]||event;wmcClass._self.startMove(evt)});
this.registerEventHandler(temp,"mousemove",function(){var evt= arguments[0]||event;wmcClass._self.move(evt)});
this.addEventHandler(temp,"mouseout",function(){wmcClass._self.stopMove()});
this.addEventHandler(temp,"mouseup",function(){wmcClass._self.stopMove()});
}
}catch(ex){}
},
createElement:function(){
// var style = document.createElement("style");
// style.id = this.wmcCSS;
// document.body.previousSibling.appendChild(style);
var div=document.createElement("div");
div.id = this.wmcMain;
div.className = 'wmc_main';
this.registerEventHandler(div,"selectstart",function(){return false;});
this.registerEventHandler(div,"contextmenu",function(){return false;});
this.registerEventHandler(div,"mousedown",function(){var evt= window.event||arguments[0]; if(evt.button==2)this.style.display="none"});
document.body.appendChild(div);
},
renderHTML : function(){
var week=this.defaults.weekNames;
var cHtml = [];
var _self = this;
cHtml.push("<iframe id='"+this.wmcLayerIfrm+"' class='wmc_ifrm_over' scrolling=\"no\" frameborder=\"0\"></iframe>");
//watermark
cHtml.push("<div id='"+this.wmcShadowDiv+"' class='wmc_shadow'></div>");
cHtml.push("<div style='position:absolute;left:0px;top:0px;z-index:1;border:1px solid #909EFF;'>");
//top
cHtml.push("<table class='wmc_top' id='"+this.wmcTopTbl+"' onmousedown='' onmouseup='' onmousemove=''>");
cHtml.push("<tr>");
cHtml.push("<td onmouseover='this.style.color=\"black\"' onmouseout='this.style.color=\"\"' onclick='wmcClass._self.prevYearMonth(this,\"y\");' title='"+this.defaults.prevYearTitle+"' class='wmc_top_next_pre'>"+this.defaults.prevYearText+"</td>");
cHtml.push("<td onmouseover='this.style.color=\"black\"' onmouseout='this.style.color=\"\"' onclick='wmcClass._self.prevYearMonth(this,\"m\");' title='"+this.defaults.prevMonthTitle+"' class='wmc_top_next_pre'>"+this.defaults.prevMonthText+"</td>");
cHtml.push("<td onmouseover=\"this.className='wmc_move1'\" onmouseout=\"this.className='';wmcClass._self.ymLayerDelayHidden(null);\" onclick='wmcClass._self.renderYMLayerHTML(this.value,\"y\");' align=center class='wmc_top_year_month'></td>");
cHtml.push("<td onmouseover=\"this.className='wmc_move1';\" onmouseout=\"this.className='';wmcClass._self.ymLayerDelayHidden(null);\" onclick='wmcClass._self.renderYMLayerHTML(this.value,\"m\");' align=center class='wmc_top_year_month'></td>");
cHtml.push("<td onmouseover='this.style.color=\"black\"' onmouseout='this.style.color=\"\"' onclick='wmcClass._self.nextYearMonth(this,\"m\");' title='"+this.defaults.nextMonthTitle+"' class='wmc_top_next_pre'>"+this.defaults.nextMonthText+"</td>");
cHtml.push("<td onmouseover='this.style.color=\"black\"' onmouseout='this.style.color=\"\"' onclick='wmcClass._self.nextYearMonth(this,\"y\");' title='"+this.defaults.nextYearTitle+"' class='wmc_top_next_pre'>"+this.defaults.nextYearText+"</td>");
cHtml.push("</tr></table>");
//week
cHtml.push("<table class='wmc_week' id='"+this.wmcWeekTbl+"'><tr>");
for(i=0;i<7;i++)
cHtml.push("<td>"+week[i]+"</td>");
cHtml.push("</tr></table>");
//date
cHtml.push("<table class='wmc_date' id='"+this.wmcDateTbl+"' cellspacing=2 cellpadding=0>");
for(i=0;i<6;i++){
cHtml.push("<tr>");
for(j=0;j<7;j++)
cHtml.push("<td width=10% onmouseover='wmcClass._self.mouseOver(this);' onmouseout='wmcClass._self.mouseOut(this);'></td>");
cHtml.push("</tr>");
}
cHtml.push("</table>");
//close today
cHtml.push("<table class='wmc_bottom' id='"+this.wmcBottomTbl+"' cellspacing=2 cellpadding=0>");
cHtml.push("<tr>");
cHtml.push("<td colspan='3' onmouseover='this.className=\"wmc_bottom_over\"' onmouseout='this.className=\"wmc_bottom_out\"' onclick='wmcClass._self.gotoToday();'>"+this.defaults.currentText+"</td>");
cHtml.push("<td colspan='3' onmouseover='this.className=\"wmc_bottom_over\"' onmouseout='this.className=\"wmc_bottom_out\"' onclick='wmcClass._self.hideCalendar()'>"+this.defaults.closeText+"</td>");
cHtml.push("</tr>");
cHtml.push("</table>");
cHtml.push("</div>");
//select layer year month
cHtml.push("<div class='wmc_ym_layer' id='"+this.wmcYearMonthLayerDiv+"' onmouseover='wmcClass._self.ymLayerDelayShow(this)' onmouseout='wmcClass._self.ymLayerDelayHidden(this)'></div>");
this.$(this.wmcMain).innerHTML = cHtml.join('');
},
renderYMLayerHTML : function(value,type){
this.noCheckHide=true;
if(wmcClass.timer_YMLayer!=null)clearTimeout(wmcClass.timer_YMLayer);
var ymHTML = [];
var wmcYMLayerDiv,year=month=0;
var ele = null;
if(type=="y")ele = this.$(this.wmcTopYearTd);
else ele= this.$(this.wmcTopMonthTd);
year=month=parseInt(value,10);
ymHTML.push("<table id='"+this.wmcYearMonthLayerTbl+"' cellspacing=0 cellpadding=2>");
if(type=="y"){
ymHTML.push("<tr><td onclick='wmcClass._self.renderYMLayerHTML("+(year-this.yearRange*2)+",\"y\");'>"+this.defaults.prevPageText+"</td></tr>");
for(var i=year-this.yearRange;i<year+this.yearRange;i++){
if(i==ele.value)
ymHTML.push("<tr style='background-color:#909eff'><td style='color:black;' onclick='wmcClass._self.adjustYearMonth("+i+",\"y\")' value="+i+">"+i+this.defaults.yearText+"</td></tr>");
else
ymHTML.push("<tr><td onmouseout='wmcClass._self.ymLayerMouseOver(this)' onmouseover='wmcClass._self.ymLayerMouseOver(this)' onclick='wmcClass._self.adjustYearMonth("+i+",\"y\")' value="+i+">"+i+this.defaults.yearText+"</td></tr>");
}
ymHTML.push("<tr><td style='cursor:pointer' onclick='wmcClass._self.renderYMLayerHTML("+(year+this.yearRange*2)+",\"y\");' align=center>"+this.defaults.nextPageText+"</td></tr>");
}else{
for(i=1;i<13;i++){
if(month==i)
ymHTML.push("<tr style='background-color:#909eff'><td style='color:black;' onclick='wmcClass._self.adjustYearMonth("+i+",\"m\")' value="+i+">"+i+this.defaults.monthText+"</td></tr>");
else
ymHTML.push("<tr><td onmouseout='wmcClass._self.ymLayerMouseOver(this)' onmouseover='wmcClass._self.ymLayerMouseOver(this)' onclick='wmcClass._self.adjustYearMonth("+i+",\"m\")' value="+i+">"+i+this.defaults.monthText+"</td></tr>");
}
}
ymHTML.push("</table>");
//ymHTML.push("<iframe id='wmc_year_layer_ifrm' style=\"height:315px;\" scrolling=\"no\" frameborder=\"0\" width=" + (ele.offsetWidth + 4) + "></iframe>");
wmcYMLayerDiv=this.$(this.wmcYearMonthLayerDiv)
wmcYMLayerDiv.innerHTML='';
wmcYMLayerDiv.innerHTML=ymHTML.join("");
wmcYMLayerDiv.style.display="block";
this.setPosition(wmcYMLayerDiv,ele.offsetTop+ele.offsetHeight,ele.offsetLeft);
},
renderStyle : function(){
// var style=new Array();
// style.push(".wmc_main{position:absolute;width:142px;height:165px;left:0px;top:-300px;z-index:9999;text-align:center;}");
// style.push(".wmc_top{width:140px;font-size:12px;color:white;cursor:default;background-color:#909EFF;}");
// style.push(".wmc_week{width:140px;font-size:12px;height:22px;line-height:22px;text-align:center;background-color:#DfDfff;}");
// style.push(".wmc_date{width:140px;font-size:12px;cursor:pointer;}");
// style.push(".wmc_date td{height:16px;text-align:center;}");
// style.push(".wmc_bottom{width:140px;font-size:12px;cursor:pointer;color:#03c;text-align:center;}");
// style.push(".wmc_bottom_over{text-decoration:underline;}");
// style.push(".wmc_bottom_out{text-decoration:none;}");
// style.push(".wmc_mover{background-color:#909EFF;}");
// style.push(".wmc_top td{border:1px solid #909EFF;}");
// style.push(".wmc_move1{border:1px solid #5d5d5d;background-color:#f4f4f4;color:#909eff;}");
// style.push("label.gray{color:#ccc;cursor:default;}");
// style.push(".wmc_shadow{width:142px;position:absolute;left:0px;top:0;font-family: Arial Black;font-size:50px;line-height:170px;color:#d4d4d4;z-index:1;background:#fff}");
// style.push(".wmc_ym_layer{position:absolute;left:0px;top:0px;z-index:1;}");
// style.push(".wmc_ym_layer table{position:absolute;left:0px;top:0px;z-index:1;border:1px solid #5d5d5d;background-color:#f4f4f4;color:#909eff;font-size:12px;}");
// style.push(".wmc_ym_layer table td{cursor:pointer;height:16px;text-align:center;white-space: nowrap;padding:0 10px}");
// style.push(".wmc_ifrm_over{margin:0 0 0 0;width:142px;height:170px;}");
// style.push(".wmc_top_next_pre{width:10px;cursor:pointer;font-weight:bold; font-family:Verdana;}");//font-family:Webdings;
// style.push(".wmc_top_year_month{border:solid 1px #909EFF;cursor:pointer;}")
// document.write("<style type='text/css' id='wmc_css'>");
// document.write(style.join(""));
// document.write("</style>");
// this.$(this.wmcCSS).innerHTML = style.join("");
},
adjustYearMonth:function(value,type){
this.noCheckHide=true;
this.$(this.wmcYearMonthLayerDiv).innerHTML = "";
if(this.currentYear==value || this.currentMonth==value){return;}
var year=month=0;
var eleTopYear,eleTopMonth;
eleTopYear = this.$(this.wmcTopYearTd);
eleTopMonth = this.$(this.wmcTopMonthTd);
if(type=="y"){
year = parseInt(value,10);
month = eleTopMonth.value;
eleTopYear.value = value;
eleTopYear.innerHTML = value+this.defaults.yearText;
}else{
year = eleTopYear.value;
month = value;
eleTopMonth.value = value;
eleTopMonth.innerHTML = value+this.defaults.monthText;
}
this.currentYear = year;
this.currentMonth = month;
this.adjustDate();
},
adjustDate:function(){
this.updateCalendar(new Date(this.currentYear,this.currentMonth-1,1));
},
updateCalendar: function(wmcDate) {
var wmcDateTbl = this.$(this.wmcDateTbl);
var wmcTop = this.$(this.wmcTopTbl);
var day=wmcDate.getDay();
var year = wmcDate.getFullYear();
var month = wmcDate.getMonth()+1;
var rowIndex=0,cellIndex=0,dayIndex=0;
var length=new Array(31,30,31,30,31,30,31,31,30,31,30,31);
length[1]=((this.currentYear%4==0)&&(this.currentYear%100!=0)||(this.currentYear%400==0))?29:28;
var wmcTempObj = null;
for(var i=0;i<wmcDateTbl.rows.length;i++){
for(var k=0;k<wmcDateTbl.rows[i].cells.length;k++){
cellIndex = (dayIndex+day)%7;
rowIndex =parseInt((dayIndex+day)/7,10);
wmcTempObj=wmcDateTbl.rows[rowIndex].cells[cellIndex];
wmcTempObj.className="";
wmcTempObj.style.color="";
wmcTempObj.style.backgroundColor="";
wmcTempObj.style.cursor="pointer";
wmcTempObj.innerHTML=dayIndex+1;
if(this.selectedDate.Day == dayIndex+1 && this.selectedDate.Month==month && this.selectedDate.Year == year){
wmcTempObj.style["backgroundColor"]="#909EFF";
}
if(this.today.Day == dayIndex+1 && this.today.Month==month && this.today.Year == year){
wmcTempObj.style["color"]="blue";
}
wmcTempObj.onclick=function(){wmcClass._self.selectDate(this.innerHTML)};
if(new Date(year,month-1,dayIndex+1).getDay()==6
||new Date(year,month-1,dayIndex+1).getDay()==0){
wmcTempObj.style.color='red';
}
if(dayIndex<length[month-1]){
dayIndex++;
}else{
break;
}
}
}
var _preMonth =month - 1;
switch(_preMonth){
case 0:_preMonth=11;break;/*1月的上一个月份*/
//case 1:_preMonth=0;break;/*2月的上一个月份*/
default:_preMonth = _preMonth -1;break;
}
for(i=0;i<day;i++){
//wmcDateTbl.rows[0].cells[day-1-i].className = "gray";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -