?? calendar-core.js
字號:
function makeTimePart(className, partId, 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.id = "zpTime" + cal.id + partId + "SelectStatus"; part.appendChild(window.document.createTextNode(init)); Zapatec.Utils.createProperty(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.id = "zpTime" + cal.id + partId + "UpButtonStatus"; Zapatec.Utils.createProperty(up, "calendar", cal); up.timePart = part; if (Zapatec.is_khtml) up.innerHTML = " "; Zapatec.Calendar._add_evs(up); var down = Zapatec.Utils.createElement("td", tr2); down.className = "down"; down.navtype = 202; down.id = "zpTime" + cal.id + partId + "DownButtonStatus"; Zapatec.Utils.createProperty(down, "calendar", cal); down.timePart = part; if (Zapatec.is_khtml) down.innerHTML = " "; 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", "Hours", 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); cell.innerHTML = ":"; cell.className = "colon"; var M = makeTimePart("minute", "Minutes", mins, 0, 59); //calculating of the step for minutes M._step = ((cal.timeInterval) && (cal.timeInterval < 60)) ? (cal.timeInterval) : 5; // FIXME: make this part configurable if (cal.showsTime == "seconds") { cell = Zapatec.Utils.createElement("td", row); cell.innerHTML = ":"; cell.className = "colon"; var S = makeTimePart("minute", "Seconds", secs, 0, 59); S._step = 5; } var AP = null; if (t12) { AP = makeTimePart("ampm", "AMPM", pm ? Zapatec.Calendar.i18n("pm", "ampm") : Zapatec.Calendar.i18n("am", "ampm"), [Zapatec.Calendar.i18n("am", "ampm"), Zapatec.Calendar.i18n("pm", "ampm")]); AP.className += " button"; } else Zapatec.Utils.createElement("td", row).innerHTML = " "; cal.onSetTime = function() { var hrs = this.currentDate.getHours(); var mins = this.currentDate.getMinutes(); if (this.showsTime == "seconds") { var secs = cal.currentDate.getSeconds(); } if (this.timeInterval) { mins += this.timeInterval - ((mins - 1 + this.timeInterval) % this.timeInterval) - 1; } while (mins >= 60) { mins -= 60; ++hrs; } if (this.timeInterval > 60) { var interval = this.timeInterval / 60; if (hrs % interval != 0) { hrs += interval - ((hrs - 1 + interval) % interval) - 1; } if (hrs >= 24) {hrs -= 24;} } //ALLOWED TIME CHECK // This part of code seeks for the first enabled time value for this date. // It is written for the cases when you change day, month or year and the time value is disabled for the new date. // So if you only allow 8:00 - 17:00 on Mondays and you change the date to a Monday but the time is 7:00 it will // automatically move forward to 8:00. var new_date = new Date(this.currentDate); if (this.getDateStatus && this.getDateStatus(this.currentDate, this.currentDate.getFullYear(), this.currentDate.getMonth(), this.currentDate.getDate(), hrs, mins)) { hours = hrs; minutes = mins; do { if (this.timeInterval) { if (this.timeInterval < 60) { minutes += this.timeInterval; } else { hrs += this.timeInterval / 60; } } else { minutes += 5; } if (minutes >=60) { minutes -= 60; hours += 1; } if (hours >= 24) {hours -= 24;} new_date.setMinutes(minutes); new_date.setHours(hours); if (!this.getDateStatus(new_date, this.currentDate.getFullYear(), this.currentDate.getMonth(), this.currentDate.getDate(), hours, minutes)) { hrs = hours; mins = minutes; } } while ((hrs != hours) || (mins != minutes)); } //END OF ALLOWED TIME CHECK this.currentDate.setMinutes(mins); this.currentDate.setHours(hrs); var pm = (hrs >= 12); if (pm && t12 && hrs != 12) hrs -= 12; if (!pm && t12 && hrs == 0) hrs = 12; H.firstChild.data = (hrs < 10) ? ("0" + hrs) : hrs; M.firstChild.data = (mins < 10) ? ("0" + mins) : mins; if (this.showsTime == "seconds") { S.firstChild.data = (secs < 10) ? ("0" + secs) : secs; } if (t12) AP.firstChild.data = pm ? Zapatec.Calendar.i18n("pm", "ampm") : Zapatec.Calendar.i18n("am", "ampm"); }; cal.onUpdateTime = function() { var date = this.currentDate; var h = parseInt(H.firstChild.data, 10); if (t12) { if (/pm/i.test(AP.firstChild.data) && h < 12) h += 12; else if (/am/i.test(AP.firstChild.data) && h == 12) h = 0; } var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); date.setHours(h); date.setMinutes(parseInt(M.firstChild.data, 10)); if (this.showsTime == "seconds") { date.setSeconds(parseInt(S.firstChild.data, 10)); } date.setFullYear(y); date.setMonth(m); date.setDate(d); this.dateClicked = false; this.callHandler(); }; })(); //empty area after the time controls if (this.monthsInRow != 1) { cell = Zapatec.Utils.createElement("td", row); cell.colSpan = ((this.weekNumbers) ? 8 : 7) * (this.monthsInRow - 1) - Math.ceil(emptyColspan); cell.className = "timetext"; cell.innerHTML = " "; } } else { this.onSetTime = this.onUpdateTime = function() {}; } row = Zapatec.Utils.createElement("tr", tfoot); row.className = "footrow"; cell = hh(Zapatec.Calendar.i18n("SEL_DATE"), this.weekNumbers ? (8 * this.numberMonths) : (7 * this.numberMonths), 300); cell.className = "ttip"; cell.id = "zpCal" + this.id + "Status"; if (this.isPopup && !this.disableDrag) { cell.ttip = Zapatec.Calendar.i18n("DRAG_TO_MOVE"); cell.style.cursor = "move"; } this.tooltips = cell; div = this.monthsCombo = Zapatec.Utils.createElement("div", this.element); div.className = "combo"; div.id = "zpCal" + this.id + "MonthDropdownCombo"; for (i = 0; i < 12; ++i) { var mn = Zapatec.Utils.createElement("div"); mn.className = Zapatec.is_ie ? "label-IEfix" : "label"; mn.id = "zpCal" + this.id + "MonthDropdownItem" + i; mn.month = i; mn.appendChild(window.document.createTextNode(Zapatec.Calendar.i18n(i, "smn"))); div.appendChild(mn); } div = this.yearsCombo = Zapatec.Utils.createElement("div", this.element); div.className = "combo"; div.id = "zpCal" + this.id + "YearDropdownCombo"; for (i = 0; i < 12; ++i) { var yr = Zapatec.Utils.createElement("div"); yr.className = Zapatec.is_ie ? "label-IEfix" : "label"; yr.id = "zpCal" + this.id + "YearDropdownItem" + i; yr.appendChild(window.document.createTextNode(" ")); div.appendChild(yr); } div = this.histCombo = Zapatec.Utils.createElement("div", this.element); div.id = "zpCal" + this.id + "HistoryDropdownCombo"; div.className = "combo history"; this._init(this.firstDayOfWeek, this.date); parent.appendChild(this.element);};/** * This function handles keypress events that occur while a popup calendar is * displayed. The implementation is quite complicated; this function calls * cellClick in order to set the new date as if it was clicked. * * @param ev [Event] the event object * @return false */Zapatec.Calendar._keyEvent = function(ev) { if (!window.calendar) { return false; } (Zapatec.is_ie) && (ev = window.event); var cal = window.calendar; var act = (Zapatec.is_ie || ev.type == "keypress"); var K = ev.keyCode; var date = new Date(cal.date); if (ev.ctrlKey) { switch (K) { case 37: // KEY left act && Zapatec.Calendar.cellClick(cal._nav_pm); break; case 38: // KEY up act && Zapatec.Calendar.cellClick(cal._nav_py); break; case 39: // KEY right act && Zapatec.Calendar.cellClick(cal._nav_nm); break; case 40: // KEY down act && Zapatec.Calendar.cellClick(cal._nav_ny); break; default: return false; } } else switch (K) { case 32: // KEY space (now) Zapatec.Calendar.cellClick(cal._nav_now); break; case 27: // KEY esc act && cal.callCloseHandler(); break; //Fix for the key navigation case 37: // KEY left if (act && !cal.multiple) { date.setTime(date.getTime() - 86400000); cal.setDate(date); } break; case 38: // KEY up if (act && !cal.multiple) { date.setTime(date.getTime() - 7 * 86400000); cal.setDate(date); } break; case 39: // KEY right if (act && !cal.multiple) { date.setTime(date.getTime() + 86400000); cal.setDate(date); } break; case 40: // KEY down if (act && !cal.multiple) { date.setTime(date.getTime() + 7 * 86400000); cal.setDate(date); } break; case 13: // KEY enter if (act) { //FIX for Enter key! Zapatec.Calendar.cellClick(cal.currentDateEl); } break; default: return false; } return Zapatec.Utils.stopEvent(ev);};/** * (RE)Initializes the calendar to the given date and firstDayOfWeek. * * This function perform the action of actually displaying the day names and * dates in the calendar. But first, it checks if the passed date fits in the * allowed range, configured by the "minYear", "maxYear", "minMonth" and * "maxMonth" properties of the Calendar object. * * It takes care to highlight special days (calling the * calendar.getDateStatus() function which can be overridden by external * scripts) or to highlight any dates that might be selected (for instance when * multiple dates is on, this function will call _initMultipleDates() to * highlight selected dates accordingly). * * This function is highly optimized for speed, therefore the code in it is not * trivial and what it does might not seem obvious. :-) So, WARNING, this is * voodoo. If you want to properly understand the code you should analyze it * line by line and try to execute it step by step; use the Venkman JS * debugger. * * @param firstDayOfWeek [int] the first day of week, 0 for Sunday, 1 for Monday, etc. * @param date [Date] the date to initialize the calendar to * */Zapatec.Calendar.prototype._init = function (firstDayOfWeek, date, last) { var today = new Date(), TD = today.getDate(), TY = today.getFullYear(), TM = today.getMonth(); //this.table.style.visibility = "hidden"; if (this.getDateStatus && !last) { var status = this.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()); var backupDate = new Date(date); while (((status == true) || (status == "disabled")) && (backupDate.getMonth() == date.getMonth())) { date.setTime(date.getTime() + 86400000); var status = this.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()); } if (backupDate.getMonth() != date.getMonth()) { date = new Date(backupDate); while (((status == true) || (status == "disabled")) && (backupDate.getMonth() == date.getMonth())) { date.setTime(date.getTime() - 86400000); var status = this.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate()); } } if (backupDate.getMonth() != date.getMonth()) { last = true; date = new Date(backupDate); } } var year = date.getFullYear(); var month = date.getMonth(); var rowsOfMonths = Math.floor(this.numberMonths / this.monthsInRow); var minMonth; var diffMonth, last_row, before_control; if (!this.vertical) { dif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -