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

📄 calendarpopup.js

📁 网页打卡钟系统,源码提供给大家学习一下啦!希望给大家带来帮助
💻 JS
📖 第 1 页 / 共 4 页
字号:
// ===================================================================// Author: Matt Kruse <matt@mattkruse.com>// WWW: http://www.mattkruse.com///// NOTICE: You may use this code for any purpose, commercial or// private, without any further permission from the author. You may// remove this notice from your final code if you wish, however it is// appreciated by the author if at least my web site address is kept.//// You may *NOT* re-distribute this code in any way except through its// use. That means, you can include it in your product, or your web// site, or any other form where the code is actually being used. You// may not put the plain javascript up on your site for download or// include it in your javascript libraries for download. // If you wish to share this code with others, please just point them// to the URL instead.// Please DO NOT link directly to my .js files from your site. Copy// the files to your server and use them there. Thank you.// ===================================================================/* SOURCE FILE: AnchorPosition.js *//* AnchorPosition.jsAuthor: Matt KruseLast modified: 10/11/02DESCRIPTION: These functions find the position of an <A> tag in a document,so other elements can be positioned relative to it.COMPATABILITY: Netscape 4.x,6.x,Mozilla, IE 5.x,6.x on Windows. Some smallpositioning errors - usually with Window positioning - occur on the Macintosh platform.FUNCTIONS:getAnchorPosition(anchorname)  Returns an Object() having .x and .y properties of the pixel coordinates  of the upper-left corner of the anchor. Position is relative to the PAGE.getAnchorWindowPosition(anchorname)  Returns an Object() having .x and .y properties of the pixel coordinates  of the upper-left corner of the anchor, relative to the WHOLE SCREEN.NOTES:1) For popping up separate browser windows, use getAnchorWindowPosition.    Otherwise, use getAnchorPosition2) Your anchor tag MUST contain both NAME and ID attributes which are the    same. For example:   <A NAME="test" ID="test"> </A>3) There must be at least a space between <A> </A> for IE5.5 to see the    anchor tag correctly. Do not do <A></A> with no space.*/ // getAnchorPosition(anchorname)//   This function returns an object having .x and .y properties which are the coordinates//   of the named anchor, relative to the page.function getAnchorPosition(anchorname) {	// This function will return an Object with x and y properties	var useWindow=false;	var coordinates=new Object();	var x=0,y=0;	// Browser capability sniffing	var use_gebi=false, use_css=false, use_layers=false;	if (document.getElementById) { use_gebi=true; }	else if (document.all) { use_css=true; }	else if (document.layers) { use_layers=true; }	// Logic to find position 	if (use_gebi && document.all) {		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);		}	else if (use_gebi) {		var o=document.getElementById(anchorname);		x=AnchorPosition_getPageOffsetLeft(o);		y=AnchorPosition_getPageOffsetTop(o);		} 	else if (use_css) {		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);		}	else if (use_layers) {		var found=0;		for (var i=0; i<document.anchors.length; i++) {			if (document.anchors[i].name==anchorname) { found=1; break; }			}		if (found==0) {			coordinates.x=0; coordinates.y=0; return coordinates;			}		x=document.anchors[i].x;		y=document.anchors[i].y;		}	else {		coordinates.x=0; coordinates.y=0; return coordinates;		}	coordinates.x=x;	coordinates.y=y;	return coordinates;	}// getAnchorWindowPosition(anchorname)//   This function returns an object having .x and .y properties which are the coordinates//   of the named anchor, relative to the windowfunction getAnchorWindowPosition(anchorname) {	var coordinates=getAnchorPosition(anchorname);	var x=0;	var y=0;	if (document.getElementById) {		if (isNaN(window.screenX)) {			x=coordinates.x-document.body.scrollLeft+window.screenLeft;			y=coordinates.y-document.body.scrollTop+window.screenTop;			}		else {			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;			}		}	else if (document.all) {		x=coordinates.x-document.body.scrollLeft+window.screenLeft;		y=coordinates.y-document.body.scrollTop+window.screenTop;		}	else if (document.layers) {		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;		}	coordinates.x=x;	coordinates.y=y;	return coordinates;	}// Functions for IE to get position of an objectfunction AnchorPosition_getPageOffsetLeft (el) {	var ol=el.offsetLeft;	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }	return ol;	}function AnchorPosition_getWindowOffsetLeft (el) {	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;	}	function AnchorPosition_getPageOffsetTop (el) {	var ot=el.offsetTop;	while((el=el.offsetParent) != null) { ot += el.offsetTop; }	return ot;	}function AnchorPosition_getWindowOffsetTop (el) {	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;	}/* SOURCE FILE: date.js */// HISTORY// ------------------------------------------------------------------// May 17, 2003: Fixed bug in parseDate() for dates <1970// March 11, 2003: Added parseDate() function// March 11, 2003: Added "NNN" formatting option. Doesn't match up//                 perfectly with SimpleDateFormat formats, but //                 backwards-compatability was required.// ------------------------------------------------------------------// These functions use the same 'format' strings as the // java.text.SimpleDateFormat class, with minor exceptions.// The format string consists of the following abbreviations:// // Field        | Full Form          | Short Form// -------------+--------------------+-----------------------// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)//              | NNN (abbr.)        |// Day of Month | dd (2 digits)      | d (1 or 2 digits)// Day of Week  | EE (name)          | E (abbr)// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)// Minute       | mm (2 digits)      | m (1 or 2 digits)// Second       | ss (2 digits)      | s (1 or 2 digits)// AM/PM        | a                  |//// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!// Examples://  "MMM d, y" matches: January 01, 2000//                      Dec 1, 1900//                      Nov 20, 00//  "M/d/yy"   matches: 01/20/00//                      9/2/00//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"// ------------------------------------------------------------------var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');function LZ(x) {return(x<0||x>9?"":"0")+x}// ------------------------------------------------------------------// isDate ( date_string, format_string )// Returns true if date string matches format of format string and// is a valid date. Else returns false.// It is recommended that you trim whitespace around the value before// passing it to this function, as whitespace is NOT ignored!// ------------------------------------------------------------------//function isDate(val,format) {//	var date=getDateFromFormat(val,format);//	if (date==0) { return false; }//	return true;//	}// Original function isDate(val,format) is listed above. i needed to change it up a bit in order for an alert box to pop up only if date==0. //// Also added two variables so the isDate() function can be called via onsubmit() in a form.function isDate(val,format) {        var val=document.forms['form'].post_date.value;        var format=document.forms['form'].date_format.value;        var date=getDateFromFormat(val,format);        if (date==0) { alert("Date format is invalid. Please choose a date from the Date Picker if you are unsure of the date format you chose within the System Settings.");                       document.forms['form'].post_date.focus();                       return false; }        return true;        }function isFromOrToDate(val,format,val2,format2) {        var val=document.forms['form'].from_date.value;        var val2=document.forms['form'].to_date.value;        var format=document.forms['form'].date_format.value;        var format2=document.forms['form'].date_format.value;        var date=getDateFromFormat(val,format);        var date2=getDateFromFormat(val2,format2);        if (date==0) { alert("Date format is invalid. Please choose a date from the Date Picker if you are unsure of the date format you chose within the System Settings.");                       document.forms['form'].from_date.focus();                       return false; }        if (date2==0) { alert("Date format is invalid. Please choose a date from the Date Picker if you are unsure of the date format you chose within the System Settings.");                       document.forms['form'].to_date.focus();                       return false; }        return true;        }//function isDate(val,format) {//        var val=form.post_date.value;//        var format=form.date_format.value;//        var date=getDateFromFormat(val,format);//        if (date==0) { alert("Date format is invalid. Please choose a date from the Date Picker if you are unsure of the date format you should use.");//                        form.post_date.focus();//                        return false;}//        return true;//        }// -------------------------------------------------------------------// compareDates(date1,date1format,date2,date2format)//   Compare two date strings to see which is greater.//   Returns://   1 if date1 is greater than date2//   0 if date2 is greater than date1 of if they are the same//  -1 if either of the dates is in an invalid format// -------------------------------------------------------------------function compareDates(date1,dateformat1,date2,dateformat2) {	var d1=getDateFromFormat(date1,dateformat1);	var d2=getDateFromFormat(date2,dateformat2);	if (d1==0 || d2==0) {		return -1;		}	else if (d1 > d2) {		return 1;		}	return 0;	}// ------------------------------------------------------------------// formatDate (date_object, format)// Returns a date in the output format specified.// The format string uses the same abbreviations as in getDateFromFormat()// ------------------------------------------------------------------function formatDate(date,format) {	format=format+"";	var result="";	var i_format=0;	var c="";	var token="";	var y=date.getYear()+"";	var M=date.getMonth()+1;	var d=date.getDate();	var E=date.getDay();	var H=date.getHours();	var m=date.getMinutes();	var s=date.getSeconds();	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;	// Convert real date parts into formatted versions	var value=new Object();	if (y.length < 4) {y=""+(y-0+1900);}	value["y"]=""+y;	value["yyyy"]=y;	value["yy"]=y.substring(2,4);	value["M"]=M;	value["MM"]=LZ(M);	value["MMM"]=MONTH_NAMES[M-1];	value["NNN"]=MONTH_NAMES[M+11];	value["d"]=d;	value["dd"]=LZ(d);	value["E"]=DAY_NAMES[E+7];	value["EE"]=DAY_NAMES[E];	value["H"]=H;	value["HH"]=LZ(H);	if (H==0){value["h"]=12;}	else if (H>12){value["h"]=H-12;}	else {value["h"]=H;}	value["hh"]=LZ(value["h"]);	if (H>11){value["K"]=H-12;} else {value["K"]=H;}	value["k"]=H+1;	value["KK"]=LZ(value["K"]);	value["kk"]=LZ(value["k"]);	if (H > 11) { value["a"]="PM"; }	else { value["a"]="AM"; }	value["m"]=m;	value["mm"]=LZ(m);	value["s"]=s;	value["ss"]=LZ(s);	while (i_format < format.length) {		c=format.charAt(i_format);		token="";		while ((format.charAt(i_format)==c) && (i_format < format.length)) {			token += format.charAt(i_format++);			}		if (value[token] != null) { result=result + value[token]; }		else { result=result + token; }		}	return result;	}	// ------------------------------------------------------------------// Utility functions for parsing in getDateFromFormat()// ------------------------------------------------------------------function _isInteger(val) {	var digits="1234567890";	for (var i=0; i < val.length; i++) {		if (digits.indexOf(val.charAt(i))==-1) { return false; }		}	return true;	}function _getInt(str,i,minlength,maxlength) {	for (var x=maxlength; x>=minlength; x--) {		var token=str.substring(i,i+x);		if (token.length < minlength) { return null; }		if (_isInteger(token)) { return token; }		}	return null;	}	// ------------------------------------------------------------------// getDateFromFormat( date_string , format_string )//// This function takes a date string and a format string. It matches// If the date string matches the format string, it returns the // getTime() of the date. If it does not match, it returns 0.// ------------------------------------------------------------------function getDateFromFormat(val,format) {	val=val+"";	format=format+"";	var i_val=0;	var i_format=0;	var c="";	var token="";	var token2="";	var x,y;	var now=new Date();	var year=now.getYear();	var month=now.getMonth()+1;	var date=1;	var hh=now.getHours();	var mm=now.getMinutes();	var ss=now.getSeconds();	var ampm="";		while (i_format < format.length) {		// Get next token from format string		c=format.charAt(i_format);		token="";

⌨️ 快捷键说明

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