⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendar.js

📁 商城改进板全站代码
💻 JS
📖 第 1 页 / 共 4 页
字号:
					}
					else
						previousSelectedObject.className = thisCalendarObject.style.todayStyle["normal"].cssClass;
				}
				else if (thisDate.compare("month", thisCalendarObject.showDate) < 0) {
					if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
						previousSelectedObject.className = thisCalendarObject.style.weekendStyle.previousMonthDayStyle["normal"].cssClass;
					}
					else {
						previousSelectedObject.className = thisCalendarObject.style.previousMonthDayStyle["normal"].cssClass;
					}
				}
				else if (thisDate.compare("month", thisCalendarObject.showDate) == 0) {
					if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
						previousSelectedObject.className = thisCalendarObject.style.weekendStyle.dayStyle["normal"].cssClass;
					}
					else {
						previousSelectedObject.className = thisCalendarObject.style.dayStyle["normal"].cssClass;
					}
				}
				else {
					if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
						previousSelectedObject.className = thisCalendarObject.style.weekendStyle.nextMonthDayStyle["normal"].cssClass;
					}
					else {
						previousSelectedObject.className = thisCalendarObject.style.nextMonthDayStyle["normal"].cssClass;
					}
				}
			}
			thisCalendarObject.previousSelectedDate = new Date(date);
			thisCalendarObject.selectedDate = thisCalendarObject.previousSelectedDate;
			date = new Date(date);
			thisDate = new DateTime(thisCalendarObject.selectedDate);
			//alert(thisCalendarObject.compareDate("month", thisCalendarObject.selectedDate, thisCalendarObject.showDate));
			if (thisDate.compare("day", new Date()) == 0) {
				if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
					obj.className = thisCalendarObject.style.weekendStyle.todayStyle["selected"].cssClass;
					thisCalendarObject.hoverToday(obj);
				}
				else {
					obj.className = thisCalendarObject.style.todayStyle["selected"].cssClass;
					thisCalendarObject.hoverToday(obj);
				}
			}
			else if (thisDate.compare("month", thisCalendarObject.showDate) < 0) {
				if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()){
					obj.className = thisCalendarObject.style.weekendStyle.previousMonthDayStyle["selected"].cssClass;
					thisCalendarObject.hoverPreviousMonthDay(obj);
				}
				else {
					obj.className = thisCalendarObject.style.previousMonthDayStyle["selected"].cssClass;
					thisCalendarObject.hoverPreviousMonthDay(obj);
				}
			}
			else if (thisDate.compare("month", thisCalendarObject.showDate) == 0) {
				if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
					obj.className = thisCalendarObject.style.weekendStyle.dayStyle["selected"].cssClass;
					thisCalendarObject.hoverDay(obj);
				}
				else {
					obj.className = thisCalendarObject.style.dayStyle["selected"].cssClass;
					thisCalendarObject.hoverDay(obj);
				}
			}
			else if (thisDate.compare("month", thisCalendarObject.showDate) > 0){
				if (thisCalendarObject.style.weekendStyle.enabled && thisDate.isWeekendDay()) {
					obj.className = thisCalendarObject.style.weekendStyle.nextMonthDayStyle["selected"].cssClass;
					thisCalendarObject.hoverNextMonthDay(obj);
				}
				else {
					obj.className = thisCalendarObject.style.nextMonthDayStyle["selected"].cssClass;
					thisCalendarObject.hoverNextMonthDay(obj);
				}
			}
			if (document.getElementById(thisCalendarObject.controlToAcceptDate) != null)
				document.getElementById(thisCalendarObject.controlToAcceptDate).value = thisCalendarObject.formatDate(thisCalendarObject.selectedDate, thisCalendarObject.format["selected"]);
			if (document.getElementById(thisCalendarObject.objectName + "_footer")) {
				var footer = "<table align=\"center\" cellspacing=\"" + thisCalendarObject.style.footerStyle.cellSpacing + "\" cellpadding=\"" + thisCalendarObject.style.footerStyle.cellPadding + "\" border=\"" + thisCalendarObject.style.footerStyle.border + "\" bordercolor=\"" + thisCalendarObject.style.footerStyle.brdrColor + "\"" + thisCalendarObject.getClass(thisCalendarObject.style.footerStyle.cssClass) + thisCalendarObject.style.footerStyle.getStyleString() + "><tr><td width=\"50%\" align=\"left\" vAlign=\"middle\"><a href=\"javascript:" + thisCalendarObject.objectName + ".setToVisible('" + thisCalendarObject.formatDate(thisCalendarObject.selectedDate, "YYYY/MM/dd") + "');\"" + thisCalendarObject.getClass(thisCalendarObject.style.footerStyle["selected"].cssClass) + ">" + thisCalendarObject.formatDate(thisCalendarObject.selectedDate, thisCalendarObject.format.footer["selected"]) + "</a></td><td width=\"50%\" align=\"right\" vAlign=\"middle\"><a href=\"javascript:" + thisCalendarObject.objectName + ".selectToday(); " + thisCalendarObject.objectName + ".setToVisible('" + thisCalendarObject.formatDate(new Date(), "YYYY/MM/dd") + "');\"" + thisCalendarObject.getClass(thisCalendarObject.style.footerStyle["today"].cssClass) + " " + thisCalendarObject.style.footerStyle["today"].getStyleString() + " title=\"" + thisCalendarObject.toolTips["selectToday"] + "\">" + thisCalendarObject.formatDate(new Date(), thisCalendarObject.format.footer["today"]) + "</a></td></tr></table>";
				document.getElementById(thisCalendarObject.objectName + "_footer").innerHTML = footer;
			}
		}
		//alert("seletion finished!");
	}

	thisCalendarObject.formatDate = function(date, format) {
		if (date != null && (date instanceof DateTime) && format != null && format != "") {
			var dateString = format;
			dateString = dateString.replace(/YYYY/g, date.getFullYear());
			dateString = dateString.replace(/YY/g, date.getYear());
			dateString = dateString.replace(/MMMM/g, thisCalendarObject.monthNames[date.getMonth()]);
			dateString = dateString.replace(/MMM/g, thisCalendarObject.abbreviatedMonthNames[date.getMonth()]);
			dateString = dateString.replace(/MM/g, ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)));
			dateString = dateString.replace(/%M/g, date.getMonth() + 1);
			dateString = dateString.replace(/dddd/g, thisCalendarObject.dayNames[date.getDay()]);
			dateString = dateString.replace(/ddd/g, thisCalendarObject.abbreviatedDayNames[date.getDay()]);
			dateString = dateString.replace(/dd/g, (date.getDate()> 9 ? date.getDate() : "0" + date.getDate()));
			dateString = dateString.replace(/%d/g, date.getDate());
			return dateString;
		}
		else
			return "";
	}

	function previousMonth() {
		thisCalendarObject.showDate.addMonths(-1);
		thisCalendarObject.show();
	}

	function nextMonth() {
		thisCalendarObject.showDate.addMonths(1);
		thisCalendarObject.show();
	}

	function previousYear() {
		thisCalendarObject.showDate.addYears(-1);
		thisCalendarObject.show();
	}

	function nextYear() {
		thisCalendarObject.showDate.addYears(1);
		thisCalendarObject.show();
	}

	function show(e) {
		//do validation here
		if (thisCalendarObject.showDate == null || thisCalendarObject.showDate == "")
			thisCalendarObject.showDate = new DateTime();
		else
			thisCalendarObject.showDate = new DateTime(thisCalendarObject.showDate.toString());
		if (thisCalendarObject.selectedDate == null || thisCalendarObject.selectedDate == "")
			thisCalendarObject.selectedDate = new DateTime();
		else
			thisCalendarObject.selectedDate = new DateTime(thisCalendarObject.selectedDate);
		if (!isNaN(Date.parse(thisCalendarObject.selectableDateRange["beginDate"])) && !isNaN(Date.parse(thisCalendarObject.selectableDateRange["endDate"]))) {
			if (new DateTime(thisCalendarObject.selectableDateRange["beginDate"]).compare("day", thisCalendarObject.selectableDateRange["endDate"]) == 1 ) {
				var tempDate = thisCalendarObject.selectableDateRange["beginDate"];
				thisCalendarObject.selectableDateRange["beginDate"] = thisCalendarObject.selectableDateRange["endDate"];
				thisCalendarObject.selectableDateRange["endDate"] = tempDate;
			}
		}
		thisCalendarObject.firstDayOfWeek = thisCalendarObject.firstDayOfWeek % 7;
		//validation ends
		var calendar = "";
		var x, y;
		if (window.event) {
			x = parseInt(window.event.clientX) + parseInt(thisCalendarObject.offsetX) + parseInt(document.documentElement.scrollLeft) + parseInt(document.body.scrollLeft);
			y = parseInt(window.event.clientY) + parseInt(thisCalendarObject.offsetY) + parseInt(document.documentElement.scrollTop) + parseInt(document.body.scrollTop);
		}
		else if (e) {
			x = parseInt(e.clientX) + parseInt(window.scrollX);
			y = parseInt(e.clientY) + parseInt(window.scrollY);
		}

		//for the first time, create div object
		if (document.getElementById(thisCalendarObject.objectName + "_div") == null) {
			var oDiv = document.createElement("div");
			oDiv.id = thisCalendarObject.objectName + "_div";
			if ((typeof(x) != "undefined" || typeof(y) != "undefined") && thisCalendarObject.dynamicPosition) {
				oDiv.style.position = "absolute";
			}
			if (thisCalendarObject.style.cssClass != null && thisCalendarObject.style.cssClass != "")
				oDiv.className = thisCalendarObject.style.cssClass;
			if (document.getElementById(thisCalendarObject.controlToDisplayCalendar) == null || thisCalendarObject.dynamicPosition){
				document.body.appendChild(oDiv);
			}
			else {
				document.getElementById(thisCalendarObject.controlToDisplayCalendar).appendChild(oDiv);
			}
		}

		if (typeof(x) != "undefined" && document.getElementById(thisCalendarObject.objectName + "_div") && thisCalendarObject.dynamicPosition) {
			document.getElementById(thisCalendarObject.objectName + "_div").style.position = "absolute";
			document.getElementById(thisCalendarObject.objectName + "_div").style.left = x + "px";
		}
		if (typeof(y) != "undefined" && document.getElementById(thisCalendarObject.objectName + "_div") && thisCalendarObject.dynamicPosition) {
			document.getElementById(thisCalendarObject.objectName + "_div").style.position = "absolute";
			document.getElementById(thisCalendarObject.objectName + "_div").style.top = y + "px";
		}

		//begin drawing calendar
		calendar += "<table align=\"center\" cellspacing=\"" + thisCalendarObject.style.cellSpacing + "\" cellpadding=\"" + thisCalendarObject.style.cellPadding + "\" bordercolor=\"" + thisCalendarObject.style.brdrColor + "\" border=\"" + thisCalendarObject.style.border + "\" " +  thisCalendarObject.style.getStyleString() + ">";
		// drawing header
		if (thisCalendarObject.visible["header"]) {
			
			calendar += "<tr><td align=\"center\" colSpan=\"7\" " + thisCalendarObject.getClass(thisCalendarObject.style.headerStyle.cssClass) + " " + thisCalendarObject.style.headerStyle.getStyleString() + "><table align=\"center\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"width: 100%; height: 100%;\"><tr>";
			//var tempCol = 7;
			//alert(calendar);
			if (thisCalendarObject.visible["previousYear"]) {
				//tempCol--;
				calendar += "<td align=\"left\" valign=\"middle\" style=\"width:1px\"><a href=\"javascript:" + thisCalendarObject.objectName + ".previousYear();\"" + thisCalendarObject.getClass(thisCalendarObject.style.headerStyle["previousYear"].cssClass) + " " + thisCalendarObject.style.headerStyle["previousYear"].getStyleString() + " title=\"" + thisCalendarObject.toolTips["previousYear"] + "\">" + thisCalendarObject.text["previousYear"] + "</a></td>";
			}
			if (thisCalendarObject.visible["previousMonth"]) {
				//tempCol--;
				calendar += "<td align=\"left\" valign=\"middle\" style=\"width:1px\"><a href=\"javascript:" + thisCalendarObject.objectName + ".previousMonth();\"" + thisCalendarObject.getClass(thisCalendarObject.style.headerStyle["previousMonth"].cssClass) + " " + thisCalendarObject.style.headerStyle["previousMonth"].getStyleString() + " title=\"" + thisCalendarObject.toolTips["previousMonth"] + "\">" + thisCalendarObject.text["previousMonth"] + "</a></td>";
			}
			var header = "";
			switch (thisCalendarObject.format["header"]) {
				case "FullMonthYear":
				case "":
					header = thisCalendarObject.monthNames[thisCalendarObject.showDate.getMonth()] + " " + thisCalendarObject.showDate.getFullYear();
					break;
				case "ShortMonthYear":
					header = thisCalendarObject.abbreviatedMonthNames[thisCalendarObject.showDate.getMonth()] + " " + thisCalendarObject.showDate.getFullYear();
					break;
				case "FullMonth":
					header = thisCalendarObject.monthNames[thisCalendarObject.showDate.getMonth()];
					break;
				case "ShortMonth":
					header = thisCalendarObject.abbreviatedMonthNames[thisCalendarObject.showDate.getMonth()];
					break;
				case "Month":
					header = parseInt(thisCalendarObject.showDate.getMonth()) + 1;
					break;
				case "YearFullMonth":
					header = thisCalendarObject.showDate.getFullYear() + " " + thisCalendarObject.monthNames[thisCalendarObject.showDate.getMonth()];
					break;
				case "YearShortMonth":
					header = thisCalendarObject.showDate.getFullYear() + " " +  thisCalendarObject.abbreviatedMonthNames[thisCalendarObject.showDate.getMonth()];
					break;
				case "YearMonth":
					header =thisCalendarObject.showDate.getFullYear() + " " + (parseInt(thisCalendarObject.showDate.getMonth()) + 1);
					break;
				case "MonthYear":
					header = (parseInt(thisCalendarObject.showDate.getMonth()) + 1) + " " + thisCalendarObject.showDate.getFullYear();
				default:
					header = thisCalendarObject.formatDate(thisCalendarObject.showDate, thisCalendarObject.format["header"]);
					break;
			}
			calendar += "<td align=\"center\" valign=\"middle\">" + header + "</td>";
			if (thisCalendarObject.visible["nextMonth"]) {
				//tempCol--;
				calendar += "<td align=\"right\" valign=\"middle\" style=\"width:1px\"><a href=\"javascript:" + thisCalendarObject.objectName + ".nextMonth();\"" + thisCalendarObject.getClass(thisCalendarObject.style.headerStyle["nextMonth"].cssClass) + " " + thisCalendarObject.style.headerStyle["nextMonth"].getStyleString() + " title=\"" + thisCalendarObject.toolTips["nextMonth"] + "\">" + thisCalendarObject.text["nextMonth"] + "</a></td>";
			}
			if (thisCalendarObject.visible["nextYear"]) {
				//tempCol--;
				calendar += "<td align=\"right\" valign=\"middle\" style=\"width:1px\"><a href=\"javascript:" + thisCalendarObject.objectName + ".nextYear();\"" + thisCalendarObject.getClass(thisCalendarObject.style.headerStyle["nextYear"].cssClass) + " " + thisCalendarObject.style.headerStyle["nextYear"].getStyleString() + " title=\"" + thisCalendarObject.toolTips["nextYear"] + "\">" + thisCalendarObject.text["nextYear"] + "</a></td>";
			}
			calendar += "</tr></table></td></tr>";
		}
		// show header ends

		// show title
		if (thisCalendarObject.visible["title"]) {
			calendar += "<tr>";
			var temp = null;
			switch (thisCalendarObject.format["title"]) {
				case "FullDay":
					temp = thisCalendarObject.dayNames;
					break;
				case "Day":
					temp = thisCalendarObject.shortDayNames;
					break;
				default:
					temp = thisCalendarObject.abbreviatedDayNames;
					break;
			}
			for (var i = 0; i < temp.length; i++) {
				calendar += "<td align=\"center\" valign=\"middle\" " + thisCalendarObject.getClass(thisCalendarObject.style.titleStyle.cssClass) + " " + thisCalendarObject.style.titleStyle.getStyleString() + ">" + temp[(thisCalendarObject.firstDayOfWeek + i) % temp.length] + "</td>";
			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -