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

📄 calendar-core.js

📁 js日期插件
💻 JS
📖 第 1 页 / 共 5 页
字号:
					      if (minutes < 0) {						 minutes += 60;						 --hours;					  	 if (hours < 0) hours += 24;						 new_date.setHours(hours);					      }					      new_date.setMinutes(minutes);					      if (!cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hours, 10), parseInt(minutes, 10))) {						 hour = hours;						 minute = minutes;						 if (hour > 12) i = 1; else i = 0;						 cal.date.setHours(hour);						 cal.date.setMinutes(minute);						 cal.onSetTime();					      }					   } while ((hour != hours) || (minute != minutes));					}					// updates our new Date object that will be passed to the handler					new_date.setHours(hour);				}				// if hours were clicked				if (el.className.indexOf("hour", 0) != -1) {				   minute = date.getMinutes(); // minutes didn't change				   hour = (!cal.time24) ? ((pm) ? ((range[i] != 12) ? (parseInt(range[i], 10) + 12) : (12)) : ((range[i] != 12) ? (range[i]) : (0))) : (range[i]);  // new value of hours				   new_date.setHours(hour);				}				// if minutes were clicked				if (el.className.indexOf("minute", 0) != -1) {				   hour = date.getHours(); // hours didn't change				   minute = range[i]; // new value of minutes				   new_date.setMinutes(minute);				}			}			var status = false;			// if the handler is set, we pass new values and retreive result in "status" variable			if (cal.getDateStatus) {			   status = cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10));			}			if (!status) {			   el.firstChild.data = range[i];			}			//END OF ALLOWED TIME CHECK			cal.onUpdateTime();			return;		    case 201: // timepart, UP		    case 202: // timepart, DOWN			var cel = el.timePart;			//turns off time changing if timeInterval is set with special value			var date = cal.currentDate;			if ((cel.className.indexOf("minute", 0) != -1) && (cal.timeInterval > 30)) {break;}			var val = parseInt(cel.firstChild.data, 10);			var pm = (date.getHours() >= 12);			var range = cel._range;			for (var i = range.length; --i >= 0;)				if (val == range[i]) {					val = i;					break;				}			var step = cel._step;			if (el.navtype == 201) {				val = step*Math.floor(val/step);				val += step;				if (val >= range.length)					val = 0;			} else {				val = step*Math.ceil(val/step);				val -= step;				if (val < 0)					val = range.length-step;			}			//ALLOWED TIME CHECK			if (cal.getDateStatus) { //Current time is changing, check with the callback to see if it's in range of allowed times			   // Fills "minute" and "hour" variables with the time that user wants to set, to pass them to the dateStatusHandler.			   // As the script passes hours in 24 format, we need to convert inputed values if they are not in the needed format						   var minute = null; // minutes to be passed			   var hour = null; // hours to be passed			   // as we pass date element to the handler, we need to create new one and fill it with new minutes or hours (depending on what had changed)			   var new_date = new Date(date);			   // if hours were changed			   if (cel.className == "hour") {			      minute = date.getMinutes();			      hour = (!cal.time24) ? ((pm) ? ((range[val] != 12) ? (parseInt(range[val], 10) + 12) : (12)) : ((range[val] != 12) ? (range[val]) : (0))) : (range[val]);			      new_date.setHours(hour);			   }			   // if minutes were changed			   if (cel.className == "minute") {			      hour = date.getHours();			      minute = val;			      new_date.setMinutes(range[val]);			   }			}			var status = false;			// if the handler is set, we pass new values and retreive result in "status" variable			if (cal.getDateStatus) {			   status = cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10));			}   			if (!status) {			   cel.firstChild.data = range[val];			}			cal.onUpdateTime();			//END OF ALLOWED TIME CHECK			return;		    case 0:			// TODAY will bring us here			//fix for the today bug for the special dates			if (cal.getDateStatus && ((cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == true) || (cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == "disabled"))) {				// remember, "date" was previously set to new				// Date() if TODAY was clicked; thus, it				// contains today date.				return false;			}			break;		}		if (!date.equalsTo(cal.date)) {			if ((el.navtype >= -2 && el.navtype <=2) && (el.navtype != 0)) {				cal._init(cal.firstDayOfWeek, date, true);				return;			}			cal.setDate(date);			newdate = !(el.navtype && (el.navtype >= -2 && el.navtype <=2));		}	}	if (newdate) {		cal.callHandler();	}	if (closing) {		Zapatec.Utils.removeClass(el, "hilite");		cal.callCloseHandler();	}};// END: CALENDAR STATIC FUNCTIONS// BEGIN: CALENDAR OBJECT FUNCTIONS/** * This function creates the calendar HTML elements inside the given parent. * If _par is null than it creates a popup calendar inside the BODY element. * If _par is an element, be it BODY, then it creates a non-popup calendar * (still hidden). * * The function looks rather complicated, but what it does is quite simple. * The basic calendar elements will be created, that is, a containing DIV, a * TABLE that contains a headers (titles, navigation bar and day names bars), a * body containing up to 12 months, each has 6 rows with 7 or 8 cells (this depends on whether week * numbers are on or off) and a footer containing the status bar.  Appropriate * event handlers are assigned to all buttons or to the titles and status bar * (for drag'n'drop). * * This function also builds the time selector if the calendar is configured * so, and it also creates the elements required for combo boxes (years, * months, history). * * This function does not display day names or dates.  This is done in * Zapatec.Calendar.prototype._init().  Therefore, by separating these 2 * actions we can make date switching happen much faster because the _init * function will already have the elements in place (so we don't need to create * them again and again).  This was a major improvement which got in * the calendar v0.9.1. * * @param _par */Zapatec.Calendar.prototype.create = function (_par) {	var parent = null;	if (! _par) {		// default parent is the document body, in which case we create		// a popup calendar.		parent = window.document.getElementsByTagName("body")[0];		this.isPopup = true;		this.WCH = Zapatec.Utils.createWCH();	} else {		parent = _par;		this.isPopup = false;	}	this.currentDate = this.date = this.dateStr ? new Date(this.dateStr) : new Date();	var table = Zapatec.Utils.createElement("table");	this.table = table;	table.cellSpacing = 0;	table.cellPadding = 0;	Zapatec.Utils.createProperty(table, "calendar", this);	Zapatec.Utils.addEvent(table, "mousedown", Zapatec.Calendar.tableMouseDown);	var div = Zapatec.Utils.createElement("div");	this.element = div;	div.className = "calendar";	div.id = "zpCal" + this.id + "Container";	//FIX for Opera's bug with row highlighting	if (Zapatec.is_opera) {		table.style.width = (this.monthsInRow * ((this.weekNumbers) ? (8) : (7)) * 2 + 4.4 * this.monthsInRow) + "em";	}	if (this.isPopup) {		div.style.position = "absolute";		div.style.display = "none";	}	div.appendChild(table);	var cell = null;	var row = null;	var cal = this;	var hh = function (text, cs, navtype, buttonType) {		cell = Zapatec.Utils.createElement("td", row);		if (buttonType) {			cell.id = "zpCal" + cal.id + buttonType + "ButtonStatus";		}		cell.colSpan = cs;		cell.className = "button";		if (Math.abs(navtype) <= 2)			cell.className += " nav";		Zapatec.Calendar._add_evs(cell);		Zapatec.Utils.createProperty(cell, "calendar", cal);		cell.navtype = navtype;		if (text.substr(0, 1) != "&") {			cell.appendChild(document.createTextNode(text));		}		else {			// FIXME: dirty hack for entities			cell.innerHTML = text;		}		return cell;	};	var hd = function(par, colspan, buttonType) {		cell = Zapatec.Utils.createElement("td", par);		if (buttonType) {			cell.id = "zpCal" + cal.id + buttonType + "ButtonStatus";		}		cell.colSpan = colspan;		cell.className = "button";		cell.innerHTML = "<div>&nbsp</div>";		return cell;	};	//Creating all the controls on the top	var title_length = ((this.weekNumbers) ? (8) : (7)) * this.monthsInRow - 2;	var thead = Zapatec.Utils.createElement("thead", table);	if (this.numberMonths == 1) {		this.title = thead;	}	row = Zapatec.Utils.createElement("tr", thead);	if (this.helpButton) {		hh("?", 1, 400, "Help").ttip = Zapatec.Calendar.i18n("INFO");	} else {		hd(row, 1, "Help");	}	this.title = hh("&nbsp;", title_length, 300);	this.title.className = "title";	this.title.id = "zpCal" + this.id + "Title";	if (this.isPopup) {		if (!this.disableDrag) {			this.title.ttip = Zapatec.Calendar.i18n("DRAG_TO_MOVE");			this.title.style.cursor = "move";		}		if (this.closeButton) {			hh("&#x00d7;", 1, 200, "Close").ttip = Zapatec.Calendar.i18n("CLOSE");		} else {			hd(row, 1, "Close");		}	} else {		hd(row, 1, "Close");	}	row = Zapatec.Utils.createElement("tr", thead);	this._nav_py = hh("&#x00ab;", 1, -2, "PrevYear");	this._nav_py.ttip = Zapatec.Calendar.i18n("PREV_YEAR");	this._nav_pm = hh("&#x2039;", 1, -1, "PrevMonth");	this._nav_pm.ttip = Zapatec.Calendar.i18n("PREV_MONTH");	this._nav_now = hh(Zapatec.Calendar.i18n("TODAY"), title_length - 2, 0, "Today");	this._nav_now.ttip = Zapatec.Calendar.i18n("GO_TODAY");	this._nav_nm = hh("&#x203a;", 1, 1, "NextMonth");	this._nav_nm.ttip = Zapatec.Calendar.i18n("NEXT_MONTH");	this._nav_ny = hh("&#x00bb;", 1, 2, "NextYear");	this._nav_ny.ttip = Zapatec.Calendar.i18n("NEXT_YEAR");	//Here we calculate the number of rows for multimonth calendar	var rowsOfMonths = Math.floor(this.numberMonths / this.monthsInRow);	if (this.numberMonths % this.monthsInRow > 0) {		++rowsOfMonths;	}	//Every iteration of this cycle creates a row of months in the calendar	for (var l = 1; l <= rowsOfMonths; ++l) {		var thead = Zapatec.Utils.createElement("thead", table);		//Fix for the Operas bug, this is a workaround which makes Opera display THEAD elements as TBODY el.		//The problem is that Opera displays all the THEAD elements in the table first, and only then TBODY elements (an ugly look!).		if (Zapatec.is_opera) {thead.style.display = "table-row-group";}		if (this.numberMonths != 1) {			row = Zapatec.Utils.createElement("tr", thead);			var title_length = 5;			this.weekNumbers && ++title_length;			//creating the titles for the months			this.titles[l] = new Array();			for (var k = 1; (k <= this.monthsInRow) && ((l - 1) * this.monthsInRow + k <= this.numberMonths); ++k) {				hd(row, 1);				this.titles[l][k] = hh("&nbsp;", title_length, 300);				this.titles[l][k].className = "title";				this.titles[l][k].id = "zpCal" + this.id + "SubTitle" + ((l - 1) * this.monthsInRow + k);				hd(row, 1);			}		}	// day names		row = Zapatec.Utils.createElement("tr", thead);		row.className = "daynames";		for (k = 1; (k <= this.monthsInRow) && ((l - 1) * this.monthsInRow + k <= this.numberMonths); ++k) {			if (this.weekNumbers) {				cell = Zapatec.Utils.createElement("td", row);				cell.className = "name wn";				cell.appendChild(window.document.createTextNode(Zapatec.Calendar.i18n("WK")));				if (k > 1) {					Zapatec.Utils.addClass(cell, "month-left-border");				}				var cal_wk = Zapatec.Calendar.i18n("WK")					if (cal_wk == null) {						//if it's not defined in the language file, leave it blank						cal_wk = "";					}					}			//week day names cells			for (var i = 7; i > 0; --i) {				cell = Zapatec.Utils.createElement("td", row);				cell.appendChild(document.createTextNode("&nbsp;"));				cell.id = "zpCal" + this.id + "WeekDayButton" + (7 - i) + "Status";			}		}		this.firstdayname = row.childNodes[this.weekNumbers?1:0];		this.rowsOfDayNames[l] = this.firstdayname; 		this._displayWeekdays();		var tbody = Zapatec.Utils.createElement("tbody", table);		this.tbody[l] = tbody;				for (i = 6; i > 0; --i) {			//creating a row of days for all the months in the row			row = Zapatec.Utils.createElement("tr", tbody);			for (k = 1; (k <= this.monthsInRow) && ((l - 1) * this.monthsInRow + k <= this.numberMonths); ++k) {				if (this.weekNumbers) {					cell = Zapatec.Utils.createElement("td", row);					cell.id = "zpCal" + this.id + "WeekNumber" + (6 - i);					cell.appendChild(document.createTextNode("&nbsp;"));				}				for (var j = 7; j > 0; --j) {					cell = Zapatec.Utils.createElement("td", row);					cell.id = "zpCal" + this.id + "DateCell" + ((l - 1) * this.monthsInRow + k) + "-" + (6 - i) + "-" + (7 - j);					cell.appendChild(document.createTextNode("&nbsp;"));					Zapatec.Utils.createProperty(cell, "calendar", this);					Zapatec.Calendar._add_evs(cell);				}			}		}	}	var tfoot = Zapatec.Utils.createElement("tfoot", table);	if (this.showsTime) {		row = Zapatec.Utils.createElement("tr", tfoot);		row.className = "time";		//empty area for positioning the time controls under the control month		var emptyColspan;		if (this.monthsInRow != 1) {			cell = Zapatec.Utils.createElement("td", row);			emptyColspan = cell.colSpan = Math.ceil((((this.weekNumbers) ? 8 : 7) * (this.monthsInRow - 1)) / 2);			cell.className = "timetext";			cell.innerHTML = "&nbsp";		}								cell = Zapatec.Utils.createElement("td", row);		cell.className = "timetext";		cell.colSpan = this.weekNumbers ? 2 : 1;		cell.innerHTML = Zapatec.Calendar.i18n("TIME") || "&nbsp;";		(function() {

⌨️ 快捷键说明

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