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

📄 calendar.js

📁 ECSHOP是一款开源免费的通用电子商务平台构建软件
💻 JS
📖 第 1 页 / 共 4 页
字号:
				var p = el.pos;				x = p & 15;				y = p >> 4;				ne = cal.ar_days[y][x];			};setVars();			function prevMonth() {				var date = new Date(cal.date);				date.setDate(date.getDate() - step);				cal.setDate(date);			};			function nextMonth() {				var date = new Date(cal.date);				date.setDate(date.getDate() + step);				cal.setDate(date);			};			while (1) {				switch (K) {				    case 37: // KEY left					if (--x >= 0)						ne = cal.ar_days[y][x];					else {						x = 6;						K = 38;						continue;					}					break;				    case 38: // KEY up					if (--y >= 0)						ne = cal.ar_days[y][x];					else {						prevMonth();						setVars();					}					break;				    case 39: // KEY right					if (++x < 7)						ne = cal.ar_days[y][x];					else {						x = 0;						K = 40;						continue;					}					break;				    case 40: // KEY down					if (++y < cal.ar_days.length)						ne = cal.ar_days[y][x];					else {						nextMonth();						setVars();					}					break;				}				break;			}			if (ne) {				if (!ne.disabled)					Calendar.cellClick(ne);				else if (prev)					prevMonth();				else					nextMonth();			}		}		break;	    case 13: // KEY enter		if (act)			Calendar.cellClick(cal.currentDateEl, ev);		break;	    default:		return false;	}	return Calendar.stopEvent(ev);};/** *  (RE)Initializes the calendar to the given date and firstDayOfWeek */Calendar.prototype._init = function (firstDayOfWeek, date) {	var today = new Date(),		TY = today.getFullYear(),		TM = today.getMonth(),		TD = today.getDate();	this.table.style.visibility = "hidden";	var year = date.getFullYear();	if (year < this.minYear) {		year = this.minYear;		date.setFullYear(year);	} else if (year > this.maxYear) {		year = this.maxYear;		date.setFullYear(year);	}	this.firstDayOfWeek = firstDayOfWeek;	this.date = new Date(date);	var month = date.getMonth();	var mday = date.getDate();	var no_days = date.getMonthDays();	// calendar voodoo for computing the first day that would actually be	// displayed in the calendar, even if it's from the previous month.	// WARNING: this is magic. ;-)	date.setDate(1);	var day1 = (date.getDay() - this.firstDayOfWeek) % 7;	if (day1 < 0)		day1 += 7;	date.setDate(-day1);	date.setDate(date.getDate() + 1);	var row = this.tbody.firstChild;	var MN = Calendar._SMN[month];	var ar_days = this.ar_days = new Array();	var weekend = Calendar._TT["WEEKEND"];	var dates = this.multiple ? (this.datesCells = {}) : null;	for (var i = 0; i < 6; ++i, row = row.nextSibling) {		var cell = row.firstChild;		if (this.weekNumbers) {			cell.className = "day wn";			cell.innerHTML = date.getWeekNumber();			cell = cell.nextSibling;		}		row.className = "daysrow";		var hasdays = false, iday, dpos = ar_days[i] = [];		for (var j = 0; j < 7; ++j, cell = cell.nextSibling, date.setDate(iday + 1)) {			iday = date.getDate();			var wday = date.getDay();			cell.className = "day";			cell.pos = i << 4 | j;			dpos[j] = cell;			var current_month = (date.getMonth() == month);			if (!current_month) {				if (this.showsOtherMonths) {					cell.className += " othermonth";					cell.otherMonth = true;				} else {					cell.className = "emptycell";					cell.innerHTML = "&nbsp;";					cell.disabled = true;					continue;				}			} else {				cell.otherMonth = false;				hasdays = true;			}			cell.disabled = false;			cell.innerHTML = this.getDateText ? this.getDateText(date, iday) : iday;			if (dates)				dates[date.print("%Y%m%d")] = cell;			if (this.getDateStatus) {				var status = this.getDateStatus(date, year, month, iday);				if (this.getDateToolTip) {					var toolTip = this.getDateToolTip(date, year, month, iday);					if (toolTip)						cell.title = toolTip;				}				if (status === true) {					cell.className += " disabled";					cell.disabled = true;				} else {					if (/disabled/i.test(status))						cell.disabled = true;					cell.className += " " + status;				}			}			if (!cell.disabled) {				cell.caldate = new Date(date);				cell.ttip = "_";				if (!this.multiple && current_month				    && iday == mday && this.hiliteToday) {					cell.className += " selected";					this.currentDateEl = cell;				}				if (date.getFullYear() == TY &&				    date.getMonth() == TM &&				    iday == TD) {					cell.className += " today";					cell.ttip += Calendar._TT["PART_TODAY"];				}				if (weekend.indexOf(wday.toString()) != -1)					cell.className += cell.otherMonth ? " oweekend" : " weekend";			}		}		if (!(hasdays || this.showsOtherMonths))			row.className = "emptyrow";	}	this.title.innerHTML = Calendar._MN[month] + ", " + year;	this.onSetTime();	this.table.style.visibility = "visible";	this._initMultipleDates();	// PROFILE	// this.tooltips.innerHTML = "Generated in " + ((new Date()) - today) + " ms";};Calendar.prototype._initMultipleDates = function() {	if (this.multiple) {		for (var i in this.multiple) {			var cell = this.datesCells[i];			var d = this.multiple[i];			if (!d)				continue;			if (cell)				cell.className += " selected";		}	}};Calendar.prototype._toggleMultipleDate = function(date) {	if (this.multiple) {		var ds = date.print("%Y%m%d");		var cell = this.datesCells[ds];		if (cell) {			var d = this.multiple[ds];			if (!d) {				Calendar.addClass(cell, "selected");				this.multiple[ds] = date;			} else {				Calendar.removeClass(cell, "selected");				delete this.multiple[ds];			}		}	}};Calendar.prototype.setDateToolTipHandler = function (unaryFunction) {	this.getDateToolTip = unaryFunction;};/** *  Calls _init function above for going to a certain date (but only if the *  date is different than the currently selected one). */Calendar.prototype.setDate = function (date) {	if (!date.equalsTo(this.date)) {		this._init(this.firstDayOfWeek, date);	}};/** *  Refreshes the calendar.  Useful if the "disabledHandler" function is *  dynamic, meaning that the list of disabled date can change at runtime. *  Just * call this function if you think that the list of disabled dates *  should * change. */Calendar.prototype.refresh = function () {	this._init(this.firstDayOfWeek, this.date);};/** Modifies the "firstDayOfWeek" parameter (pass 0 for Synday, 1 for Monday, etc.). */Calendar.prototype.setFirstDayOfWeek = function (firstDayOfWeek) {	this._init(firstDayOfWeek, this.date);	this._displayWeekdays();};/** *  Allows customization of what dates are enabled.  The "unaryFunction" *  parameter must be a function object that receives the date (as a JS Date *  object) and returns a boolean value.  If the returned value is true then *  the passed date will be marked as disabled. */Calendar.prototype.setDateStatusHandler = Calendar.prototype.setDisabledHandler = function (unaryFunction) {	this.getDateStatus = unaryFunction;};/** Customization of allowed year range for the calendar. */Calendar.prototype.setRange = function (a, z) {	this.minYear = a;	this.maxYear = z;};/** Calls the first user handler (selectedHandler). */Calendar.prototype.callHandler = function () {	if (this.onSelected) {		this.onSelected(this, this.date.print(this.dateFormat));	}};/** Calls the second user handler (closeHandler). */Calendar.prototype.callCloseHandler = function () {	if (this.onClose) {		this.onClose(this);	}	this.hideShowCovered();};/** Removes the calendar object from the DOM tree and destroys it. */Calendar.prototype.destroy = function () {	var el = this.element.parentNode;	el.removeChild(this.element);	Calendar._C = null;	window._dynarch_popupCalendar = null;};/** *  Moves the calendar element to a different section in the DOM tree (changes *  its parent). */Calendar.prototype.reparent = function (new_parent) {	var el = this.element;	el.parentNode.removeChild(el);	new_parent.appendChild(el);};// This gets called when the user presses a mouse button anywhere in the// document, if the calendar is shown.  If the click was outside the open// calendar this function closes it.Calendar._checkCalendar = function(ev) {	var calendar = window._dynarch_popupCalendar;	if (!calendar) {		return false;	}	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);	for (; el != null && el != calendar.element; el = el.parentNode);	if (el == null) {		// calls closeHandler which should hide the calendar.		window._dynarch_popupCalendar.callCloseHandler();		return Calendar.stopEvent(ev);	}};/** Shows the calendar. */Calendar.prototype.show = function () {	var rows = this.table.getElementsByTagName("tr");	for (var i = rows.length; i > 0;) {		var row = rows[--i];		Calendar.removeClass(row, "rowhilite");		var cells = row.getElementsByTagName("td");		for (var j = cells.length; j > 0;) {			var cell = cells[--j];			Calendar.removeClass(cell, "hilite");			Calendar.removeClass(cell, "active");		}	}	this.element.style.display = "block";	this.hidden = false;	if (this.isPopup) {		window._dynarch_popupCalendar = this;		Calendar.addEvent(document, "keydown", Calendar._keyEvent);		Calendar.addEvent(document, "keypress", Calendar._keyEvent);		Calendar.addEvent(document, "mousedown", Calendar._checkCalendar);	}	this.hideShowCovered();};/** *  Hides the calendar.  Also removes any "hilite" from the class of any TD *  element. */Calendar.prototype.hide = function () {	if (this.isPopup) {		Calendar.removeEvent(document, "keydown", Calendar._keyEvent);		Calendar.removeEvent(document, "keypress", Calendar._keyEvent);		Calendar.removeEvent(document, "mousedown", Calendar._checkCalendar);	}	this.element.style.display = "none";	this.hidden = true;	this.hideShowCovered();};/** *  Shows the calendar at a given absolute position (beware that, depending on *  the calendar element style -- position property -- this might be relative *  to the parent's containing rectangle). */Calendar.prototype.showAt = function (x, y) {	var s = this.element.style;	s.left = x + "px";	s.top = y + "px";	this.show();};/** Shows the calendar near a given element. */Calendar.prototype.showAtElement = function (el, opts) {	var self = this;	var p = Calendar.getAbsolutePos(el);	if (!opts || typeof opts != "string") {		this.showAt(p.x, p.y + el.offsetHeight);		return true;	}	function fixPosition(box) {		if (box.x < 0)			box.x = 0;		if (box.y < 0)			box.y = 0;		var cp = document.createElement("div");		var s = cp.style;		s.position = "absolute";		s.right = s.bottom = s.width = s.height = "0px";		document.body.appendChild(cp);		var br = Calendar.getAbsolutePos(cp);		document.body.removeChild(cp);		if (Calendar.is_ie) {			br.y += document.body.scrollTop;			br.x += document.body.scrollLeft;		} else {			br.y += window.scrollY;			br.x += window.scrollX;		}		var tmp = box.x + box.width - br.x;		if (tmp > 0) box.x -= tmp;		tmp = box.y + box.height - br.y;		if (tmp > 0) box.y -= tmp;	};	this.element.style.display = "block";	Calendar.continuation_for_the_fucking_khtml_browser = function() {		var w = self.element.offsetWidth;		var h = self.element.offsetHeight;		self.element.style.display = "none";		var valign = opts.substr(0, 1);		var halign = "l";		if (opts.length > 1) {			halign = opts.substr(1, 1);		}		// vertical alignment		switch (valign) {		    case "T": p.y -= h; break;		    case "B": p.y += el.offsetHeight; break;		    case "C": p.y += (el.offsetHeight - h) / 2; break;		    case "t": p.y += el.offsetHeight - h; break;		    case "b": break; // already there		}		// horizontal alignment		switch (halign) {		    case "L": p.x -= w; break;		    case "R": p.x += el.offsetWidth; break;		    case "C": p.x += (el.offsetWidth - w) / 2; break;		    case "l": p.x += el.offsetWidth - w; break;		    case "r": break; // already there		}		p.width = w;		p.height = h + 40;		self.monthsCombo.style.display = "none";		//fixPosition(p);		self.showAt(p.x, p.y);	};	if (Calendar.is_khtml)		setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10);	else		Calendar.continuation_for_the_fucking_khtml_browser();};/** Customizes the date format. */Calendar.prototype.setDateFormat = function (str) {	this.dateFormat = str;};/** Customizes the tooltip date format. */Calendar.prototype.setTtDateFormat = function (str) {	this.ttDateFormat = str;};/** *  Tries to identify the date represented in a string.  If successful it also *  calls this.setDate which moves the calendar to the given date. */Calendar.prototype.parseDate = function(str, fmt) {	if (!fmt)		fmt = this.dateFormat;	this.setDate(Date.parseDate(str, fmt));};Calendar.prototype.hideShowCovered = function () {	if (!Calendar.is_ie && !Calendar.is_opera)		return;	function getVisib(obj){		var value = obj.style.visibility;		if (!value) {			if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C				if (!Calendar.is_khtml)					value = document.defaultView.						getComputedStyle(obj, "").getPropertyValue("visibility");				else					value = '';			} else if (obj.currentStyle) { // IE				value = obj.currentStyle.visibility;			} else				value = '';		}		return value;	};	var tags = new Array("applet", "select");	var el = this.element;	var p = Calendar.getAbsolutePos(el);	var EX1 = p.x;	var EX2 = el.offsetWidth + EX1;	var EY1 = p.y;	var EY2 = el.offsetHeight + EY1;	for (var k = tags.length; k > 0; ) {		var ar = document.getElementsByTagName(tags[--k]);		var cc = null;		for (var i = ar.length; i > 0;) {			cc = ar[--i];			p = Calendar.getAbsolutePos(cc);			var CX1 = p.x;			var CX2 = cc.offsetWidth + CX1;

⌨️ 快捷键说明

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