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

📄 dateout.js

📁 最好用的站点内容管理系统 全部源代码都有
💻 JS
📖 第 1 页 / 共 5 页
字号:
document.writeln("};");
document.writeln("");
document.writeln("\/** Calls the first user handler (selectedHandler). *\/");
document.writeln("Calendar.prototype.callHandler = function () {");
document.writeln("	if (this.onSelected) {");
document.writeln("		this.onSelected(this, this.date.print(this.dateFormat));");
document.writeln("	}");
document.writeln("};");
document.writeln("");
document.writeln("\/** Calls the second user handler (closeHandler). *\/");
document.writeln("Calendar.prototype.callCloseHandler = function () {");
document.writeln("	if (this.onClose) {");
document.writeln("		this.onClose(this);");
document.writeln("	}");
document.writeln("	this.hideShowCovered();");
document.writeln("};");
document.writeln("");
document.writeln("\/** Removes the calendar object from the DOM tree and destroys it. *\/");
document.writeln("Calendar.prototype.destroy = function () {");
document.writeln("	var el = this.element.parentNode;");
document.writeln("	el.removeChild(this.element);");
document.writeln("	Calendar._C = null;");
document.writeln("};");
document.writeln("");
document.writeln("\/**");
document.writeln(" *  Moves the calendar element to a different section in the DOM tree (changes");
document.writeln(" *  its parent).");
document.writeln(" *\/");
document.writeln("Calendar.prototype.reparent = function (new_parent) {");
document.writeln("	var el = this.element;");
document.writeln("	el.parentNode.removeChild(el);");
document.writeln("	new_parent.appendChild(el);");
document.writeln("};");
document.writeln("");
document.writeln("\/\/ This gets called when the user presses a mouse button anywhere in the");
document.writeln("\/\/ document, if the calendar is shown.  If the click was outside the open");
document.writeln("\/\/ calendar this function closes it.");
document.writeln("Calendar._checkCalendar = function(ev) {");
document.writeln("	if (!window.calendar) {");
document.writeln("		return false;");
document.writeln("	}");
document.writeln("	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);");
document.writeln("	for (; el != null && el != calendar.element; el = el.parentNode);");
document.writeln("	if (el == null) {");
document.writeln("		\/\/ calls closeHandler which should hide the calendar.");
document.writeln("		window.calendar.callCloseHandler();");
document.writeln("		return Calendar.stopEvent(ev);");
document.writeln("	}");
document.writeln("};");
document.writeln("");
document.writeln("\/** Shows the calendar. *\/");
document.writeln("Calendar.prototype.show = function () {");
document.writeln("	var rows = this.table.getElementsByTagName(\"tr\");");
document.writeln("	for (var i = rows.length; i > 0;) {");
document.writeln("		var row = rows[--i];");
document.writeln("		Calendar.removeClass(row, \"rowhilite\");");
document.writeln("		var cells = row.getElementsByTagName(\"td\");");
document.writeln("		for (var j = cells.length; j > 0;) {");
document.writeln("			var cell = cells[--j];");
document.writeln("			Calendar.removeClass(cell, \"hilite\");");
document.writeln("			Calendar.removeClass(cell, \"active\");");
document.writeln("		}");
document.writeln("	}");
document.writeln("	this.element.style.display = \"block\";");
document.writeln("	this.hidden = false;");
document.writeln("	if (this.isPopup) {");
document.writeln("		window.calendar = this;");
document.writeln("		Calendar.addEvent(document, \"keydown\", Calendar._keyEvent);");
document.writeln("		Calendar.addEvent(document, \"keypress\", Calendar._keyEvent);");
document.writeln("		Calendar.addEvent(document, \"mousedown\", Calendar._checkCalendar);");
document.writeln("	}");
document.writeln("	this.hideShowCovered();");
document.writeln("};");
document.writeln("");
document.writeln("\/**");
document.writeln(" *  Hides the calendar.  Also removes any \"hilite\" from the class of any TD");
document.writeln(" *  element.");
document.writeln(" *\/");
document.writeln("Calendar.prototype.hide = function () {");
document.writeln("	if (this.isPopup) {");
document.writeln("		Calendar.removeEvent(document, \"keydown\", Calendar._keyEvent);");
document.writeln("		Calendar.removeEvent(document, \"keypress\", Calendar._keyEvent);");
document.writeln("		Calendar.removeEvent(document, \"mousedown\", Calendar._checkCalendar);");
document.writeln("	}");
document.writeln("	this.element.style.display = \"none\";");
document.writeln("	this.hidden = true;");
document.writeln("	this.hideShowCovered();");
document.writeln("};");
document.writeln("");
document.writeln("\/**");
document.writeln(" *  Shows the calendar at a given absolute position (beware that, depending on");
document.writeln(" *  the calendar element style -- position property -- this might be relative");
document.writeln(" *  to the parent\'s containing rectangle).");
document.writeln(" *\/");
document.writeln("Calendar.prototype.showAt = function (x, y) {");
document.writeln("	var s = this.element.style;");
document.writeln("	s.left = x + \"px\";");
document.writeln("	s.top = y + \"px\";");
document.writeln("	this.show();");
document.writeln("};");
document.writeln("");
document.writeln("\/** Shows the calendar near a given element. *\/");
document.writeln("Calendar.prototype.showAtElement = function (el, opts) {");
document.writeln("	var p = Calendar.getAbsolutePos(el);");
document.writeln("	if (!opts || typeof opts != \"string\") {");
document.writeln("		this.showAt(p.x, p.y + el.offsetHeight);");
document.writeln("		return true;");
document.writeln("	}");
document.writeln("	this.show();");
document.writeln("	var w = this.element.offsetWidth;");
document.writeln("	var h = this.element.offsetHeight;");
document.writeln("	this.hide();");
document.writeln("	var valign = opts.substr(0, 1);");
document.writeln("	var halign = \"l\";");
document.writeln("	if (opts.length > 1) {");
document.writeln("		halign = opts.substr(1, 1);");
document.writeln("	}");
document.writeln("	\/\/ vertical alignment");
document.writeln("        switch (valign) {");
document.writeln("	    case \"T\": p.y -= h; break;");
document.writeln("	    case \"B\": p.y += el.offsetHeight; break;");
document.writeln("	    case \"C\": p.y += (el.offsetHeight - h) \/ 2; break;");
document.writeln("	    case \"t\": p.y += el.offsetHeight - h; break;");
document.writeln("	    case \"b\": break; \/\/ already there");
document.writeln("        }");
document.writeln("	\/\/ horizontal alignment");
document.writeln("	switch (halign) {");
document.writeln("	    case \"L\": p.x -= w; break;");
document.writeln("	    case \"R\": p.x += el.offsetWidth; break;");
document.writeln("	    case \"C\": p.x += (el.offsetWidth - w) \/ 2; break;");
document.writeln("	    case \"r\": p.x += el.offsetWidth - w; break;");
document.writeln("	    case \"l\": break; \/\/ already there");
document.writeln("	}");
document.writeln("	this.showAt(p.x, p.y);");
document.writeln("};");
document.writeln("");
document.writeln("\/** Customizes the date format. *\/");
document.writeln("Calendar.prototype.setDateFormat = function (str) {");
document.writeln("	this.dateFormat = str;");
document.writeln("};");
document.writeln("");
document.writeln("\/** Customizes the tooltip date format. *\/");
document.writeln("Calendar.prototype.setTtDateFormat = function (str) {");
document.writeln("	this.ttDateFormat = str;");
document.writeln("};");
document.writeln("");
document.writeln("\/**");
document.writeln(" *  Tries to identify the date represented in a string.  If successful it also");
document.writeln(" *  calls this.setDate which moves the calendar to the given date.");
document.writeln(" *\/");
document.writeln("Calendar.prototype.parseDate = function (str, fmt) {");
document.writeln("	var y = 0;");
document.writeln("	var m = -1;");
document.writeln("	var d = 0;");
document.writeln("	var a = str.split(\/\\W+\/);");
document.writeln("	if (!fmt) {");
document.writeln("		fmt = this.dateFormat;");
document.writeln("	}");
document.writeln("	var b = fmt.split(\/\\W+\/);");
document.writeln("	var i = 0, j = 0;");
document.writeln("	for (i = 0; i < a.length; ++i) {");
document.writeln("		if (b[i] == \"D\" || b[i] == \"DD\") {");
document.writeln("			continue;");
document.writeln("		}");
document.writeln("		if (b[i] == \"d\" || b[i] == \"dd\") {");
document.writeln("			d = parseInt(a[i], 10);");
document.writeln("		}");
document.writeln("		if (b[i] == \"m\" || b[i] == \"mm\") {");
document.writeln("			m = parseInt(a[i], 10) - 1;");
document.writeln("		}");
document.writeln("		if ((b[i] == \"y\") || (b[i] == \"yy\")) {");
document.writeln("			y = parseInt(a[i], 10);");
document.writeln("			(y < 100) && (y += (y > 29) ? 1900 : 2000);");
document.writeln("		}");
document.writeln("		if (b[i] == \"M\" || b[i] == \"MM\") {");
document.writeln("			for (j = 0; j < 12; ++j) {");
document.writeln("				if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }");
document.writeln("			}");
document.writeln("		}");
document.writeln("	}");
document.writeln("	if (y != 0 && m != -1 && d != 0) {");
document.writeln("		this.setDate(new Date(y, m, d));");
document.writeln("		return;");
document.writeln("	}");
document.writeln("	y = 0; m = -1; d = 0;");
document.writeln("	for (i = 0; i < a.length; ++i) {");
document.writeln("		if (a[i].search(\/[a-zA-Z]+\/) != -1) {");
document.writeln("			var t = -1;");
document.writeln("			for (j = 0; j < 12; ++j) {");
document.writeln("				if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }");
document.writeln("			}");
document.writeln("			if (t != -1) {");
document.writeln("				if (m != -1) {");
document.writeln("					d = m+1;");
document.writeln("				}");
document.writeln("				m = t;");
document.writeln("			}");
document.writeln("		} else if (parseInt(a[i], 10) <= 12 && m == -1) {");
document.writeln("			m = a[i]-1;");
document.writeln("		} else if (parseInt(a[i], 10) > 31 && y == 0) {");
document.writeln("			y = parseInt(a[i], 10);");
document.writeln("			(y < 100) && (y += (y > 29) ? 1900 : 2000);");
document.writeln("		} else if (d == 0) {");
document.writeln("			d = a[i];");
document.writeln("		}");
document.writeln("	}");
document.writeln("	if (y == 0) {");
document.writeln("		var today = new Date();");
document.writeln("		y = today.getFullYear();");
document.writeln("	}");
document.writeln("	if (m != -1 && d != 0) {");
document.writeln("		this.setDate(new Date(y, m, d));");
document.writeln("	}");
document.writeln("};");
document.writeln("");
document.writeln("Calendar.prototype.hideShowCovered = function () {");
document.writeln("	function getStyleProp(obj, style){");
document.writeln("		var value = obj.style[style];");
document.writeln("		if (!value) {");
document.writeln("			if (document.defaultView && typeof (document.defaultView.getComputedStyle) == \"function\") { \/\/ Gecko, W3C");
document.writeln("				value = document.defaultView.");
document.writeln("					getComputedStyle(obj, \"\").getPropertyValue(style);");
document.writeln("			} else if (obj.currentStyle) { \/\/ IE");
document.writeln("				value = obj.currentStyle[style];");
document.writeln("			} else {");
document.writeln("				value = obj.style[style];");
document.writeln("			}");
document.writeln("		}");
document.writeln("		return value;");
document.writeln("	};");
document.writeln("");
document.writeln("	var tags = new Array(\"applet\", \"iframe\", \"select\");");
document.writeln("	var el = this.element;");
document.writeln("");
document.writeln("	var p = Calendar.getAbsolutePos(el);");
document.writeln("	var EX1 = p.x;");
document.writeln("	var EX2 = el.offsetWidth + EX1;");
document.writeln("	var EY1 = p.y;");
document.writeln("	var EY2 = el.offsetHeight + EY1;");
document.writeln("");
document.writeln("	for (var k = tags.length; k > 0; ) {");
document.writeln("		var ar = document.getElementsByTagName(tags[--k]);");
document.writeln("		var cc = null;");
document.writeln("");
document.writeln("		for (var i = ar.length; i > 0;) {");
document.writeln("			cc = ar[--i];");
document.writeln("");
document.writeln("			p = Calendar.getAbsolutePos(cc);");
document.writeln("			var CX1 = p.x;");
document.writeln("			var CX2 = cc.offsetWidth + CX1;");
document.writeln("			var CY1 = p.y;");
document.writeln("			var CY2 = cc.offsetHeight + CY1;");
document.writeln("");
document.writeln("			if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {");
document.writeln("				if (!cc.__msh_save_visibility) {");
document.writeln("					cc.__msh_save_visibility = g

⌨️ 快捷键说明

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