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

📄 calendar.js

📁 一个使用yui-ext库
💻 JS
📖 第 1 页 / 共 5 页
字号:
	/**	* A copy of the initial render functions created before rendering.	* @property _renderStack	* @private	* @type Array	*/	_renderStack : null,	/**	* The private list of initially selected dates.	* @property _selectedDates	* @private	* @type Array	*/	_selectedDates : null,	/**	* A map of DOM event handlers to attach to cells associated with specific CSS class names	* @property domEventMap	* @type Object	*/	domEventMap : null};/*** Initializes the Calendar widget.* @method init* @param {String}	id			The id of the table element that will represent the calendar widget* @param {String}	containerId	The id of the container div element that will wrap the calendar table* @param {Object}	config		The configuration object containing the Calendar's arguments*/YAHOO.widget.Calendar.prototype.init = function(id, containerId, config) {	this.initEvents();	this.today = new Date();	YAHOO.widget.DateMath.clearTime(this.today);	this.id = id;	this.oDomContainer = document.getElementById(containerId);	/**	* The Config object used to hold the configuration variables for the Calendar	* @property cfg	* @type YAHOO.util.Config	*/	this.cfg = new YAHOO.util.Config(this);		/**	* The local object which contains the Calendar's options	* @property Options	* @type Object	*/	this.Options = {};	/**	* The local object which contains the Calendar's locale settings	* @property Locale	* @type Object	*/	this.Locale = {};	this.initStyles();	YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_CONTAINER);		YAHOO.util.Dom.addClass(this.oDomContainer, this.Style.CSS_SINGLE);	this.cellDates = [];	this.cells = [];	this.renderStack = [];	this._renderStack = [];	this.setupConfig();		if (config) {		this.cfg.applyConfig(config, true);	}		this.cfg.fireQueue();};/*** Renders the built-in IFRAME shim for the IE6 and below* @method configIframe*/YAHOO.widget.Calendar.prototype.configIframe = function(type, args, obj) {	var useIframe = args[0];	if (YAHOO.util.Dom.inDocument(this.oDomContainer)) {		if (useIframe) {			var pos = YAHOO.util.Dom.getStyle(this.oDomContainer, "position");			if (this.browser == "ie" && (pos == "absolute" || pos == "relative")) {				if (! YAHOO.util.Dom.inDocument(this.iframe)) {					this.iframe = document.createElement("iframe");					this.iframe.src = "javascript:false;";					YAHOO.util.Dom.setStyle(this.iframe, "opacity", "0");					this.oDomContainer.insertBefore(this.iframe, this.oDomContainer.firstChild);				}			}		} else {			if (this.iframe) {				if (this.iframe.parentNode) {					this.iframe.parentNode.removeChild(this.iframe);				}				this.iframe = null;			}		}	}};/*** Default handler for the "title" property* @method configTitle*/YAHOO.widget.Calendar.prototype.configTitle = function(type, args, obj) {	var title = args[0];	var close = this.cfg.getProperty("close");		var titleDiv;	if (title && title !== "") {		titleDiv = YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || document.createElement("div");		titleDiv.className = YAHOO.widget.CalendarGroup.CSS_2UPTITLE;		titleDiv.innerHTML = title;		this.oDomContainer.insertBefore(titleDiv, this.oDomContainer.firstChild);		YAHOO.util.Dom.addClass(this.oDomContainer, "withtitle");	} else {		titleDiv = YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE, "div", this.oDomContainer)[0] || null;		if (titleDiv) {			YAHOO.util.Event.purgeElement(titleDiv);			this.oDomContainer.removeChild(titleDiv);		}		if (! close) {			YAHOO.util.Dom.removeClass(this.oDomContainer, "withtitle");		}	}};/*** Default handler for the "close" property* @method configClose*/YAHOO.widget.Calendar.prototype.configClose = function(type, args, obj) {	var close = args[0];	var title = this.cfg.getProperty("title");		var DEPR_CLOSE_PATH = "us/my/bn/x_d.gif";	var linkClose;	if (close === true) {		linkClose = YAHOO.util.Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || document.createElement("a");		linkClose.href = "javascript:void(null);";		linkClose.className = "link-close";		YAHOO.util.Event.addListener(linkClose, "click", this.hide, this, true);				if (YAHOO.widget.Calendar.IMG_ROOT !== null) {			var imgClose = document.createElement("img");			imgClose.src = YAHOO.widget.Calendar.IMG_ROOT + DEPR_CLOSE_PATH;			imgClose.className = YAHOO.widget.CalendarGroup.CSS_2UPCLOSE;			linkClose.appendChild(imgClose);		} else {			linkClose.innerHTML = '<span class="' + YAHOO.widget.CalendarGroup.CSS_2UPCLOSE + ' ' + this.Style.CSS_CLOSE + '"></span>';		}				this.oDomContainer.appendChild(linkClose);		YAHOO.util.Dom.addClass(this.oDomContainer, "withtitle");	} else {		linkClose = YAHOO.util.Dom.getElementsByClassName("link-close", "a", this.oDomContainer)[0] || null;		if (linkClose) {			YAHOO.util.Event.purgeElement(linkClose);			this.oDomContainer.removeChild(linkClose);		}		if (! title || title === "") {			YAHOO.util.Dom.removeClass(this.oDomContainer, "withtitle");		}	}};/*** Initializes Calendar's built-in CustomEvents* @method initEvents*/YAHOO.widget.Calendar.prototype.initEvents = function() {	/**	* Fired before a selection is made	* @event beforeSelectEvent	*/	this.beforeSelectEvent = new YAHOO.util.CustomEvent("beforeSelect"); 	/**	* Fired when a selection is made	* @event selectEvent	* @param {Array}	Array of Date field arrays in the format [YYYY, MM, DD].	*/	this.selectEvent = new YAHOO.util.CustomEvent("select");	/**	* Fired before a selection is made	* @event beforeDeselectEvent	*/	this.beforeDeselectEvent = new YAHOO.util.CustomEvent("beforeDeselect");	/**	* Fired when a selection is made	* @event deselectEvent	* @param {Array}	Array of Date field arrays in the format [YYYY, MM, DD].	*/	this.deselectEvent = new YAHOO.util.CustomEvent("deselect");	/**	* Fired when the Calendar page is changed	* @event changePageEvent	*/	this.changePageEvent = new YAHOO.util.CustomEvent("changePage");	/**	* Fired before the Calendar is rendered	* @event beforeRenderEvent	*/	this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender");	/**	* Fired when the Calendar is rendered	* @event renderEvent	*/	this.renderEvent = new YAHOO.util.CustomEvent("render");	/**	* Fired when the Calendar is reset	* @event resetEvent	*/	this.resetEvent = new YAHOO.util.CustomEvent("reset");	/**	* Fired when the Calendar is cleared	* @event clearEvent	*/	this.clearEvent = new YAHOO.util.CustomEvent("clear");	this.beforeSelectEvent.subscribe(this.onBeforeSelect, this, true);	this.selectEvent.subscribe(this.onSelect, this, true);	this.beforeDeselectEvent.subscribe(this.onBeforeDeselect, this, true);	this.deselectEvent.subscribe(this.onDeselect, this, true);	this.changePageEvent.subscribe(this.onChangePage, this, true);	this.renderEvent.subscribe(this.onRender, this, true);	this.resetEvent.subscribe(this.onReset, this, true);	this.clearEvent.subscribe(this.onClear, this, true);};/*** The default event function that is attached to a date link within a calendar cell* when the calendar is rendered.* @method doSelectCell* @param {DOMEvent} e	The event* @param {Calendar} cal	A reference to the calendar passed by the Event utility*/YAHOO.widget.Calendar.prototype.doSelectCell = function(e, cal) {	var target = YAHOO.util.Event.getTarget(e);	var cell,index,d,date;	while (target.tagName.toLowerCase() != "td" && ! YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {		target = target.parentNode;		if (target.tagName.toLowerCase() == "html") {			return;		}	}		cell = target;	if (YAHOO.util.Dom.hasClass(cell, cal.Style.CSS_CELL_SELECTABLE)) {		index = cell.id.split("cell")[1];		d = cal.cellDates[index];		date = new Date(d[0],d[1]-1,d[2]);			var link;		if (cal.Options.MULTI_SELECT) {			link = cell.getElementsByTagName("a")[0];			if (link) {				link.blur();			}						var cellDate = cal.cellDates[index];			var cellDateIndex = cal._indexOfSelectedFieldArray(cellDate);						if (cellDateIndex > -1) {					cal.deselectCell(index);			} else {				cal.selectCell(index);			}						} else {			link = cell.getElementsByTagName("a")[0];			if (link) {				link.blur();			}			cal.selectCell(index);		}	}};/*** The event that is executed when the user hovers over a cell* @method doCellMouseOver* @param {DOMEvent} e	The event* @param {Calendar} cal	A reference to the calendar passed by the Event utility*/YAHOO.widget.Calendar.prototype.doCellMouseOver = function(e, cal) {	var target;	if (e) {		target = YAHOO.util.Event.getTarget(e);	} else {		target = this;	}	while (target.tagName.toLowerCase() != "td") {		target = target.parentNode;		if (target.tagName.toLowerCase() == "html") {			return;		}	}	if (YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {		YAHOO.util.Dom.addClass(target, cal.Style.CSS_CELL_HOVER);	}};/*** The event that is executed when the user moves the mouse out of a cell* @method doCellMouseOut* @param {DOMEvent} e	The event* @param {Calendar} cal	A reference to the calendar passed by the Event utility*/YAHOO.widget.Calendar.prototype.doCellMouseOut = function(e, cal) {	var target;	if (e) {		target = YAHOO.util.Event.getTarget(e);	} else {		target = this;	}	while (target.tagName.toLowerCase() != "td") {		target = target.parentNode;		if (target.tagName.toLowerCase() == "html") {			return;		}	}	if (YAHOO.util.Dom.hasClass(target, cal.Style.CSS_CELL_SELECTABLE)) {		YAHOO.util.Dom.removeClass(target, cal.Style.CSS_CELL_HOVER);	}};YAHOO.widget.Calendar.prototype.setupConfig = function() {	/**	* The month/year representing the current visible Calendar date (mm/yyyy)	* @config pagedate	* @type String	* @default today's date	*/	this.cfg.addProperty("pagedate", { value:new Date(), handler:this.configPageDate } );	/**	* The date or range of dates representing the current Calendar selection	* @config selected	* @type String	* @default []	*/	this.cfg.addProperty("selected", { value:[], handler:this.configSelected } );	/**	* The title to display above the Calendar's month header	* @config title	* @type String	* @default ""	*/	this.cfg.addProperty("title", { value:"", handler:this.configTitle } );	/**	* Whether or not a close button should be displayed for this Calendar	* @config close	* @type Boolean	* @default false	*/	this.cfg.addProperty("close", { value:false, handler:this.configClose } );	/**	* Whether or not an iframe shim should be placed under the Calendar to prevent select boxes from bleeding through in Internet Explorer 6 and below.	* @config iframe	* @type Boolean	* @default true	*/	this.cfg.addProperty("iframe", { value:true, handler:this.configIframe, validator:this.cfg.checkBoolean } );	/**	* The minimum selectable date in the current Calendar (mm/dd/yyyy)	* @config mindate	* @type String	* @default null	*/	this.cfg.addProperty("mindate", { value:null, handler:this.configMinDate } );	/**	* The maximum selectable date in the current Calendar (mm/dd/yyyy)	* @config maxdate	* @type String	* @default null	*/	this.cfg.addProperty("maxdate", { value:null, handler:this.configMaxDate } );	// Options properties	/**	* True if the Calendar should allow multiple selections. False by default.	* @config MULTI_SELECT	* @type Boolean	* @default false	*/	this.cfg.addProperty("MULTI_SELECT",	{ value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } );	/**	* The weekday the week begins on. Default is 0 (Sunday).	* @config START_WEEKDAY	* @type number	* @default 0	*/	this.cfg.addProperty("START_WEEKDAY",	{ value:0, handler:this.configOptions, validator:this.cfg.checkNumber  } );	/**	* True if the Calendar should show weekday labels. True by default.	* @config SHOW_WEEKDAYS	* @type Boolean	* @default true	*/	this.cfg.addProperty("SHOW_WEEKDAYS",	{ value:true, handler:this.configOptions, validator:this.cfg.checkBoolean  } );	/**	* True if the Calendar should show week row headers. False by default.	* @config SHOW_WEEK_HEADER	* @type Boolean	* @default false	*/	this.cfg.addProperty("SHOW_WEEK_HEADER",{ value:false, handler:this.configOptions, validator:this.cfg.checkBoolean } );	/**	* True if the Calendar should show week row footers. False by default.	* @config SHOW_WEEK_FOOTER	* @type Boolean	* @default false	*/	

⌨️ 快捷键说明

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