📄 popcalendar.js
字号:
jscalendarPopDownMonth(); var sHTML = ""; if (!jscalendarYearConstructed) { sHTML = "<tr><td align='center' onmouseover='this.className=\""+jscalendarThemePrefix+"-dropdown-select-style\"' onmouseout='clearInterval(jscalendarIntervalID1); this.className=\""+jscalendarThemePrefix+"-dropdown-normal-style\"' onmousedown='clearInterval(jscalendarIntervalID1);jscalendarIntervalID1=setInterval(\"jscalendarDecYear()\",30)' onmouseup='clearInterval(jscalendarIntervalID1)'>-</td></tr>"; var j = 0; jscalendarNStartingYear = jscalendarYearSelected-3; for (i=jscalendarYearSelected-3; i<=(jscalendarYearSelected+3); i++) { var sName = i; if (i==jscalendarYearSelected) sName = "<b>"+sName+"</b>"; sHTML += "<tr><td id='y"+j+"' onmouseover='this.className=\""+jscalendarThemePrefix+"-dropdown-select-style\"' onmouseout='this.className=\""+jscalendarThemePrefix+"-dropdown-normal-style\"' onclick='jscalendarSelectYear("+j+");event.cancelBubble=true'> "+sName+" </td></tr>"; j++; } sHTML += "<tr><td align='center' onmouseover='this.className=\""+jscalendarThemePrefix+"-dropdown-select-style\"' onmouseout='clearInterval(jscalendarIntervalID2); this.className=\""+jscalendarThemePrefix+"-dropdown-normal-style\"' onmousedown='clearInterval(jscalendarIntervalID2);jscalendarIntervalID2=setInterval(\"jscalendarIncYear()\",30)' onmouseup='clearInterval(jscalendarIntervalID2)'>+</td></tr>"; document.getElementById("selectYear").innerHTML = "<table width='44' class='"+jscalendarThemePrefix+"-dropdown-style' onmouseover='clearTimeout(jscalendarTimeoutID2)' onmouseout='clearTimeout(jscalendarTimeoutID2);jscalendarTimeoutID2=setTimeout(\"jscalendarPopDownYear()\",100)' cellspacing='0'>"+sHTML+"</table>"; jscalendarYearConstructed = true; }}function jscalendarPopDownYear() { clearInterval(jscalendarIntervalID1); clearTimeout(jscalendarTimeoutID1); clearInterval(jscalendarIntervalID2); clearTimeout(jscalendarTimeoutID2); jscalendarCrossYearObj.visibility= "hidden";}function jscalendarPopUpYear() { var leftOffset; jscalendarConstructYear(); jscalendarCrossYearObj.visibility = (jscalendarDom||jscalendarIe) ? "visible" : "show"; leftOffset = parseInt(jscalendarCrossobj.left) + document.getElementById("spanYear").offsetLeft; if (jscalendarIe) leftOffset += 6; jscalendarCrossYearObj.left = leftOffset + "px"; jscalendarCrossYearObj.top = parseInt(jscalendarCrossobj.top) + 26 + "px";}/*** calendar ***/function jscalendarWeekNbr(n) { // Algorithm used: // From Klaus Tondering's Calendar document (The Authority/Guru) // hhtp://www.tondering.dk/claus/calendar.html // a = (14-month) / 12 // y = year + 4800 - a // m = month + 12a - 3 // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045 // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461 // L = d4 / 1460 // d1 = ((d4 - L) mod 365) + L // WeekNumber = d1 / 7 + 1 year = n.getFullYear(); month = n.getMonth() + 1; if (jscalendarStartAt == 0) day = n.getDate() + 1; else day = n.getDate(); a = Math.floor((14-month) / 12); y = year + 4800 - a; m = month + 12 * a - 3; b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400); J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045; d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461; L = Math.floor(d4 / 1460); d1 = ((d4 - L) % 365) + L; week = Math.floor(d1/7) + 1; return week;}function jscalendarConstructCalendar () { var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31); var dateMessage; var startDate = new Date (jscalendarYearSelected,jscalendarMonthSelected,1); var endDate; if (jscalendarMonthSelected==1){ endDate = new Date (jscalendarYearSelected,jscalendarMonthSelected+1,1); endDate = new Date (endDate - (24*60*60*1000)); numDaysInMonth = endDate.getDate(); }else numDaysInMonth = aNumDays[jscalendarMonthSelected]; datePointer = 0; dayPointer = startDate.getDay() - jscalendarStartAt; if (dayPointer<0) dayPointer = 6; var sHTML = "<table border=0 class='"+jscalendarThemePrefix+"-body-style'><tr>" if (jscalendarShowWeekNumber==1) sHTML += "<td width=27><b>" + jscalendarWeekString + "</b></td><td width=1 rowspan=7 class='"+jscalendarThemePrefix+"-weeknumber-div-style'><img src='"+jscalendarImgDir+"divider.gif' width=1></td>"; for (i=0; i<7; i++) sHTML += "<td width='27' align='right'><B>"+ jscalendarDayName[i]+"</B></td>"; sHTML +="</tr><tr>"; if (jscalendarShowWeekNumber==1) sHTML += "<td align=right>" + jscalendarWeekNbr(startDate) + " </td>"; for ( var i=1; i<=dayPointer;i++ ) sHTML += "<td> </td>"; for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ ){ dayPointer++; sHTML += "<td align=right>"; var sStyle=jscalendarThemePrefix+"-normal-day-style"; //regular day if ((datePointer==jscalendarDateNow)&&(jscalendarMonthSelected==jscalendarMonthNow)&&(jscalendarYearSelected==jscalendarYearNow)) //today { sStyle = jscalendarThemePrefix+"-current-day-style"; } else if (dayPointer % 7 == (jscalendarStartAt * -1) +1) //end-of-the-week day { sStyle = jscalendarThemePrefix+"-end-of-weekday-style"; } //selected day if ((datePointer==jscalendarOdateSelected) && (jscalendarMonthSelected==jscalendarOmonthSelected) && (jscalendarYearSelected==jscalendarOyearSelected)) { sStyle += " "+jscalendarThemePrefix+"-selected-day-style"; } sHint = "" for (k=0;k<jscalendarHolidaysCounter;k++) { if ((parseInt(jscalendarHolidays[k].d)==datePointer)&&(parseInt(jscalendarHolidays[k].m)==(jscalendarMonthSelected+1))) { if ((parseInt(jscalendarHolidays[k].y)==0)||((parseInt(jscalendarHolidays[k].y)==jscalendarYearSelected)&&(parseInt(jscalendarHolidays[k].y)!=0))) { sStyle += " "+jscalendarThemePrefix+"-holiday-style"; sHint+=sHint==""?jscalendarHolidays[k].desc:"\n"+jscalendarHolidays[k].desc } } } var regexp= /\"/g sHint=sHint.replace(regexp,"""); sSelectStyle = sStyle+" "+jscalendarThemePrefix+"-would-be-selected-day-style"; sNormalStyle = sStyle; dateMessage = "onmousemove='window.status=\""+jscalendarSelectDateMessage.replace("[date]",jscalendarConstructDate(datePointer,jscalendarMonthSelected,jscalendarYearSelected))+"\"' onmouseout='this.className=\""+sNormalStyle+"\"; window.status=\"\"' " sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" href='javascript:jscalendarDateSelected="+datePointer+";jscalendarCloseCalendar();' onmouseover='this.className=\""+sSelectStyle+"\";' > " + datePointer + " </a>"; if ((dayPointer+jscalendarStartAt) % 7 == jscalendarStartAt) { sHTML += "</tr><tr>"; if ((jscalendarShowWeekNumber==1)&&(datePointer<numDaysInMonth)) sHTML += "<td align=right>" + (jscalendarWeekNbr(new Date(jscalendarYearSelected,jscalendarMonthSelected,datePointer+1))) + " </td>"; } } document.getElementById("content").innerHTML = sHTML; document.getElementById("spanMonth").innerHTML = " " + jscalendarMonthName[jscalendarMonthSelected] + " <IMG id='changeMonth' SRC='"+jscalendarImgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"; document.getElementById("spanYear").innerHTML = " " + jscalendarYearSelected + " <IMG id='changeYear' SRC='"+jscalendarImgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"; document.getElementById("jscalendarCloseButton").innerHTML = "<img src='"+jscalendarImgDir+"close.gif' width='15' height='13' border='0' alt='Close the Calendar'>";}function jscalendarPopUpCalendar(ctl, ctl2, format){ if (jscalendarBPageLoaded){ if ( jscalendarCrossobj.visibility == "hidden" ) { jscalendarCtlToPlaceValue = ctl2; jscalendarDateFormat=format; var formatChar = " "; aFormat = jscalendarDateFormat.split(formatChar) if (aFormat.length<3){ formatChar = "/"; aFormat = jscalendarDateFormat.split(formatChar) if (aFormat.length<3){ formatChar = "."; aFormat = jscalendarDateFormat.split(formatChar) if (aFormat.length<3){ formatChar = "-"; aFormat = jscalendarDateFormat.split(formatChar) if (aFormat.length<3){ // invalid date format formatChar=""; } } } } var tokensChanged = 0; if ( formatChar != "" ){ // use user's date aData = ctl2.value.split(formatChar) for (i=0;i<3;i++){ if ((aFormat[i]=="d") || (aFormat[i]=="dd")){ jscalendarDateSelected = parseInt(aData[i]); tokensChanged++; }else if ((aFormat[i]=="m") || (aFormat[i]=="mm") || (aFormat[i]=="M") || (aFormat[i]=="MM")){ jscalendarMonthSelected = parseInt(aData[i]) - 1; tokensChanged++; }else if (aFormat[i]=="yyyy"){ jscalendarYearSelected = parseInt(aData[i]); tokensChanged++; }else if (aFormat[i]=="yy"){ newYear = parseInt(aData[i]); if(newYear>50) jscalendarYearSelected = 1900+newYear; else jscalendarYearSelected = 2000+newYear; tokensChanged++ }else if (aFormat[i]=="mmm" || aFormat[i]=="MMM"){ for (j=0; j<12; j++){ if (aData[i]==jscalendarMonthName[j]){ jscalendarMonthSelected=j; tokensChanged++; } } }else if (aFormat[i]=="mmmm" || aFormat[i]=="MMMM"){ for (j=0; j<12; j++){ if (aData[i]==jscalendarMonthName2[j]){ jscalendarMonthSelected=j; tokensChanged++; } } } } } if ((tokensChanged!=3)||isNaN(jscalendarDateSelected)||isNaN(jscalendarMonthSelected)||isNaN(jscalendarYearSelected)){ jscalendarDateSelected = jscalendarDateNow; jscalendarMonthSelected = jscalendarMonthNow; jscalendarYearSelected = jscalendarYearNow; } jscalendarPopUpCalendar_Show(ctl); }else{ jscalendarHideCalendar(); if (jscalendarCtlNow!=ctl) jscalendarPopUpCalendar(ctl, ctl2, format); } jscalendarCtlNow = ctl; }}function jscalendarPopUpCalendarForInputDate(clientId, format){ if (jscalendarBPageLoaded){ jscalendarMyFacesCtlType = "x:inputDate"; jscalendarMyFacesInputDateClientId = clientId; jscalendarDateFormat=format; jscalendarDateSelected = parseInt( document.getElementById(clientId+".day").value ); jscalendarMonthSelected = parseInt( document.getElementById(clientId+".month").value )-1; jscalendarYearSelected = parseInt( document.getElementById(clientId+".year").value ); jscalendarCtlNow = document.getElementById(clientId+".day"); jscalendarPopUpCalendar_Show(document.getElementById(clientId+".day")); }}function jscalendarPopUpCalendar_Show(ctl){ jscalendarOdateSelected = jscalendarDateSelected; jscalendarOmonthSelected = jscalendarMonthSelected; jscalendarOyearSelected = jscalendarYearSelected; var leftpos = 0; var toppos = 0; var aTag = ctl; do { aTag = aTag.offsetParent; leftpos += aTag.offsetLeft; toppos += aTag.offsetTop; } while(aTag.tagName!="BODY"); jscalendarCrossobj.left = jscalendarFixedX==-1 ? ctl.offsetLeft + leftpos + "px": jscalendarFixedX; jscalendarCrossobj.top = jscalendarFixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 + "px": jscalendarFixedY; jscalendarConstructCalendar (1, jscalendarMonthSelected, jscalendarYearSelected); jscalendarCrossobj.visibility=(jscalendarDom||jscalendarIe)? "visible" : "show"; jscalendarHideElement( 'SELECT', document.getElementById("calendar") ); jscalendarHideElement( 'APPLET', document.getElementById("calendar") ); jscalendarBShow = true;}document.onkeypress = function jscalendarHidecal1 () { if (event.keyCode==27) jscalendarHideCalendar();}document.onclick = function jscalendarHidecal2 () { if (!jscalendarBShow) jscalendarHideCalendar(); jscalendarBShow = false;}if(jscalendarIe) jscalendarInit();else window.onload=jscalendarInit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -