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

📄 calendar.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
	*/	between : function(date, dateBegin, dateEnd) {		if (this.after(date, dateBegin) && this.before(date, dateEnd)) {			return true;		} else {			return false;		}	},		/**	* Retrieves a JavaScript Date object representing January 1 of any given year.	* @method getJan1	* @param {Number} calendarYear		The calendar year for which to retrieve January 1	* @return {Date}	January 1 of the calendar year specified.	*/	getJan1 : function(calendarYear) {		return this.getDate(calendarYear,0,1);	},	/**	* Calculates the number of days the specified date is from January 1 of the specified calendar year.	* Passing January 1 to this function would return an offset value of zero.	* @method getDayOffset	* @param {Date}	date	The JavaScript date for which to find the offset	* @param {Number} calendarYear	The calendar year to use for determining the offset	* @return {Number}	The number of days since January 1 of the given year	*/	getDayOffset : function(date, calendarYear) {		var beginYear = this.getJan1(calendarYear); // Find the start of the year. This will be in week 1.				// Find the number of days the passed in date is away from the calendar year start		var dayOffset = Math.ceil((date.getTime()-beginYear.getTime()) / this.ONE_DAY_MS);		return dayOffset;	},	/**	* Calculates the week number for the given date. Can currently support standard	* U.S. week numbers, based on Jan 1st defining the 1st week of the year, and 	* ISO8601 week numbers, based on Jan 4th defining the 1st week of the year.	* 	* @method getWeekNumber	* @param {Date}	date The JavaScript date for which to find the week number	* @param {Number} firstDayOfWeek The index of the first day of the week (0 = Sun, 1 = Mon ... 6 = Sat).	* Defaults to 0	* @param {Number} janDate The date in the first week of January which defines week one for the year	* Defaults to the value of YAHOO.widget.DateMath.WEEK_ONE_JAN_DATE, which is 1 (Jan 1st). 	* For the U.S, this is normally Jan 1st. ISO8601 uses Jan 4th to define the first week of the year.	* 	* @return {Number} The number of the week containing the given date.	*/	getWeekNumber : function(date, firstDayOfWeek, janDate) {		// Setup Defaults		firstDayOfWeek = firstDayOfWeek || 0;		janDate = janDate || this.WEEK_ONE_JAN_DATE;		var targetDate = this.clearTime(date),			startOfWeek,			endOfWeek;		if (targetDate.getDay() === firstDayOfWeek) { 			startOfWeek = targetDate;		} else {			startOfWeek = this.getFirstDayOfWeek(targetDate, firstDayOfWeek);		}		var startYear = startOfWeek.getFullYear(),			startTime = startOfWeek.getTime();		// DST shouldn't be a problem here, math is quicker than setDate();		endOfWeek = new Date(startOfWeek.getTime() + 6*this.ONE_DAY_MS);		var weekNum;		if (startYear !== endOfWeek.getFullYear() && endOfWeek.getDate() >= janDate) {			// If years don't match, endOfWeek is in Jan. and if the 			// week has WEEK_ONE_JAN_DATE in it, it's week one by definition.			weekNum = 1;		} else {			// Get the 1st day of the 1st week, and 			// find how many days away we are from it.			var weekOne = this.clearTime(this.getDate(startYear, 0, janDate)),				weekOneDayOne = this.getFirstDayOfWeek(weekOne, firstDayOfWeek);			// Round days to smoothen out 1 hr DST diff			var daysDiff  = Math.round((targetDate.getTime() - weekOneDayOne.getTime())/this.ONE_DAY_MS);			// Calc. Full Weeks			var rem = daysDiff % 7;			var weeksDiff = (daysDiff - rem)/7;			weekNum = weeksDiff + 1;		}		return weekNum;	},	/**	 * Get the first day of the week, for the give date. 	 * @param {Date} dt The date in the week for which the first day is required.	 * @param {Number} startOfWeek The index for the first day of the week, 0 = Sun, 1 = Mon ... 6 = Sat (defaults to 0)	 * @return {Date} The first day of the week	 */	getFirstDayOfWeek : function (dt, startOfWeek) {		startOfWeek = startOfWeek || 0;		var dayOfWeekIndex = dt.getDay(),			dayOfWeek = (dayOfWeekIndex - startOfWeek + 7) % 7;		return this.subtract(dt, this.DAY, dayOfWeek);	},	/**	* Determines if a given week overlaps two different years.	* @method isYearOverlapWeek	* @param {Date}	weekBeginDate	The JavaScript Date representing the first day of the week.	* @return {Boolean}	true if the date overlaps two different years.	*/	isYearOverlapWeek : function(weekBeginDate) {		var overlaps = false;		var nextWeek = this.add(weekBeginDate, this.DAY, 6);		if (nextWeek.getFullYear() != weekBeginDate.getFullYear()) {			overlaps = true;		}		return overlaps;	},	/**	* Determines if a given week overlaps two different months.	* @method isMonthOverlapWeek	* @param {Date}	weekBeginDate	The JavaScript Date representing the first day of the week.	* @return {Boolean}	true if the date overlaps two different months.	*/	isMonthOverlapWeek : function(weekBeginDate) {		var overlaps = false;		var nextWeek = this.add(weekBeginDate, this.DAY, 6);		if (nextWeek.getMonth() != weekBeginDate.getMonth()) {			overlaps = true;		}		return overlaps;	},	/**	* Gets the first day of a month containing a given date.	* @method findMonthStart	* @param {Date}	date	The JavaScript Date used to calculate the month start	* @return {Date}		The JavaScript Date representing the first day of the month	*/	findMonthStart : function(date) {		var start = this.getDate(date.getFullYear(), date.getMonth(), 1);		return start;	},	/**	* Gets the last day of a month containing a given date.	* @method findMonthEnd	* @param {Date}	date	The JavaScript Date used to calculate the month end	* @return {Date}		The JavaScript Date representing the last day of the month	*/	findMonthEnd : function(date) {		var start = this.findMonthStart(date);		var nextMonth = this.add(start, this.MONTH, 1);		var end = this.subtract(nextMonth, this.DAY, 1);		return end;	},	/**	* Clears the time fields from a given date, effectively setting the time to 12 noon.	* @method clearTime	* @param {Date}	date	The JavaScript Date for which the time fields will be cleared	* @return {Date}		The JavaScript Date cleared of all time fields	*/	clearTime : function(date) {		date.setHours(12,0,0,0);		return date;	},	/**	 * Returns a new JavaScript Date object, representing the given year, month and date. Time fields (hr, min, sec, ms) on the new Date object	 * are set to 0. The method allows Date instances to be created with the a year less than 100. "new Date(year, month, date)" implementations 	 * set the year to 19xx if a year (xx) which is less than 100 is provided.	 * <p>	 * <em>NOTE:</em>Validation on argument values is not performed. It is the caller's responsibility to ensure	 * arguments are valid as per the ECMAScript-262 Date object specification for the new Date(year, month[, date]) constructor.	 * </p>	 * @method getDate	 * @param {Number} y Year.	 * @param {Number} m Month index from 0 (Jan) to 11 (Dec).	 * @param {Number} d (optional) Date from 1 to 31. If not provided, defaults to 1.	 * @return {Date} The JavaScript date object with year, month, date set as provided.	 */	getDate : function(y, m, d) {		var dt = null;		if (YAHOO.lang.isUndefined(d)) {			d = 1;		}		if (y >= 100) {			dt = new Date(y, m, d);		} else {			dt = new Date();			dt.setFullYear(y);			dt.setMonth(m);			dt.setDate(d);			dt.setHours(0,0,0,0);		}		return dt;	}};/*** The Calendar component is a UI control that enables users to choose one or more dates from a graphical calendar presented in a one-month or* multi-month interface. Calendars are generated entirely via script and can be navigated without any page refreshes.* @module    calendar* @title    Calendar* @namespace  YAHOO.widget* @requires  yahoo,dom,event*/(function(){	var Dom = YAHOO.util.Dom,		Event = YAHOO.util.Event,		Lang = YAHOO.lang,		DateMath = YAHOO.widget.DateMath;/*** Calendar is the base class for the Calendar widget. In its most basic* implementation, it has the ability to render a calendar widget on the page* that can be manipulated to select a single date, move back and forth between* months and years.* <p>To construct the placeholder for the calendar widget, the code is as* follows:*	<xmp>*		<div id="calContainer"></div>*	</xmp>* </p>* <p>* <strong>NOTE: As of 2.4.0, the constructor's ID argument is optional.</strong>* The Calendar can be constructed by simply providing a container ID string, * or a reference to a container DIV HTMLElement (the element needs to exist * in the document).* * E.g.:*	<xmp>*		var c = new YAHOO.widget.Calendar("calContainer", configOptions);*	</xmp>* or:*   <xmp>*       var containerDiv = YAHOO.util.Dom.get("calContainer");*		var c = new YAHOO.widget.Calendar(containerDiv, configOptions);*	</xmp>* </p>* <p>* If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix.* For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t".* </p>* * @namespace YAHOO.widget* @class Calendar* @constructor* @param {String} id optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.* @param {String | HTMLElement} container The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.* @param {Object} config optional The configuration object containing the initial configuration values for the Calendar.*/function Calendar(id, containerId, config) {	this.init.apply(this, arguments);}/*** The path to be used for images loaded for the Calendar* @property YAHOO.widget.Calendar.IMG_ROOT* @static* @deprecated	You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively* @type String*/Calendar.IMG_ROOT = null;/*** Type constant used for renderers to represent an individual date (M/D/Y)* @property YAHOO.widget.Calendar.DATE* @static* @final* @type String*/Calendar.DATE = "D";/*** Type constant used for renderers to represent an individual date across any year (M/D)* @property YAHOO.widget.Calendar.MONTH_DAY* @static* @final* @type String*/Calendar.MONTH_DAY = "MD";/*** Type constant used for renderers to represent a weekday* @property YAHOO.widget.Calendar.WEEKDAY* @static* @final* @type String*/Calendar.WEEKDAY = "WD";/*** Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)* @property YAHOO.widget.Calendar.RANGE* @static* @final* @type String*/Calendar.RANGE = "R";/*** Type constant used for renderers to represent a month across any year* @property YAHOO.widget.Calendar.MONTH* @static* @final* @type String*/Calendar.MONTH = "M";/*** Constant that represents the total number of date cells that are displayed in a given month* @property YAHOO.widget.Calendar.DISPLAY_DAYS* @static* @final* @type Number*/Calendar.DISPLAY_DAYS = 42;/*** Constant used for halting the execution of the remainder of the render stack* @property YAHOO.widget.Calendar.STOP_RENDER* @static* @final* @type String*/Calendar.STOP_RENDER = "S";/*** Constant used to represent short date field string formats (e.g. Tu or Feb)* @property YAHOO.widget.Calendar.SHORT* @static* @final* @type String*/Calendar.SHORT = "short";/*** Constant used to represent long date field string formats (e.g. Monday or February)* @property YAHOO.widget.Calendar.LONG* @static* @final* @type String*/Calendar.LONG = "long";/*** Constant used to represent medium date field string formats (e.g. Mon)* @property YAHOO.widget.Calendar.MEDIUM* @static* @final* @type String*/Calendar.MEDIUM = "medium";/*** Constant used to represent single character date field string formats (e.g. M, T, W)* @property YAHOO.widget.Calendar.ONE_CHAR* @static* @final* @type String*/Calendar.ONE_CHAR = "1char";/*** The set of default Config property keys and values for the Calendar* @property YAHOO.widget.Calendar._DEFAULT_CONFIG* @final* @static* @private* @type Object*/Calendar._DEFAULT_CONFIG = {	// Default values for pagedate and selected are not class level constants - they are set during instance creation 	PAGEDATE : {key:"pagedate", value:null},	SELECTED : {key:"selected", value:null},	TITLE : {key:"title", value:""},	CLOSE : {key:"close", value:false},	IFRAME : {key:"iframe", value:(YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 6) ? true : false},	MINDATE : {key:"mindate", value:null},	MAXDATE : {key:"maxdate", value:null},	MULTI_SELECT : {key:"multi_select", value:false},	START_WEEKDAY : {key:"start_weekday", value:0},	SHOW_WEEKDAYS : {key:"show_weekdays", value:true},	SHOW_WEEK_HEADER : {key:"show_week_header", value:false},	SHOW_WEEK_FOOTER : {key:"show_week_footer", value:false},	HIDE_BLANK_WEEKS : {key:"hide_blank_weeks", value:false},	NAV_ARROW_LEFT: {key:"nav_arrow_left", value:null} ,	NAV_ARROW_RIGHT : {key:"nav_arrow_right", value:null} ,	MONTHS_SHORT : {key:"months_short", value:["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]},	MONTHS_LONG: {key:"months_long", value:["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]},	WEEKDAYS_1CHAR: {key:"weekdays_1char", value:["S", "M", "T", "W", "T", "F", "S"]},	WEEKDAYS_SHORT: {key:"weekdays_short", value:["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]},	WEEKDAYS_MEDIUM: {key:"weekdays_medium", value:["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]},	WEEKDAYS_LONG: {key:"weekdays_long", value:["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]},	LOCALE_MONTHS:{key:"locale_months", value:"long"},	LOCALE_WEEKDAYS:{key:"locale_weekdays", value:"short"},	DATE_DELIMITER:{key:"date_delimiter", value:","},	DATE_FIELD_DELIMITER:{key:"date_field_delimiter", value:"/"},	DATE_RANGE_DELIMITER:{key:"date_range_delimiter", value:"-"},	MY_MONTH_POSITION:{key:"my_month_position", value:1},	MY_YEAR_POSITION:{key:"my_year_position", value:2},	MD_MONTH_POSITION:{key:"md_month_position", value:1},	MD_DAY_POSITION:{key:"md_day_position", value:2},	MDY_MONTH_POSITION:{key:"mdy_month_position", value:1},	MDY_DAY_POSITION:{key:"mdy_day_position", value:2},	MDY_YEAR_POSITION:{key:"mdy_year_position", value:3},	MY_LABEL_MONTH_POSITION:{key:"my_label_month_position", value:1},	MY_LABEL_YEAR_POSITION:{key:"my_label_year_position", value:2},	MY_LABEL_MONTH_SUFFIX:{key:"my_label_month_suffix", value:" "},	MY_LABEL_YEAR_SUFFIX:{key:"my_label_year_suffix", value:""},	NAV: {key:"navigator", value: null},	STRINGS : { 		key:"strings",		value: {			previousMonth : "Previous Month",			nextMonth : "Next Month",			close: "Close"		},		supercedes : ["close", "title"]	}};var DEF_CFG = Calendar._DEFAULT_CONFIG;/*** The set of Custom Event types supported by the Calendar* @property YAHOO.widget.Calendar._EVENT_TYPES* @final* @static* @private* @type Object

⌨️ 快捷键说明

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