📄 calendar-core.js
字号:
* calendar. (note, this is only for IE5; for IE5.5 there are better--albeit * uglier--workarounds). * * @param ev [Event] the event object * @return false */Zapatec.Calendar.calDragEnd = function (ev) { var cal = Zapatec.Calendar._C; Zapatec.Utils.removeEvent(window.document, "mousemove", Zapatec.Calendar.calDragIt); Zapatec.Utils.removeEvent(window.document, "mouseover", Zapatec.Calendar.calDragIt); Zapatec.Utils.removeEvent(window.document, "mouseup", Zapatec.Calendar.calDragEnd); if (!cal) { return false; } cal.dragging = false; Zapatec.Calendar.tableMouseUp(ev); cal.hideShowCovered();};//@}/** * Called when the mouse button is pressed upon a button. The name of this * function is so for historical reasons; currently, this function is used for * \em any type of buttons used in the calendar, not only "days". * * This function does quite some things. It checks if the clicked cell is the * title bar or the status bar, in which case it starts the calendar dragging * mechanism (cal._dragStart()). If the cell is a time part, then it registers * Zapatec.Calendar.tableMouseOver() event handler on the document. If the * cell is a "navigation" button (next/prev year or month, or today) then a * timeout is created that will show the appropriate combo box if the button is * not quickly depressed. * * @param ev [Event] the event object * @return false */Zapatec.Calendar.dayMouseDown = function(ev) { var canDrag = true; var el = Zapatec.Utils.getElement(ev); if (el.className.indexOf("disabled") != -1 || el.className.indexOf("true") != -1) { return false; } var cal = el.calendar; //BEGIN: fix for the extra information bug in IE while(!cal) { el = el.parentNode; cal = el.calendar; } //END cal.bEventShowHistory=false; // Set state the we DID NOT enter History event cal.activeDiv = el; Zapatec.Calendar._C = cal; if (el.navtype != 300) { if (el.navtype == 50) { //turns off changing the time by dragging if timeInterval is set if (!((cal.timeInterval == null) || ((cal.timeInterval < 60) && (el.className.indexOf("hour", 0) != -1)))) {canDrag = false;} el._current = el.firstChild.data; if (canDrag) {Zapatec.Utils.addEvent(window.document, "mousemove", Zapatec.Calendar.tableMouseOver);} } else { if (((el.navtype == 201) || (el.navtype == 202)) && (cal.timeInterval > 30) && (el.timePart.className.indexOf("minute", 0) != -1)) {canDrag = false;} if (canDrag) {Zapatec.Utils.addEvent(window.document, Zapatec.is_ie5 ? "mousemove" : "mouseover", Zapatec.Calendar.tableMouseOver);} } if (canDrag) {Zapatec.Utils.addClass(el, "hilite active");} Zapatec.Utils.addEvent(window.document, "mouseup", Zapatec.Calendar.tableMouseUp); } else if (cal.isPopup) { cal._dragStart(ev); } else { Zapatec.Calendar._C = null; } if (el.navtype == -1 || el.navtype == 1) { if (cal.timeout) clearTimeout(cal.timeout); cal.timeout = setTimeout("Zapatec.Calendar.showMonthsCombo()", 250); } else if (el.navtype == -2 || el.navtype == 2) { if (cal.timeout) clearTimeout(cal.timeout); cal.timeout = setTimeout((el.navtype > 0) ? "Zapatec.Calendar.showYearsCombo(true)" : "Zapatec.Calendar.showYearsCombo(false)", 250); } else if (el.navtype == 0 && Zapatec.Calendar.prefs.history) { if (cal.timeout) clearTimeout(cal.timeout); cal.timeout = setTimeout("Zapatec.Calendar.showHistoryCombo()", 250); } else { cal.timeout = null; } return Zapatec.Utils.stopEvent(ev);};/** * For IE5 we can't make unselectable elements, but we can void the selection * immediately after the double click event :D. This function is a double * click handler which does exactly that. Uses IE-specific functions. */Zapatec.Calendar.dayMouseDblClick = function(ev) { Zapatec.Calendar.cellClick(Zapatec.Utils.getElement(ev), ev || window.event); if (Zapatec.is_ie) window.document.selection.empty();};/** * This function gets called at "onmouseover" events that trigger on any kind * of button, like dates, navigation buttons, etc. Basically, the function * computes and caches the tooltip (if it's a date cell for instance) and * displays it in the status bar. If the cell is not a navigation button, it * will also add "rowhilite" class to the containing TR element. * * @param ev [Event] the event object. * @return false */Zapatec.Calendar.dayMouseOver = function(ev) { var el = Zapatec.Utils.getElement(ev), caldate = el.caldate; //BEGIN: fix for the extra information bug in IE while (!el.calendar) { el = el.parentNode; caldate = el.caldate; } //END var cal = el.calendar; var cel = el.timePart; if (caldate) { caldate = new Date(caldate[0], caldate[1], caldate[2]); if (caldate.getDate() != el.caldate[2]) caldate.setDate(el.caldate[2]); } if (Zapatec.Utils.isRelated(el, ev) || Zapatec.Calendar._C || el.className.indexOf("disabled") != -1 || el.className.indexOf("true") != -1) { return false; } if (el.ttip) { if (el.ttip.substr(0, 1) == "_") { el.ttip = caldate.print(el.calendar.ttDateFormat) + el.ttip.substr(1); } el.calendar.showHint(el.ttip); } if (el.navtype != 300) { //turns off highliting of the time part which can not be changed by dragging if (!((cal.timeInterval == null) || (el.className.indexOf("ampm", 0) != -1) || ((cal.timeInterval < 60) && (el.className.indexOf("hour", 0) != -1))) && (el.navtype == 50)) {return Zapatec.Utils.stopEvent(ev);} if (((el.navtype == 201) || (el.navtype == 202)) && (cal.timeInterval > 30) && (cel.className.indexOf("minute", 0) != -1)) {return Zapatec.Utils.stopEvent(ev);} Zapatec.Utils.addClass(el, "hilite"); if (caldate) { Zapatec.Utils.addClass(el.parentNode, "rowhilite"); } } return Zapatec.Utils.stopEvent(ev);};/** * Gets called when the mouse leaves a button. This function "undoes" what * dayMouseOver did, that is, it removes the "rowhilite" class from the * containing TR and restores the status bar display to read "Select date". * * @param ev [Event] the event object. * @return false */Zapatec.Calendar.dayMouseOut = function(ev) { var el = Zapatec.Utils.getElement(ev); //BEGIN: fix for the extra information bug in IE while (!el.calendar) { el = el.parentNode; caldate = el.caldate; } //END if (Zapatec.Utils.isRelated(el, ev) || Zapatec.Calendar._C || el.className.indexOf("disabled") != -1 || el.className.indexOf("true") != -1) return false; Zapatec.Utils.removeClass(el, "hilite"); if (el.caldate) Zapatec.Utils.removeClass(el.parentNode, "rowhilite"); if (el.calendar) el.calendar.showHint(Zapatec.Calendar.i18n("SEL_DATE")); return Zapatec.Utils.stopEvent(ev);};/** * The generic "click" handler. This function handles actions on any kind of * buttons that appear inside our calendar. It determines the button type by * querying \em el.navtype. The following types of objects are supported: * * - Date cells (navtype is undefined). The function will select that date, * add appropriate class names and remove them from the previously selected * date. If the date in the calendar \em has \em changed, it calls the * calendar's onSelect handler (see the constructor). If multiple dates is * enabled, it will not unselect previously selected date but rather maintain * an array of dates which will be avaliable to the onSelect or onClose * handler. * - The Close button (navtype == 200). If this is clicked, then the * calendar's onClose handler is called immediately. * - The Today button (navtype == 0). The calendar will jump to the "today" * date and time, unless it's already there. * - The About button (navtype == 400). It will display an alert with the * "about message", as defined in the translation file. * - Previous year (navtype == -2) * - Previous month (navtype == -1) * - Next month (navtype == 1) * - Next year (navtype == 2) * - Day names (navtype == 100). If any of them is clicked, the calendar will * display that day as the first day of week. It calls the "onFDOW" event * handler if defined. * - Time parts (navtype == 50). If any of them is clicked, this function will * determine if it's a click or shift-click, and will take the appropriate * action (simple click means add 1, shift-click means substract 1 from that * time part). Then it calls onUpdateTime() to refresh the display. * - Time scroll buttons (navtype == 201 or navtype == 202). If such buttons * are clicked, the time part involved is determined and it is incremented or * decremented with the current step (default: 5). 201 is for "add", 202 for * "substract". * * @param el [HTMLElement] the object being clicked on * @param ev [Event] the event object */Zapatec.Calendar.cellClick = function(el, ev) { var cal = el.calendar; var closing = false; var newdate = false; var date = null; //BEGIN: fix for the extra information bug in IE while(!cal) { el = el.parentNode; cal = el.calendar; } //END if (el.className.indexOf("disabled") != -1 || el.className.indexOf("true") != -1) { return false; } if (typeof el.navtype == "undefined") { if (cal.currentDateEl) { Zapatec.Utils.removeClass(cal.currentDateEl, "selected"); Zapatec.Utils.addClass(el, "selected"); closing = (cal.currentDateEl == el); if (!closing) { cal.currentDateEl = el; } } var tmpDate = new Date(el.caldate[0], el.caldate[1], el.caldate[2]); if (tmpDate.getDate() != el.caldate[2]) { tmpDate.setDate(el.caldate[2]); } cal.date.setDateOnly(tmpDate); cal.currentDate.setDateOnly(tmpDate); date = cal.date; cal.dateClicked = true; if (cal.multiple) cal._toggleMultipleDate(new Date(date)); newdate = true; // a date was clicked if (el.otherMonth) cal._init(cal.firstDayOfWeek, date); cal.onSetTime(); } else { if (el.navtype == 200) { Zapatec.Utils.removeClass(el, "hilite"); cal.callCloseHandler(); return; } date = new Date(cal.date); if (el.navtype == 0 && !cal.bEventShowHistory) // Set date to Today if Today clicked AND History NOT shown date.setDateOnly(new Date()); // TODAY // unless "today" was clicked, we assume no date was clicked so // the selected handler will know not to close the calenar when // in single-click mode. // cal.dateClicked = (el.navtype == 0); cal.dateClicked = false; var year = date.getFullYear(); var mon = date.getMonth(); function setMonth(m) { var day = date.getDate(); var max = date.getMonthDays(m); if (day > max) { date.setDate(max); } date.setMonth(m); }; switch (el.navtype) { case 400: Zapatec.Utils.removeClass(el, "hilite"); var text = Zapatec.Calendar.i18n("ABOUT"); if (typeof text != "undefined") { text += cal.showsTime ? Zapatec.Calendar.i18n("ABOUT_TIME") : ""; } else { // FIXME: this should be removed as soon as lang files get updated! text = "Help and about box text is not translated into this language.\n" + "If you know this language and you feel generous please update\n" + "the corresponding file in \"lang\" subdir to match calendar-en.js\n" + "and send it back to <support@zapatec.com> to get it into the distribution ;-)\n\n" + "Thank you!\n" + "http://www.zapatec.com\n"; } alert(text); return; case -2: if (year > cal.minYear) { date.setFullYear(year - 1); } break; case -1: if (mon > 0) { setMonth(mon - 1); } else if (year-- > cal.minYear) { date.setFullYear(year); setMonth(11); } break; case 1: if (mon < 11) { setMonth(mon + 1); } else if (year < cal.maxYear) { date.setFullYear(year + 1); setMonth(0); } break; case 2: if (year < cal.maxYear) { date.setFullYear(year + 1); } break; case 100: cal.setFirstDayOfWeek(el.fdow); Zapatec.Calendar.prefs.fdow = cal.firstDayOfWeek; Zapatec.Calendar.savePrefs(); if (cal.onFDOW) cal.onFDOW(cal.firstDayOfWeek); return; case 50: //turns off time changing if timeInterval is set with special value var date = cal.currentDate; if (el.className.indexOf("ampm", 0) >= 0) // always check ampm changes ; else if (!((cal.timeInterval == null) || ((cal.timeInterval < 60) && (el.className.indexOf("hour", 0) != -1)))) {break;} var range = el._range; var current = el.firstChild.data; var pm = (date.getHours() >= 12); for (var i = range.length; --i >= 0;) if (range[i] == current) break; if (ev && ev.shiftKey) { if (--i < 0) { i = range.length - 1; } } else if ( ++i >= range.length ) { i = 0; } //ALLOWED TIME CHECK if (cal.getDateStatus) { //Current time is changing, check with the callback to see if it's in range // 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 "ampm" was clicked if (el.className.indexOf("ampm", 0) != -1) { minute = date.getMinutes(); // minutes didn't change // if the "ampm" value has changed we need to correct hours (add 12 or exclude 12 or set it to zero) hour = (range[i] == Zapatec.Calendar.i18n("pm", "ampm")) ? ((date.getHours() == 12) ? (date.getHours()) : (date.getHours() + 12)) : (date.getHours() - 12); // if the time is disabled we seek the first one disabled. // It fixes the bug when you can not change from 'am' to 'pm' or vice versa for the dates that have restrictions for time. // This part of code is very easy to understand, so it don't need much comments if ( cal.getDateStatus && cal.getDateStatus(new_date, date.getFullYear(), date.getMonth(), date.getDate(), parseInt(hour, 10), parseInt(minute, 10)) ) { var dirrect; if (range[i] == Zapatec.Calendar.i18n("pm", "ampm")) { dirrect = -5; } else { dirrect = 5; } hours = hour; minutes = minute; do { minutes += dirrect; if (minutes >=60) { minutes -= 60; ++hours; if (hours >= 24) hours -= 24; new_date.setHours(hours); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -