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

📄 calendar.js

📁 商城改进板全站代码
💻 JS
📖 第 1 页 / 共 4 页
字号:
DateTime = Date;

DateTime.prototype.addDays = function(days) {
	var tempDay = this.getDate();
	tempDay += days;
	this.setDate(tempDay);
	return this;
}

DateTime.prototype.addMonths = function(months) {
	var tempMonth = this.getMonth();
	tempMonth += months;
	this.setMonth(tempMonth);
	return this;
}

DateTime.prototype.addYears = function(years) {
	var tempYear = this.getFullYear();
	tempYear += years;
	this.setYear(tempYear);
	return this;
}

DateTime.prototype.getDaysInMonth = function(year, month) {
	if (year != null && month == null) {
		month = year;
		year = this.getFullYear();
	}
	else if (year == null && month == null) {
		year = this.getFullYear();
		month = this.getMonth()
	}
	while (month < 0) {
		month += 11;
		year--;
	}
	while (month > 11) {
		month -=11;
		year++;
	}

	switch(month) {
		case 1:
			if ((year % 100 != 0 && year % 4 ==0) || (year % 400 == 0))
				return 29;
			else
				return 28;
			break;
		case 3:
		case 5:
		case 8:
		case 10:
			return 30;
			break;
		default:
			return 31;
			break;
	}
}

DateTime.prototype.isLeapYear = function() {
	var year = this.getFullYear();
	if ((year % 100 != 0 && year % 4 ==0) || (year % 400 == 0))
		return true;
	else
		return false;
}

DateTime.prototype.dayOfYear = function() {
	var year = this.getFullYear();
	if ((year % 100 != 0 && year % 4 ==0) || (year % 400 == 0))
		return 366;
	else
		return 365;
}

DateTime.prototype.isWeekendDay = function() {
	var dayOfWeek = this.getDay();
	if (dayOfWeek == 0 || dayOfWeek == 6)
		return true;
	else
		return false;
}

DateTime.prototype.compare = function(datePart, date) {
	if (!(date instanceof Date)) {
		date = new Date(date);
	}
	if (!isNaN(date)) {
		var temp1 = null, temp2 = null;
		if (datePart.toLowerCase() == "year") {
			temp1 = new Date(this.getFullYear(), 1, 1, 0, 0, 0, 0);
			temp2 = new Date(date.getFullYear(), 1, 1, 0, 0, 0, 0);
		}
		else if (datePart.toLowerCase() == "month") {
			temp1 = new Date(this.getFullYear(), this.getMonth(), 1, 0, 0, 0, 0);
			temp2 = new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
		}
		else if (datePart.toLowerCase() == "day") {
			temp1 = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0, 0);
			temp2 = new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
		}
		else {
			temp1 = new Date();
			temp2 = temp1;
		}
		if (temp1.getTime() == temp2.getTime())
			return 0;
		else if (temp1.getTime() < temp2.getTime())
			return -1;
		else
			return 1;
	}
	else
		return null;
}

function Style() {
	thisStyle = this;
	thisStyle.width = "";
	thisStyle.height = "";
	thisStyle.borderStyle = "";
	thisStyle.borderWidth = "";
	thisStyle.borderColor = "";
	thisStyle.foreColor = "";
	thisStyle.fontFamily = "";
	thisStyle.fontSize = "";
	thisStyle.backColor  = "";
	thisStyle.bold = false;
	thisStyle.italic = false;
	thisStyle.cssClass = "";
	thisStyle.borderCollapse = "";
	thisStyle.padding = "";

	//this following style should be applied as attributes of the tag instead of style string;
	thisStyle.align = "";
	thisStyle.vAlign = "";
}

Style.prototype.appendStyle = function(styleString, style, value) {
	var thisStyle = this;
	if (styleString == null || styleString == "")
		return style + ": " + value + "; ";
	else
		return styleString + style + ": " + value + "; ";
}

Style.prototype.getRawStyleString = function() {
	var thisStyle = this;
	var styleString = "";
	if (thisStyle.width != null && thisStyle.width != "")
		styleString = thisStyle.appendStyle(styleString, "width", thisStyle.width);
	if (thisStyle.height != null && thisStyle.height != "")
		styleString = thisStyle.appendStyle(styleString, "height", thisStyle.height);
	if (thisStyle.borderStyle != null && thisStyle.borderStyle != "")
		styleString = thisStyle.appendStyle(styleString, "border-style", thisStyle.borderStyle);
	if (thisStyle.borderWidth != null && thisStyle.borderWidth != "")
		styleString = thisStyle.appendStyle(styleString, "border-width", thisStyle.borderWidth);
	if (thisStyle.borderColor != null && thisStyle.borderColor != "")
		styleString = thisStyle.appendStyle(styleString, "border-color", thisStyle.borderColor);
	if (thisStyle.foreColor != null && thisStyle.foreColor != "")
		styleString = thisStyle.appendStyle(styleString, "color", thisStyle.foreColor);
	if (thisStyle.fontFamily != null && thisStyle.fontFamily != "")
		styleString = thisStyle.appendStyle(styleString, "font-family", thisStyle.fontFamily);
	if (thisStyle.fontSize != null && thisStyle.fontSize != "")
		styleString = thisStyle.appendStyle(styleString, "font-size", thisStyle.fontSize);
	if (thisStyle.backColor != null && thisStyle.backColor != "")
		styleString = thisStyle.appendStyle(styleString, "background-color", thisStyle.backColor);
	if (thisStyle.bold)	{
		styleString = thisStyle.appendStyle(styleString, "font-weight", "bold");
	}
	if (thisStyle.italic){
		styleString = thisStyle.appendStyle(styleString, "font-style", "italic");
	}
	if (thisStyle.borderCollapse != null && thisStyle.borderCollapse != "")
		styleString = thisStyle.appendStyle(styleString, "border-collapse", thisStyle.borderCollapse);
	if (thisStyle.padding != null && thisStyle.padding != "")
		styleString = thisStyle.appendStyle(styleString, "padding", thisStyle.padding);
	
	return styleString;
}

Style.prototype.getStyleString = function() {
	var thisStyle = this;
	var rawStyleString = thisStyle.getRawStyleString();
	if (rawStyleString == null || rawStyleString == "")
		return "";
	else
		return "style=\"" + rawStyleString + "\"";
}

Style.prototype.getAlign = function() {
	var thisStyle = this;
	var align = thisStyle.align.toLowerCase();
	if (align == "left" || align == "right" || align == "center") {
		return " align=\"" + align + "\" ";
	}
	else
		return "";
}

Style.prototype.getValign = function() {
	var thisStyle = this;
	var vAlign = thisStyle.vAlign.toLowerCase();
	if (vAlign == "top" || vAlign == "bottom" || vAlign == "middle") {
		return " vAlign=\"" + vAlign + "\" ";
	}
	else
		return "";
}

function CalendarObject(objectName, showDate, selectedDate) {
	var thisCalendarObject = this;
	//properties

	if (objectName == null || objectName == "") {
		alert("Object cannot be created without a valid object name.");
	}
	else {
		thisCalendarObject.objectName = objectName;
	}

	thisCalendarObject.style = new Style();
	thisCalendarObject.style.width = "100%";
	thisCalendarObject.style.height = "100%";
	thisCalendarObject.style.cellSpacing = 0;
	thisCalendarObject.style.cellPadding = 0;
	thisCalendarObject.style.border = 0;
	thisCalendarObject.style.brdrColor = "transparent";
	thisCalendarObject.style.backColor = "white";
	thisCalendarObject.style.borderWidth = "0px";
	thisCalendarObject.style.borderStyle = "solid";
	thisCalendarObject.style.borderColor = "black";
	thisCalendarObject.style.fontSize = "9pt";
	thisCalendarObject.style.fontFamily = "Tahoma";
	thisCalendarObject.style.cssClass = "Calendar";

	thisCalendarObject.style.headerStyle = new Style();
	thisCalendarObject.style.headerStyle.cssClass = "headerStyle";
	thisCalendarObject.style.headerStyle.width = "100%";

	thisCalendarObject.style.headerStyle["previousYear"] = new Style();
	thisCalendarObject.style.headerStyle["previousMonth"] = new Style();
	thisCalendarObject.style.headerStyle["nextYear"] = new Style();
	thisCalendarObject.style.headerStyle["nextMonth"] = new Style();
	thisCalendarObject.style.headerStyle["previousYear"].cssClass = "previousYearTextStyle";
	thisCalendarObject.style.headerStyle["previousMonth"].cssClass = "previousMonthTextStyle";
	thisCalendarObject.style.headerStyle["nextYear"].cssClass = "nextYearTextStyle";
	thisCalendarObject.style.headerStyle["nextMonth"].cssClass = "nextMonthTextStyle";

	thisCalendarObject.style.titleStyle = new Style();
	thisCalendarObject.style.titleStyle.cssClass = "titleStyle";

	thisCalendarObject.style.dayStyle = new Style();
	thisCalendarObject.style.dayStyle["normal"] = new Style();
	thisCalendarObject.style.dayStyle["hover"] = new Style();
	thisCalendarObject.style.dayStyle["selected"] = new Style();

	thisCalendarObject.style.dayStyle.cssClass ="dayStyle";

⌨️ 快捷键说明

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