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

📄 calendar.js

📁 尚洋仓库管理系统,对仓库
💻 JS
📖 第 1 页 / 共 5 页
字号:
			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			// remember, "date" was previously set to new			// Date() if TODAY was clicked; thus, it			// contains today date.			if (cal.getDateStatus && ((cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == true) || (cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()) == "disabled"))) {				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;	table.calendar = this;	Zapatec.Utils.addEvent(table, "mousedown", Zapatec.Calendar.tableMouseDown);	var div = Zapatec.Utils.createElement("div");	this.element = div;	div.className = "calendar";	//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) {		cell = Zapatec.Utils.createElement("td", row);		cell.colSpan = cs;		cell.className = "button";		if (Math.abs(navtype) <= 2)			cell.className += " nav";		Zapatec.Calendar._add_evs(cell);		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;	};	//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).ttip = Zapatec.Calendar.i18n("INFO");	} else {		cell = Zapatec.Utils.createElement("td", row);		cell.colSpan = 1;		cell.className = "button";		cell.innerHTML = "<p>&nbsp</p>";	}	this.title = hh("", title_length, 300);	this.title.className = "title";	if (this.isPopup) {		this.title.ttip = Zapatec.Calendar.i18n("DRAG_TO_MOVE");		this.title.style.cursor = "move";		hh("&#x00d7;", 1, 200).ttip = Zapatec.Calendar.i18n("CLOSE");	} else {		cell = Zapatec.Utils.createElement("td", row);		cell.colSpan = 1;		cell.className = "button";		cell.innerHTML = "<p>&nbsp</p>";	}	if (this.params && this.params.titleHtml)		this.title.innerHTML=this.params.titleHtml	row = Zapatec.Utils.createElement("tr", thead);	this._nav_py = hh("&#x00ab;", 1, -2);	this._nav_py.ttip = Zapatec.Calendar.i18n("PREV_YEAR");	this._nav_pm = hh("&#x2039;", 1, -1);	this._nav_pm.ttip = Zapatec.Calendar.i18n("PREV_MONTH");	this._nav_now = hh(Zapatec.Calendar.i18n("TODAY"), title_length - 2, 0);	this._nav_now.ttip = Zapatec.Calendar.i18n("GO_TODAY");	this._nav_nm = hh("&#x203a;", 1, 1);	this._nav_nm.ttip = Zapatec.Calendar.i18n("NEXT_MONTH");	this._nav_ny = hh("&#x00bb;", 1, 2);	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) {				cell = Zapatec.Utils.createElement("td", row);				cell.colSpan = 1;				cell.className = "button";				cell.innerHTML = "<p>&nbsp</p>";				this.titles[l][k] = hh("", title_length, 300);				this.titles[l][k].className = "title";				cell = Zapatec.Utils.createElement("td", row);				cell.colSpan = 1;				cell.className = "button";				cell.innerHTML = "<p>&nbsp</p>";			}		}	// 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 = "";					}					}			for (var i = 7; i > 0; --i) {				cell = Zapatec.Utils.createElement("td", row);				cell.appendChild(window.document.createTextNode(""));			}		}		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.appendChild(document.createTextNode(""));				}				for (var j = 7; j > 0; --j) {					cell = Zapatec.Utils.createElement("td", row);					cell.appendChild(document.createTextNode(""));					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() {			function makeTimePart(className, init, range_start, range_end) {				var table, tbody, tr, tr2, part;				if (range_end) {					cell = Zapatec.Utils.createElement("td", row);					cell.colSpan = 1;					if (cal.showsTime != "seconds") {						++cell.colSpan;					}					cell.className = "parent-" + className;					table = Zapatec.Utils.createElement("table", cell);					table.cellSpacing = table.cellPadding = 0;					if (className == "hour")						table.align = "right";					table.className = "calendar-time-scroller";					tbody = Zapatec.Utils.createElement("tbody", table);					tr    = Zapatec.Utils.createElement("tr", tbody);					tr2   = Zapatec.Utils.createElement("tr", tbody);				} else					tr = row;				part = Zapatec.Utils.createElement("td", tr);				part.className = className;				part.appendChild(window.document.createTextNode(init));				part.calendar = cal;				part.ttip = Zapatec.Calendar.i18n("TIME_PART");				part.navtype = 50;				part._range = [];				if (!range_end)					part._range = range_start;				else {					part.rowSpan = 2;					for (var i = range_start; i <= range_end; ++i) {						var txt;						if (i < 10 && range_end >= 10) txt = '0' + i;						else txt = '' + i;						part._range[part._range.length] = txt;					}					var up = Zapatec.Utils.createElement("td", tr);					up.className = "up";					up.navtype = 201;					up.calendar = cal;					up.timePart = part;					if (Zapatec.is_khtml)						up.innerHTML = "&nbsp;";					Zapatec.Calendar._add_evs(up);					var down = Zapatec.Utils.createElement("td", tr2);					down.className = "down";					down.navtype = 202;					down.calendar = cal;					down.timePart = part;					if (Zapatec.is_khtml)						down.innerHTML = "&nbsp;";					Zapatec.Calendar._add_evs(down);				}				Zapatec.Calendar._add_evs(part);				return part;			};			var hrs = cal.currentDate.getHours();			var mins = cal.currentDate.getMinutes();			if (cal.showsTime == "seconds") {				var secs = cal.currentDate.getSeconds();			}			var t12 = !cal.time24;			var pm = (hrs > 12);			if (t12 && pm) hrs -= 12;			var H = makeTimePart("hour", hrs, t12 ? 1 : 0, t12 ? 12 : 23);			//calculating of the step for hours			H._step = (cal.timeInterval > 30) ? (cal.timeInterval / 60) : 1;			cell = Zapatec.Utils.createElement("td", row);

⌨️ 快捷键说明

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