Chris@0: /* Copyright Mihai Bazon, 2002-2005 | www.bazon.net/mishoo Chris@0: * ----------------------------------------------------------- Chris@0: * Chris@0: * The DHTML Calendar, version 1.0 "It is happening again" Chris@0: * Chris@0: * Details and latest version at: Chris@0: * www.dynarch.com/projects/calendar Chris@0: * Chris@0: * This script is developed by Dynarch.com. Visit us at www.dynarch.com. Chris@0: * Chris@0: * This script is distributed under the GNU Lesser General Public License. Chris@0: * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html Chris@0: */ Chris@0: Chris@0: // $Id: calendar.js,v 1.51 2005/03/07 16:44:31 mishoo Exp $ Chris@0: Chris@0: /** The Calendar object constructor. */ Chris@0: Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) { Chris@0: // member variables Chris@0: this.activeDiv = null; Chris@0: this.currentDateEl = null; Chris@0: this.getDateStatus = null; Chris@0: this.getDateToolTip = null; Chris@0: this.getDateText = null; Chris@0: this.timeout = null; Chris@0: this.onSelected = onSelected || null; Chris@0: this.onClose = onClose || null; Chris@0: this.dragging = false; Chris@0: this.hidden = false; Chris@0: this.minYear = 1970; Chris@0: this.maxYear = 2050; Chris@0: this.dateFormat = Calendar._TT["DEF_DATE_FORMAT"]; Chris@0: this.ttDateFormat = Calendar._TT["TT_DATE_FORMAT"]; Chris@0: this.isPopup = true; Chris@0: this.weekNumbers = true; Chris@0: this.firstDayOfWeek = typeof firstDayOfWeek == "number" ? firstDayOfWeek : Calendar._FD; // 0 for Sunday, 1 for Monday, etc. Chris@0: this.showsOtherMonths = false; Chris@0: this.dateStr = dateStr; Chris@0: this.ar_days = null; Chris@0: this.showsTime = false; Chris@0: this.time24 = true; Chris@0: this.yearStep = 2; Chris@0: this.hiliteToday = true; Chris@0: this.multiple = null; Chris@0: // HTML elements Chris@0: this.table = null; Chris@0: this.element = null; Chris@0: this.tbody = null; Chris@0: this.firstdayname = null; Chris@0: // Combo boxes Chris@0: this.monthsCombo = null; Chris@0: this.yearsCombo = null; Chris@0: this.hilitedMonth = null; Chris@0: this.activeMonth = null; Chris@0: this.hilitedYear = null; Chris@0: this.activeYear = null; Chris@0: // Information Chris@0: this.dateClicked = false; Chris@0: Chris@0: // one-time initializations Chris@0: if (typeof Calendar._SDN == "undefined") { Chris@0: // table of short day names Chris@0: if (typeof Calendar._SDN_len == "undefined") Chris@0: Calendar._SDN_len = 3; Chris@0: var ar = new Array(); Chris@0: for (var i = 8; i > 0;) { Chris@0: ar[--i] = Calendar._DN[i].substr(0, Calendar._SDN_len); Chris@0: } Chris@0: Calendar._SDN = ar; Chris@0: // table of short month names Chris@0: if (typeof Calendar._SMN_len == "undefined") Chris@0: Calendar._SMN_len = 3; Chris@0: ar = new Array(); Chris@0: for (var i = 12; i > 0;) { Chris@0: ar[--i] = Calendar._MN[i].substr(0, Calendar._SMN_len); Chris@0: } Chris@0: Calendar._SMN = ar; Chris@0: } Chris@0: }; Chris@0: Chris@0: // ** constants Chris@0: Chris@0: /// "static", needed for event handlers. Chris@0: Calendar._C = null; Chris@0: Chris@0: /// detect a special case of "web browser" Chris@0: Calendar.is_ie = ( /msie/i.test(navigator.userAgent) && Chris@0: !/opera/i.test(navigator.userAgent) ); Chris@0: Chris@0: Calendar.is_ie5 = ( Calendar.is_ie && /msie 5\.0/i.test(navigator.userAgent) ); Chris@0: Chris@0: /// detect Opera browser Chris@0: Calendar.is_opera = /opera/i.test(navigator.userAgent); Chris@0: Chris@0: /// detect KHTML-based browsers Chris@0: Calendar.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent); Chris@0: Chris@0: // BEGIN: UTILITY FUNCTIONS; beware that these might be moved into a separate Chris@0: // library, at some point. Chris@0: Chris@0: Calendar.getAbsolutePos = function(el) { Chris@0: var SL = 0, ST = 0; Chris@0: var is_div = /^div$/i.test(el.tagName); Chris@0: if (is_div && el.scrollLeft) Chris@0: SL = el.scrollLeft; Chris@0: if (is_div && el.scrollTop) Chris@0: ST = el.scrollTop; Chris@0: var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST }; Chris@0: if (el.offsetParent) { Chris@0: var tmp = this.getAbsolutePos(el.offsetParent); Chris@0: r.x += tmp.x; Chris@0: r.y += tmp.y; Chris@0: } Chris@0: return r; Chris@0: }; Chris@0: Chris@0: Calendar.isRelated = function (el, evt) { Chris@0: var related = evt.relatedTarget; Chris@0: if (!related) { Chris@0: var type = evt.type; Chris@0: if (type == "mouseover") { Chris@0: related = evt.fromElement; Chris@0: } else if (type == "mouseout") { Chris@0: related = evt.toElement; Chris@0: } Chris@0: } Chris@0: while (related) { Chris@0: if (related == el) { Chris@0: return true; Chris@0: } Chris@0: related = related.parentNode; Chris@0: } Chris@0: return false; Chris@0: }; Chris@0: Chris@0: Calendar.removeClass = function(el, className) { Chris@0: if (!(el && el.className)) { Chris@0: return; Chris@0: } Chris@0: var cls = el.className.split(" "); Chris@0: var ar = new Array(); Chris@0: for (var i = cls.length; i > 0;) { Chris@0: if (cls[--i] != className) { Chris@0: ar[ar.length] = cls[i]; Chris@0: } Chris@0: } Chris@0: el.className = ar.join(" "); Chris@0: }; Chris@0: Chris@0: Calendar.addClass = function(el, className) { Chris@0: Calendar.removeClass(el, className); Chris@0: el.className += " " + className; Chris@0: }; Chris@0: Chris@0: // FIXME: the following 2 functions totally suck, are useless and should be replaced immediately. Chris@0: Calendar.getElement = function(ev) { Chris@0: var f = Calendar.is_ie ? window.event.srcElement : ev.currentTarget; Chris@0: while (f.nodeType != 1 || /^div$/i.test(f.tagName)) Chris@0: f = f.parentNode; Chris@0: return f; Chris@0: }; Chris@0: Chris@0: Calendar.getTargetElement = function(ev) { Chris@0: var f = Calendar.is_ie ? window.event.srcElement : ev.target; Chris@0: while (f.nodeType != 1) Chris@0: f = f.parentNode; Chris@0: return f; Chris@0: }; Chris@0: Chris@0: Calendar.stopEvent = function(ev) { Chris@0: ev || (ev = window.event); Chris@0: if (Calendar.is_ie) { Chris@0: ev.cancelBubble = true; Chris@0: ev.returnValue = false; Chris@0: } else { Chris@0: ev.preventDefault(); Chris@0: ev.stopPropagation(); Chris@0: } Chris@0: return false; Chris@0: }; Chris@0: Chris@0: Calendar.addEvent = function(el, evname, func) { Chris@0: if (el.attachEvent) { // IE Chris@0: el.attachEvent("on" + evname, func); Chris@0: } else if (el.addEventListener) { // Gecko / W3C Chris@0: el.addEventListener(evname, func, true); Chris@0: } else { Chris@0: el["on" + evname] = func; Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.removeEvent = function(el, evname, func) { Chris@0: if (el.detachEvent) { // IE Chris@0: el.detachEvent("on" + evname, func); Chris@0: } else if (el.removeEventListener) { // Gecko / W3C Chris@0: el.removeEventListener(evname, func, true); Chris@0: } else { Chris@0: el["on" + evname] = null; Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.createElement = function(type, parent) { Chris@0: var el = null; Chris@0: if (document.createElementNS) { Chris@0: // use the XHTML namespace; IE won't normally get here unless Chris@0: // _they_ "fix" the DOM2 implementation. Chris@0: el = document.createElementNS("http://www.w3.org/1999/xhtml", type); Chris@0: } else { Chris@0: el = document.createElement(type); Chris@0: } Chris@0: if (typeof parent != "undefined") { Chris@0: parent.appendChild(el); Chris@0: } Chris@0: return el; Chris@0: }; Chris@0: Chris@0: // END: UTILITY FUNCTIONS Chris@0: Chris@0: // BEGIN: CALENDAR STATIC FUNCTIONS Chris@0: Chris@0: /** Internal -- adds a set of events to make some element behave like a button. */ Chris@0: Calendar._add_evs = function(el) { Chris@0: with (Calendar) { Chris@0: addEvent(el, "mouseover", dayMouseOver); Chris@0: addEvent(el, "mousedown", dayMouseDown); Chris@0: addEvent(el, "mouseout", dayMouseOut); Chris@0: if (is_ie) { Chris@0: addEvent(el, "dblclick", dayMouseDblClick); Chris@0: el.setAttribute("unselectable", true); Chris@0: } Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.findMonth = function(el) { Chris@0: if (typeof el.month != "undefined") { Chris@0: return el; Chris@0: } else if (typeof el.parentNode.month != "undefined") { Chris@0: return el.parentNode; Chris@0: } Chris@0: return null; Chris@0: }; Chris@0: Chris@0: Calendar.findYear = function(el) { Chris@0: if (typeof el.year != "undefined") { Chris@0: return el; Chris@0: } else if (typeof el.parentNode.year != "undefined") { Chris@0: return el.parentNode; Chris@0: } Chris@0: return null; Chris@0: }; Chris@0: Chris@0: Calendar.showMonthsCombo = function () { Chris@0: var cal = Calendar._C; Chris@0: if (!cal) { Chris@0: return false; Chris@0: } Chris@0: var cal = cal; Chris@0: var cd = cal.activeDiv; Chris@0: var mc = cal.monthsCombo; Chris@0: if (cal.hilitedMonth) { Chris@0: Calendar.removeClass(cal.hilitedMonth, "hilite"); Chris@0: } Chris@0: if (cal.activeMonth) { Chris@0: Calendar.removeClass(cal.activeMonth, "active"); Chris@0: } Chris@0: var mon = cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()]; Chris@0: Calendar.addClass(mon, "active"); Chris@0: cal.activeMonth = mon; Chris@0: var s = mc.style; Chris@0: s.display = "block"; Chris@0: if (cd.navtype < 0) Chris@0: s.left = cd.offsetLeft + "px"; Chris@0: else { Chris@0: var mcw = mc.offsetWidth; Chris@0: if (typeof mcw == "undefined") Chris@0: // Konqueror brain-dead techniques Chris@0: mcw = 50; Chris@0: s.left = (cd.offsetLeft + cd.offsetWidth - mcw) + "px"; Chris@0: } Chris@0: s.top = (cd.offsetTop + cd.offsetHeight) + "px"; Chris@0: }; Chris@0: Chris@0: Calendar.showYearsCombo = function (fwd) { Chris@0: var cal = Calendar._C; Chris@0: if (!cal) { Chris@0: return false; Chris@0: } Chris@0: var cal = cal; Chris@0: var cd = cal.activeDiv; Chris@0: var yc = cal.yearsCombo; Chris@0: if (cal.hilitedYear) { Chris@0: Calendar.removeClass(cal.hilitedYear, "hilite"); Chris@0: } Chris@0: if (cal.activeYear) { Chris@0: Calendar.removeClass(cal.activeYear, "active"); Chris@0: } Chris@0: cal.activeYear = null; Chris@0: var Y = cal.date.getFullYear() + (fwd ? 1 : -1); Chris@0: var yr = yc.firstChild; Chris@0: var show = false; Chris@0: for (var i = 12; i > 0; --i) { Chris@0: if (Y >= cal.minYear && Y <= cal.maxYear) { Chris@0: yr.innerHTML = Y; Chris@0: yr.year = Y; Chris@0: yr.style.display = "block"; Chris@0: show = true; Chris@0: } else { Chris@0: yr.style.display = "none"; Chris@0: } Chris@0: yr = yr.nextSibling; Chris@0: Y += fwd ? cal.yearStep : -cal.yearStep; Chris@0: } Chris@0: if (show) { Chris@0: var s = yc.style; Chris@0: s.display = "block"; Chris@0: if (cd.navtype < 0) Chris@0: s.left = cd.offsetLeft + "px"; Chris@0: else { Chris@0: var ycw = yc.offsetWidth; Chris@0: if (typeof ycw == "undefined") Chris@0: // Konqueror brain-dead techniques Chris@0: ycw = 50; Chris@0: s.left = (cd.offsetLeft + cd.offsetWidth - ycw) + "px"; Chris@0: } Chris@0: s.top = (cd.offsetTop + cd.offsetHeight) + "px"; Chris@0: } Chris@0: }; Chris@0: Chris@0: // event handlers Chris@0: Chris@0: Calendar.tableMouseUp = function(ev) { Chris@0: var cal = Calendar._C; Chris@0: if (!cal) { Chris@0: return false; Chris@0: } Chris@0: if (cal.timeout) { Chris@0: clearTimeout(cal.timeout); Chris@0: } Chris@0: var el = cal.activeDiv; Chris@0: if (!el) { Chris@0: return false; Chris@0: } Chris@0: var target = Calendar.getTargetElement(ev); Chris@0: ev || (ev = window.event); Chris@0: Calendar.removeClass(el, "active"); Chris@0: if (target == el || target.parentNode == el) { Chris@0: Calendar.cellClick(el, ev); Chris@0: } Chris@0: var mon = Calendar.findMonth(target); Chris@0: var date = null; Chris@0: if (mon) { Chris@0: date = new Date(cal.date); Chris@0: if (mon.month != date.getMonth()) { Chris@0: date.setMonth(mon.month); Chris@0: cal.setDate(date); Chris@0: cal.dateClicked = false; Chris@0: cal.callHandler(); Chris@0: } Chris@0: } else { Chris@0: var year = Calendar.findYear(target); Chris@0: if (year) { Chris@0: date = new Date(cal.date); Chris@0: if (year.year != date.getFullYear()) { Chris@0: date.setFullYear(year.year); Chris@0: cal.setDate(date); Chris@0: cal.dateClicked = false; Chris@0: cal.callHandler(); Chris@0: } Chris@0: } Chris@0: } Chris@0: with (Calendar) { Chris@0: removeEvent(document, "mouseup", tableMouseUp); Chris@0: removeEvent(document, "mouseover", tableMouseOver); Chris@0: removeEvent(document, "mousemove", tableMouseOver); Chris@0: cal._hideCombos(); Chris@0: _C = null; Chris@0: return stopEvent(ev); Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.tableMouseOver = function (ev) { Chris@0: var cal = Calendar._C; Chris@0: if (!cal) { Chris@0: return; Chris@0: } Chris@0: var el = cal.activeDiv; Chris@0: var target = Calendar.getTargetElement(ev); Chris@0: if (target == el || target.parentNode == el) { Chris@0: Calendar.addClass(el, "hilite active"); Chris@0: Calendar.addClass(el.parentNode, "rowhilite"); Chris@0: } else { Chris@0: if (typeof el.navtype == "undefined" || (el.navtype != 50 && (el.navtype == 0 || Math.abs(el.navtype) > 2))) Chris@0: Calendar.removeClass(el, "active"); Chris@0: Calendar.removeClass(el, "hilite"); Chris@0: Calendar.removeClass(el.parentNode, "rowhilite"); Chris@0: } Chris@0: ev || (ev = window.event); Chris@0: if (el.navtype == 50 && target != el) { Chris@0: var pos = Calendar.getAbsolutePos(el); Chris@0: var w = el.offsetWidth; Chris@0: var x = ev.clientX; Chris@0: var dx; Chris@0: var decrease = true; Chris@0: if (x > pos.x + w) { Chris@0: dx = x - pos.x - w; Chris@0: decrease = false; Chris@0: } else Chris@0: dx = pos.x - x; Chris@0: Chris@0: if (dx < 0) dx = 0; Chris@0: var range = el._range; Chris@0: var current = el._current; Chris@0: var count = Math.floor(dx / 10) % range.length; Chris@0: for (var i = range.length; --i >= 0;) Chris@0: if (range[i] == current) Chris@0: break; Chris@0: while (count-- > 0) Chris@0: if (decrease) { Chris@0: if (--i < 0) Chris@0: i = range.length - 1; Chris@0: } else if ( ++i >= range.length ) Chris@0: i = 0; Chris@0: var newval = range[i]; Chris@0: el.innerHTML = newval; Chris@0: Chris@0: cal.onUpdateTime(); Chris@0: } Chris@0: var mon = Calendar.findMonth(target); Chris@0: if (mon) { Chris@0: if (mon.month != cal.date.getMonth()) { Chris@0: if (cal.hilitedMonth) { Chris@0: Calendar.removeClass(cal.hilitedMonth, "hilite"); Chris@0: } Chris@0: Calendar.addClass(mon, "hilite"); Chris@0: cal.hilitedMonth = mon; Chris@0: } else if (cal.hilitedMonth) { Chris@0: Calendar.removeClass(cal.hilitedMonth, "hilite"); Chris@0: } Chris@0: } else { Chris@0: if (cal.hilitedMonth) { Chris@0: Calendar.removeClass(cal.hilitedMonth, "hilite"); Chris@0: } Chris@0: var year = Calendar.findYear(target); Chris@0: if (year) { Chris@0: if (year.year != cal.date.getFullYear()) { Chris@0: if (cal.hilitedYear) { Chris@0: Calendar.removeClass(cal.hilitedYear, "hilite"); Chris@0: } Chris@0: Calendar.addClass(year, "hilite"); Chris@0: cal.hilitedYear = year; Chris@0: } else if (cal.hilitedYear) { Chris@0: Calendar.removeClass(cal.hilitedYear, "hilite"); Chris@0: } Chris@0: } else if (cal.hilitedYear) { Chris@0: Calendar.removeClass(cal.hilitedYear, "hilite"); Chris@0: } Chris@0: } Chris@0: return Calendar.stopEvent(ev); Chris@0: }; Chris@0: Chris@0: Calendar.tableMouseDown = function (ev) { Chris@0: if (Calendar.getTargetElement(ev) == Calendar.getElement(ev)) { Chris@0: return Calendar.stopEvent(ev); Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.calDragIt = function (ev) { Chris@0: var cal = Calendar._C; Chris@0: if (!(cal && cal.dragging)) { Chris@0: return false; Chris@0: } Chris@0: var posX; Chris@0: var posY; Chris@0: if (Calendar.is_ie) { Chris@0: posY = window.event.clientY + document.body.scrollTop; Chris@0: posX = window.event.clientX + document.body.scrollLeft; Chris@0: } else { Chris@0: posX = ev.pageX; Chris@0: posY = ev.pageY; Chris@0: } Chris@0: cal.hideShowCovered(); Chris@0: var st = cal.element.style; Chris@0: st.left = (posX - cal.xOffs) + "px"; Chris@0: st.top = (posY - cal.yOffs) + "px"; Chris@0: return Calendar.stopEvent(ev); Chris@0: }; Chris@0: Chris@0: Calendar.calDragEnd = function (ev) { Chris@0: var cal = Calendar._C; Chris@0: if (!cal) { Chris@0: return false; Chris@0: } Chris@0: cal.dragging = false; Chris@0: with (Calendar) { Chris@0: removeEvent(document, "mousemove", calDragIt); Chris@0: removeEvent(document, "mouseup", calDragEnd); Chris@0: tableMouseUp(ev); Chris@0: } Chris@0: cal.hideShowCovered(); Chris@0: }; Chris@0: Chris@0: Calendar.dayMouseDown = function(ev) { Chris@0: var el = Calendar.getElement(ev); Chris@0: if (el.disabled) { Chris@0: return false; Chris@0: } Chris@0: var cal = el.calendar; Chris@0: cal.activeDiv = el; Chris@0: Calendar._C = cal; Chris@0: if (el.navtype != 300) with (Calendar) { Chris@0: if (el.navtype == 50) { Chris@0: el._current = el.innerHTML; Chris@0: addEvent(document, "mousemove", tableMouseOver); Chris@0: } else Chris@0: addEvent(document, Calendar.is_ie5 ? "mousemove" : "mouseover", tableMouseOver); Chris@0: addClass(el, "hilite active"); Chris@0: addEvent(document, "mouseup", tableMouseUp); Chris@0: } else if (cal.isPopup) { Chris@0: cal._dragStart(ev); Chris@0: } Chris@0: if (el.navtype == -1 || el.navtype == 1) { Chris@0: if (cal.timeout) clearTimeout(cal.timeout); Chris@0: cal.timeout = setTimeout("Calendar.showMonthsCombo()", 250); Chris@0: } else if (el.navtype == -2 || el.navtype == 2) { Chris@0: if (cal.timeout) clearTimeout(cal.timeout); Chris@0: cal.timeout = setTimeout((el.navtype > 0) ? "Calendar.showYearsCombo(true)" : "Calendar.showYearsCombo(false)", 250); Chris@0: } else { Chris@0: cal.timeout = null; Chris@0: } Chris@0: return Calendar.stopEvent(ev); Chris@0: }; Chris@0: Chris@0: Calendar.dayMouseDblClick = function(ev) { Chris@0: Calendar.cellClick(Calendar.getElement(ev), ev || window.event); Chris@0: if (Calendar.is_ie) { Chris@0: document.selection.empty(); Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.dayMouseOver = function(ev) { Chris@0: var el = Calendar.getElement(ev); Chris@0: if (Calendar.isRelated(el, ev) || Calendar._C || el.disabled) { Chris@0: return false; Chris@0: } Chris@0: if (el.ttip) { Chris@0: if (el.ttip.substr(0, 1) == "_") { Chris@0: el.ttip = el.caldate.print(el.calendar.ttDateFormat) + el.ttip.substr(1); Chris@0: } Chris@0: el.calendar.tooltips.innerHTML = el.ttip; Chris@0: } Chris@0: if (el.navtype != 300) { Chris@0: Calendar.addClass(el, "hilite"); Chris@0: if (el.caldate) { Chris@0: Calendar.addClass(el.parentNode, "rowhilite"); Chris@0: } Chris@0: } Chris@0: return Calendar.stopEvent(ev); Chris@0: }; Chris@0: Chris@0: Calendar.dayMouseOut = function(ev) { Chris@0: with (Calendar) { Chris@0: var el = getElement(ev); Chris@0: if (isRelated(el, ev) || _C || el.disabled) Chris@0: return false; Chris@0: removeClass(el, "hilite"); Chris@0: if (el.caldate) Chris@0: removeClass(el.parentNode, "rowhilite"); Chris@0: if (el.calendar) Chris@0: el.calendar.tooltips.innerHTML = _TT["SEL_DATE"]; Chris@0: return stopEvent(ev); Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Chris@0: * A generic "click" handler :) handles all types of buttons defined in this Chris@0: * calendar. Chris@0: */ Chris@0: Calendar.cellClick = function(el, ev) { Chris@0: var cal = el.calendar; Chris@0: var closing = false; Chris@0: var newdate = false; Chris@0: var date = null; Chris@0: if (typeof el.navtype == "undefined") { Chris@0: if (cal.currentDateEl) { Chris@0: Calendar.removeClass(cal.currentDateEl, "selected"); Chris@0: Calendar.addClass(el, "selected"); Chris@0: closing = (cal.currentDateEl == el); Chris@0: if (!closing) { Chris@0: cal.currentDateEl = el; Chris@0: } Chris@0: } Chris@0: cal.date.setDateOnly(el.caldate); Chris@0: date = cal.date; Chris@0: var other_month = !(cal.dateClicked = !el.otherMonth); Chris@0: if (!other_month && !cal.currentDateEl) Chris@0: cal._toggleMultipleDate(new Date(date)); Chris@0: else Chris@0: newdate = !el.disabled; Chris@0: // a date was clicked Chris@0: if (other_month) Chris@0: cal._init(cal.firstDayOfWeek, date); Chris@0: } else { Chris@0: if (el.navtype == 200) { Chris@0: Calendar.removeClass(el, "hilite"); Chris@0: cal.callCloseHandler(); Chris@0: return; Chris@0: } Chris@0: date = new Date(cal.date); Chris@0: if (el.navtype == 0) Chris@0: date.setDateOnly(new Date()); // TODAY Chris@0: // unless "today" was clicked, we assume no date was clicked so Chris@0: // the selected handler will know not to close the calenar when Chris@0: // in single-click mode. Chris@0: // cal.dateClicked = (el.navtype == 0); Chris@0: cal.dateClicked = false; Chris@0: var year = date.getFullYear(); Chris@0: var mon = date.getMonth(); Chris@0: function setMonth(m) { Chris@0: var day = date.getDate(); Chris@0: var max = date.getMonthDays(m); Chris@0: if (day > max) { Chris@0: date.setDate(max); Chris@0: } Chris@0: date.setMonth(m); Chris@0: }; Chris@0: switch (el.navtype) { Chris@0: case 400: Chris@0: Calendar.removeClass(el, "hilite"); Chris@0: var text = Calendar._TT["ABOUT"]; Chris@0: if (typeof text != "undefined") { Chris@0: text += cal.showsTime ? Calendar._TT["ABOUT_TIME"] : ""; Chris@0: } else { Chris@0: // FIXME: this should be removed as soon as lang files get updated! Chris@0: text = "Help and about box text is not translated into this language.\n" + Chris@0: "If you know this language and you feel generous please update\n" + Chris@0: "the corresponding file in \"lang\" subdir to match calendar-en.js\n" + Chris@0: "and send it back to to get it into the distribution ;-)\n\n" + Chris@0: "Thank you!\n" + Chris@0: "http://dynarch.com/mishoo/calendar.epl\n"; Chris@0: } Chris@0: alert(text); Chris@0: return; Chris@0: case -2: Chris@0: if (year > cal.minYear) { Chris@0: date.setFullYear(year - 1); Chris@0: } Chris@0: break; Chris@0: case -1: Chris@0: if (mon > 0) { Chris@0: setMonth(mon - 1); Chris@0: } else if (year-- > cal.minYear) { Chris@0: date.setFullYear(year); Chris@0: setMonth(11); Chris@0: } Chris@0: break; Chris@0: case 1: Chris@0: if (mon < 11) { Chris@0: setMonth(mon + 1); Chris@0: } else if (year < cal.maxYear) { Chris@0: date.setFullYear(year + 1); Chris@0: setMonth(0); Chris@0: } Chris@0: break; Chris@0: case 2: Chris@0: if (year < cal.maxYear) { Chris@0: date.setFullYear(year + 1); Chris@0: } Chris@0: break; Chris@0: case 100: Chris@0: cal.setFirstDayOfWeek(el.fdow); Chris@0: return; Chris@0: case 50: Chris@0: var range = el._range; Chris@0: var current = el.innerHTML; Chris@0: for (var i = range.length; --i >= 0;) Chris@0: if (range[i] == current) Chris@0: break; Chris@0: if (ev && ev.shiftKey) { Chris@0: if (--i < 0) Chris@0: i = range.length - 1; Chris@0: } else if ( ++i >= range.length ) Chris@0: i = 0; Chris@0: var newval = range[i]; Chris@0: el.innerHTML = newval; Chris@0: cal.onUpdateTime(); Chris@0: return; Chris@0: case 0: Chris@0: // TODAY will bring us here Chris@0: if ((typeof cal.getDateStatus == "function") && Chris@0: cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) { Chris@0: return false; Chris@0: } Chris@0: break; Chris@0: } Chris@0: if (!date.equalsTo(cal.date)) { Chris@0: cal.setDate(date); Chris@0: newdate = true; Chris@0: } else if (el.navtype == 0) Chris@0: newdate = closing = true; Chris@0: } Chris@0: if (newdate) { Chris@0: ev && cal.callHandler(); Chris@0: } Chris@0: if (closing) { Chris@0: Calendar.removeClass(el, "hilite"); Chris@0: ev && cal.callCloseHandler(); Chris@0: } Chris@0: }; Chris@0: Chris@0: // END: CALENDAR STATIC FUNCTIONS Chris@0: Chris@0: // BEGIN: CALENDAR OBJECT FUNCTIONS Chris@0: Chris@0: /** Chris@0: * This function creates the calendar inside the given parent. If _par is Chris@0: * null than it creates a popup calendar inside the BODY element. If _par is Chris@0: * an element, be it BODY, then it creates a non-popup calendar (still Chris@0: * hidden). Some properties need to be set before calling this function. Chris@0: */ Chris@0: Calendar.prototype.create = function (_par) { Chris@0: var parent = null; Chris@0: if (! _par) { Chris@0: // default parent is the document body, in which case we create Chris@0: // a popup calendar. Chris@0: parent = document.getElementsByTagName("body")[0]; Chris@0: this.isPopup = true; Chris@0: } else { Chris@0: parent = _par; Chris@0: this.isPopup = false; Chris@0: } Chris@0: this.date = this.dateStr ? new Date(this.dateStr) : new Date(); Chris@0: Chris@0: var table = Calendar.createElement("table"); Chris@0: this.table = table; Chris@0: table.cellSpacing = 0; Chris@0: table.cellPadding = 0; Chris@0: table.calendar = this; Chris@0: Calendar.addEvent(table, "mousedown", Calendar.tableMouseDown); Chris@0: Chris@0: var div = Calendar.createElement("div"); Chris@0: this.element = div; Chris@0: div.className = "calendar"; Chris@0: if (this.isPopup) { Chris@0: div.style.position = "absolute"; Chris@0: div.style.display = "none"; Chris@0: } Chris@0: div.appendChild(table); Chris@0: Chris@0: var thead = Calendar.createElement("thead", table); Chris@0: var cell = null; Chris@0: var row = null; Chris@0: Chris@0: var cal = this; Chris@0: var hh = function (text, cs, navtype) { Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.colSpan = cs; Chris@0: cell.className = "button"; Chris@0: if (navtype != 0 && Math.abs(navtype) <= 2) Chris@0: cell.className += " nav"; Chris@0: Calendar._add_evs(cell); Chris@0: cell.calendar = cal; Chris@0: cell.navtype = navtype; Chris@0: cell.innerHTML = "
" + text + "
"; Chris@0: return cell; Chris@0: }; Chris@0: Chris@0: row = Calendar.createElement("tr", thead); Chris@0: var title_length = 6; Chris@0: (this.isPopup) && --title_length; Chris@0: (this.weekNumbers) && ++title_length; Chris@0: Chris@0: hh("?", 1, 400).ttip = Calendar._TT["INFO"]; Chris@0: this.title = hh("", title_length, 300); Chris@0: this.title.className = "title"; Chris@0: if (this.isPopup) { Chris@0: this.title.ttip = Calendar._TT["DRAG_TO_MOVE"]; Chris@0: this.title.style.cursor = "move"; Chris@0: hh("×", 1, 200).ttip = Calendar._TT["CLOSE"]; Chris@0: } Chris@0: Chris@0: row = Calendar.createElement("tr", thead); Chris@0: row.className = "headrow"; Chris@0: Chris@0: this._nav_py = hh("«", 1, -2); Chris@0: this._nav_py.ttip = Calendar._TT["PREV_YEAR"]; Chris@0: Chris@0: this._nav_pm = hh("‹", 1, -1); Chris@0: this._nav_pm.ttip = Calendar._TT["PREV_MONTH"]; Chris@0: Chris@0: this._nav_now = hh(Calendar._TT["TODAY"], this.weekNumbers ? 4 : 3, 0); Chris@0: this._nav_now.ttip = Calendar._TT["GO_TODAY"]; Chris@0: Chris@0: this._nav_nm = hh("›", 1, 1); Chris@0: this._nav_nm.ttip = Calendar._TT["NEXT_MONTH"]; Chris@0: Chris@0: this._nav_ny = hh("»", 1, 2); Chris@0: this._nav_ny.ttip = Calendar._TT["NEXT_YEAR"]; Chris@0: Chris@0: // day names Chris@0: row = Calendar.createElement("tr", thead); Chris@0: row.className = "daynames"; Chris@0: if (this.weekNumbers) { Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.className = "name wn"; Chris@0: cell.innerHTML = Calendar._TT["WK"]; Chris@0: } Chris@0: for (var i = 7; i > 0; --i) { Chris@0: cell = Calendar.createElement("td", row); Chris@0: if (!i) { Chris@0: cell.navtype = 100; Chris@0: cell.calendar = this; Chris@0: Calendar._add_evs(cell); Chris@0: } Chris@0: } Chris@0: this.firstdayname = (this.weekNumbers) ? row.firstChild.nextSibling : row.firstChild; Chris@0: this._displayWeekdays(); Chris@0: Chris@0: var tbody = Calendar.createElement("tbody", table); Chris@0: this.tbody = tbody; Chris@0: Chris@0: for (i = 6; i > 0; --i) { Chris@0: row = Calendar.createElement("tr", tbody); Chris@0: if (this.weekNumbers) { Chris@0: cell = Calendar.createElement("td", row); Chris@0: } Chris@0: for (var j = 7; j > 0; --j) { Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.calendar = this; Chris@0: Calendar._add_evs(cell); Chris@0: } Chris@0: } Chris@0: Chris@0: if (this.showsTime) { Chris@0: row = Calendar.createElement("tr", tbody); Chris@0: row.className = "time"; Chris@0: Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.className = "time"; Chris@0: cell.colSpan = 2; Chris@0: cell.innerHTML = Calendar._TT["TIME"] || " "; Chris@0: Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.className = "time"; Chris@0: cell.colSpan = this.weekNumbers ? 4 : 3; Chris@0: Chris@0: (function(){ Chris@0: function makeTimePart(className, init, range_start, range_end) { Chris@0: var part = Calendar.createElement("span", cell); Chris@0: part.className = className; Chris@0: part.innerHTML = init; Chris@0: part.calendar = cal; Chris@0: part.ttip = Calendar._TT["TIME_PART"]; Chris@0: part.navtype = 50; Chris@0: part._range = []; Chris@0: if (typeof range_start != "number") Chris@0: part._range = range_start; Chris@0: else { Chris@0: for (var i = range_start; i <= range_end; ++i) { Chris@0: var txt; Chris@0: if (i < 10 && range_end >= 10) txt = '0' + i; Chris@0: else txt = '' + i; Chris@0: part._range[part._range.length] = txt; Chris@0: } Chris@0: } Chris@0: Calendar._add_evs(part); Chris@0: return part; Chris@0: }; Chris@0: var hrs = cal.date.getHours(); Chris@0: var mins = cal.date.getMinutes(); Chris@0: var t12 = !cal.time24; Chris@0: var pm = (hrs > 12); Chris@0: if (t12 && pm) hrs -= 12; Chris@0: var H = makeTimePart("hour", hrs, t12 ? 1 : 0, t12 ? 12 : 23); Chris@0: var span = Calendar.createElement("span", cell); Chris@0: span.innerHTML = ":"; Chris@0: span.className = "colon"; Chris@0: var M = makeTimePart("minute", mins, 0, 59); Chris@0: var AP = null; Chris@0: cell = Calendar.createElement("td", row); Chris@0: cell.className = "time"; Chris@0: cell.colSpan = 2; Chris@0: if (t12) Chris@0: AP = makeTimePart("ampm", pm ? "pm" : "am", ["am", "pm"]); Chris@0: else Chris@0: cell.innerHTML = " "; Chris@0: Chris@0: cal.onSetTime = function() { Chris@0: var pm, hrs = this.date.getHours(), Chris@0: mins = this.date.getMinutes(); Chris@0: if (t12) { Chris@0: pm = (hrs >= 12); Chris@0: if (pm) hrs -= 12; Chris@0: if (hrs == 0) hrs = 12; Chris@0: AP.innerHTML = pm ? "pm" : "am"; Chris@0: } Chris@0: H.innerHTML = (hrs < 10) ? ("0" + hrs) : hrs; Chris@0: M.innerHTML = (mins < 10) ? ("0" + mins) : mins; Chris@0: }; Chris@0: Chris@0: cal.onUpdateTime = function() { Chris@0: var date = this.date; Chris@0: var h = parseInt(H.innerHTML, 10); Chris@0: if (t12) { Chris@0: if (/pm/i.test(AP.innerHTML) && h < 12) Chris@0: h += 12; Chris@0: else if (/am/i.test(AP.innerHTML) && h == 12) Chris@0: h = 0; Chris@0: } Chris@0: var d = date.getDate(); Chris@0: var m = date.getMonth(); Chris@0: var y = date.getFullYear(); Chris@0: date.setHours(h); Chris@0: date.setMinutes(parseInt(M.innerHTML, 10)); Chris@0: date.setFullYear(y); Chris@0: date.setMonth(m); Chris@0: date.setDate(d); Chris@0: this.dateClicked = false; Chris@0: this.callHandler(); Chris@0: }; Chris@0: })(); Chris@0: } else { Chris@0: this.onSetTime = this.onUpdateTime = function() {}; Chris@0: } Chris@0: Chris@0: var tfoot = Calendar.createElement("tfoot", table); Chris@0: Chris@0: row = Calendar.createElement("tr", tfoot); Chris@0: row.className = "footrow"; Chris@0: Chris@0: cell = hh(Calendar._TT["SEL_DATE"], this.weekNumbers ? 8 : 7, 300); Chris@0: cell.className = "ttip"; Chris@0: if (this.isPopup) { Chris@0: cell.ttip = Calendar._TT["DRAG_TO_MOVE"]; Chris@0: cell.style.cursor = "move"; Chris@0: } Chris@0: this.tooltips = cell; Chris@0: Chris@0: div = Calendar.createElement("div", this.element); Chris@0: this.monthsCombo = div; Chris@0: div.className = "combo"; Chris@0: for (i = 0; i < Calendar._MN.length; ++i) { Chris@0: var mn = Calendar.createElement("div"); Chris@0: mn.className = Calendar.is_ie ? "label-IEfix" : "label"; Chris@0: mn.month = i; Chris@0: mn.innerHTML = Calendar._SMN[i]; Chris@0: div.appendChild(mn); Chris@0: } Chris@0: Chris@0: div = Calendar.createElement("div", this.element); Chris@0: this.yearsCombo = div; Chris@0: div.className = "combo"; Chris@0: for (i = 12; i > 0; --i) { Chris@0: var yr = Calendar.createElement("div"); Chris@0: yr.className = Calendar.is_ie ? "label-IEfix" : "label"; Chris@0: div.appendChild(yr); Chris@0: } Chris@0: Chris@0: this._init(this.firstDayOfWeek, this.date); Chris@0: parent.appendChild(this.element); Chris@0: }; Chris@0: Chris@0: /** keyboard navigation, only for popup calendars */ Chris@0: Calendar._keyEvent = function(ev) { Chris@0: var cal = window._dynarch_popupCalendar; Chris@0: if (!cal || cal.multiple) Chris@0: return false; Chris@0: (Calendar.is_ie) && (ev = window.event); Chris@0: var act = (Calendar.is_ie || ev.type == "keypress"), Chris@0: K = ev.keyCode; Chris@0: if (ev.ctrlKey) { Chris@0: switch (K) { Chris@0: case 37: // KEY left Chris@0: act && Calendar.cellClick(cal._nav_pm); Chris@0: break; Chris@0: case 38: // KEY up Chris@0: act && Calendar.cellClick(cal._nav_py); Chris@0: break; Chris@0: case 39: // KEY right Chris@0: act && Calendar.cellClick(cal._nav_nm); Chris@0: break; Chris@0: case 40: // KEY down Chris@0: act && Calendar.cellClick(cal._nav_ny); Chris@0: break; Chris@0: default: Chris@0: return false; Chris@0: } Chris@0: } else switch (K) { Chris@0: case 32: // KEY space (now) Chris@0: Calendar.cellClick(cal._nav_now); Chris@0: break; Chris@0: case 27: // KEY esc Chris@0: act && cal.callCloseHandler(); Chris@0: break; Chris@0: case 37: // KEY left Chris@0: case 38: // KEY up Chris@0: case 39: // KEY right Chris@0: case 40: // KEY down Chris@0: if (act) { Chris@0: var prev, x, y, ne, el, step; Chris@0: prev = K == 37 || K == 38; Chris@0: step = (K == 37 || K == 39) ? 1 : 7; Chris@0: function setVars() { Chris@0: el = cal.currentDateEl; Chris@0: var p = el.pos; Chris@0: x = p & 15; Chris@0: y = p >> 4; Chris@0: ne = cal.ar_days[y][x]; Chris@0: };setVars(); Chris@0: function prevMonth() { Chris@0: var date = new Date(cal.date); Chris@0: date.setDate(date.getDate() - step); Chris@0: cal.setDate(date); Chris@0: }; Chris@0: function nextMonth() { Chris@0: var date = new Date(cal.date); Chris@0: date.setDate(date.getDate() + step); Chris@0: cal.setDate(date); Chris@0: }; Chris@0: while (1) { Chris@0: switch (K) { Chris@0: case 37: // KEY left Chris@0: if (--x >= 0) Chris@0: ne = cal.ar_days[y][x]; Chris@0: else { Chris@0: x = 6; Chris@0: K = 38; Chris@0: continue; Chris@0: } Chris@0: break; Chris@0: case 38: // KEY up Chris@0: if (--y >= 0) Chris@0: ne = cal.ar_days[y][x]; Chris@0: else { Chris@0: prevMonth(); Chris@0: setVars(); Chris@0: } Chris@0: break; Chris@0: case 39: // KEY right Chris@0: if (++x < 7) Chris@0: ne = cal.ar_days[y][x]; Chris@0: else { Chris@0: x = 0; Chris@0: K = 40; Chris@0: continue; Chris@0: } Chris@0: break; Chris@0: case 40: // KEY down Chris@0: if (++y < cal.ar_days.length) Chris@0: ne = cal.ar_days[y][x]; Chris@0: else { Chris@0: nextMonth(); Chris@0: setVars(); Chris@0: } Chris@0: break; Chris@0: } Chris@0: break; Chris@0: } Chris@0: if (ne) { Chris@0: if (!ne.disabled) Chris@0: Calendar.cellClick(ne); Chris@0: else if (prev) Chris@0: prevMonth(); Chris@0: else Chris@0: nextMonth(); Chris@0: } Chris@0: } Chris@0: break; Chris@0: case 13: // KEY enter Chris@0: if (act) Chris@0: Calendar.cellClick(cal.currentDateEl, ev); Chris@0: break; Chris@0: default: Chris@0: return false; Chris@0: } Chris@0: return Calendar.stopEvent(ev); Chris@0: }; Chris@0: Chris@0: /** Chris@0: * (RE)Initializes the calendar to the given date and firstDayOfWeek Chris@0: */ Chris@0: Calendar.prototype._init = function (firstDayOfWeek, date) { Chris@0: var today = new Date(), Chris@0: TY = today.getFullYear(), Chris@0: TM = today.getMonth(), Chris@0: TD = today.getDate(); Chris@0: this.table.style.visibility = "hidden"; Chris@0: var year = date.getFullYear(); Chris@0: if (year < this.minYear) { Chris@0: year = this.minYear; Chris@0: date.setFullYear(year); Chris@0: } else if (year > this.maxYear) { Chris@0: year = this.maxYear; Chris@0: date.setFullYear(year); Chris@0: } Chris@0: this.firstDayOfWeek = firstDayOfWeek; Chris@0: this.date = new Date(date); Chris@0: var month = date.getMonth(); Chris@0: var mday = date.getDate(); Chris@0: var no_days = date.getMonthDays(); Chris@0: Chris@0: // calendar voodoo for computing the first day that would actually be Chris@0: // displayed in the calendar, even if it's from the previous month. Chris@0: // WARNING: this is magic. ;-) Chris@0: date.setDate(1); Chris@0: var day1 = (date.getDay() - this.firstDayOfWeek) % 7; Chris@0: if (day1 < 0) Chris@0: day1 += 7; Chris@0: date.setDate(0-day1); Chris@0: date.setDate(date.getDate() + 1); Chris@0: Chris@0: var row = this.tbody.firstChild; Chris@0: var MN = Calendar._SMN[month]; Chris@0: var ar_days = this.ar_days = new Array(); Chris@0: var weekend = Calendar._TT["WEEKEND"]; Chris@0: var dates = this.multiple ? (this.datesCells = {}) : null; Chris@0: for (var i = 0; i < 6; ++i, row = row.nextSibling) { Chris@0: var cell = row.firstChild; Chris@0: if (this.weekNumbers) { Chris@0: cell.className = "day wn"; Chris@0: cell.innerHTML = date.getWeekNumber(); Chris@0: cell = cell.nextSibling; Chris@0: } Chris@0: row.className = "daysrow"; Chris@0: var hasdays = false, iday, dpos = ar_days[i] = []; Chris@0: for (var j = 0; j < 7; ++j, cell = cell.nextSibling, date.setDate(iday + 1)) { Chris@0: iday = date.getDate(); Chris@0: var wday = date.getDay(); Chris@0: cell.className = "day"; Chris@0: cell.pos = i << 4 | j; Chris@0: dpos[j] = cell; Chris@0: var current_month = (date.getMonth() == month); Chris@0: if (!current_month) { Chris@0: if (this.showsOtherMonths) { Chris@0: cell.className += " othermonth"; Chris@0: cell.otherMonth = true; Chris@0: } else { Chris@0: cell.className = "emptycell"; Chris@0: cell.innerHTML = " "; Chris@0: cell.disabled = true; Chris@0: continue; Chris@0: } Chris@0: } else { Chris@0: cell.otherMonth = false; Chris@0: hasdays = true; Chris@0: } Chris@0: cell.disabled = false; Chris@0: cell.innerHTML = this.getDateText ? this.getDateText(date, iday) : iday; Chris@0: if (dates) Chris@0: dates[date.print("%Y%m%d")] = cell; Chris@0: if (this.getDateStatus) { Chris@0: var status = this.getDateStatus(date, year, month, iday); Chris@0: if (this.getDateToolTip) { Chris@0: var toolTip = this.getDateToolTip(date, year, month, iday); Chris@0: if (toolTip) Chris@0: cell.title = toolTip; Chris@0: } Chris@0: if (status === true) { Chris@0: cell.className += " disabled"; Chris@0: cell.disabled = true; Chris@0: } else { Chris@0: if (/disabled/i.test(status)) Chris@0: cell.disabled = true; Chris@0: cell.className += " " + status; Chris@0: } Chris@0: } Chris@0: if (!cell.disabled) { Chris@0: cell.caldate = new Date(date); Chris@0: cell.ttip = "_"; Chris@0: if (!this.multiple && current_month Chris@0: && iday == mday && this.hiliteToday) { Chris@0: cell.className += " selected"; Chris@0: this.currentDateEl = cell; Chris@0: } Chris@0: if (date.getFullYear() == TY && Chris@0: date.getMonth() == TM && Chris@0: iday == TD) { Chris@0: cell.className += " today"; Chris@0: cell.ttip += Calendar._TT["PART_TODAY"]; Chris@0: } Chris@0: if (weekend.indexOf(wday.toString()) != -1) Chris@0: cell.className += cell.otherMonth ? " oweekend" : " weekend"; Chris@0: } Chris@0: } Chris@0: if (!(hasdays || this.showsOtherMonths)) Chris@0: row.className = "emptyrow"; Chris@0: } Chris@0: this.title.innerHTML = Calendar._MN[month] + ", " + year; Chris@0: this.onSetTime(); Chris@0: this.table.style.visibility = "visible"; Chris@0: this._initMultipleDates(); Chris@0: // PROFILE Chris@0: // this.tooltips.innerHTML = "Generated in " + ((new Date()) - today) + " ms"; Chris@0: }; Chris@0: Chris@0: Calendar.prototype._initMultipleDates = function() { Chris@0: if (this.multiple) { Chris@0: for (var i in this.multiple) { Chris@0: var cell = this.datesCells[i]; Chris@0: var d = this.multiple[i]; Chris@0: if (!d) Chris@0: continue; Chris@0: if (cell) Chris@0: cell.className += " selected"; Chris@0: } Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.prototype._toggleMultipleDate = function(date) { Chris@0: if (this.multiple) { Chris@0: var ds = date.print("%Y%m%d"); Chris@0: var cell = this.datesCells[ds]; Chris@0: if (cell) { Chris@0: var d = this.multiple[ds]; Chris@0: if (!d) { Chris@0: Calendar.addClass(cell, "selected"); Chris@0: this.multiple[ds] = date; Chris@0: } else { Chris@0: Calendar.removeClass(cell, "selected"); Chris@0: delete this.multiple[ds]; Chris@0: } Chris@0: } Chris@0: } Chris@0: }; Chris@0: Chris@0: Calendar.prototype.setDateToolTipHandler = function (unaryFunction) { Chris@0: this.getDateToolTip = unaryFunction; Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Calls _init function above for going to a certain date (but only if the Chris@0: * date is different than the currently selected one). Chris@0: */ Chris@0: Calendar.prototype.setDate = function (date) { Chris@0: if (!date.equalsTo(this.date)) { Chris@0: this._init(this.firstDayOfWeek, date); Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Refreshes the calendar. Useful if the "disabledHandler" function is Chris@0: * dynamic, meaning that the list of disabled date can change at runtime. Chris@0: * Just * call this function if you think that the list of disabled dates Chris@0: * should * change. Chris@0: */ Chris@0: Calendar.prototype.refresh = function () { Chris@0: this._init(this.firstDayOfWeek, this.date); Chris@0: }; Chris@0: Chris@0: /** Modifies the "firstDayOfWeek" parameter (pass 0 for Synday, 1 for Monday, etc.). */ Chris@0: Calendar.prototype.setFirstDayOfWeek = function (firstDayOfWeek) { Chris@0: this._init(firstDayOfWeek, this.date); Chris@0: this._displayWeekdays(); Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Allows customization of what dates are enabled. The "unaryFunction" Chris@0: * parameter must be a function object that receives the date (as a JS Date Chris@0: * object) and returns a boolean value. If the returned value is true then Chris@0: * the passed date will be marked as disabled. Chris@0: */ Chris@0: Calendar.prototype.setDateStatusHandler = Calendar.prototype.setDisabledHandler = function (unaryFunction) { Chris@0: this.getDateStatus = unaryFunction; Chris@0: }; Chris@0: Chris@0: /** Customization of allowed year range for the calendar. */ Chris@0: Calendar.prototype.setRange = function (a, z) { Chris@0: this.minYear = a; Chris@0: this.maxYear = z; Chris@0: }; Chris@0: Chris@0: /** Calls the first user handler (selectedHandler). */ Chris@0: Calendar.prototype.callHandler = function () { Chris@0: if (this.onSelected) { Chris@0: this.onSelected(this, this.date.print(this.dateFormat)); Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Calls the second user handler (closeHandler). */ Chris@0: Calendar.prototype.callCloseHandler = function () { Chris@0: if (this.onClose) { Chris@0: this.onClose(this); Chris@0: } Chris@0: this.hideShowCovered(); Chris@0: }; Chris@0: Chris@0: /** Removes the calendar object from the DOM tree and destroys it. */ Chris@0: Calendar.prototype.destroy = function () { Chris@0: var el = this.element.parentNode; Chris@0: el.removeChild(this.element); Chris@0: Calendar._C = null; Chris@0: window._dynarch_popupCalendar = null; Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Moves the calendar element to a different section in the DOM tree (changes Chris@0: * its parent). Chris@0: */ Chris@0: Calendar.prototype.reparent = function (new_parent) { Chris@0: var el = this.element; Chris@0: el.parentNode.removeChild(el); Chris@0: new_parent.appendChild(el); Chris@0: }; Chris@0: Chris@0: // This gets called when the user presses a mouse button anywhere in the Chris@0: // document, if the calendar is shown. If the click was outside the open Chris@0: // calendar this function closes it. Chris@0: Calendar._checkCalendar = function(ev) { Chris@0: var calendar = window._dynarch_popupCalendar; Chris@0: if (!calendar) { Chris@0: return false; Chris@0: } Chris@0: var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev); Chris@0: for (; el != null && el != calendar.element; el = el.parentNode); Chris@0: if (el == null) { Chris@0: // calls closeHandler which should hide the calendar. Chris@0: window._dynarch_popupCalendar.callCloseHandler(); Chris@0: return Calendar.stopEvent(ev); Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Shows the calendar. */ Chris@0: Calendar.prototype.show = function () { Chris@0: var rows = this.table.getElementsByTagName("tr"); Chris@0: for (var i = rows.length; i > 0;) { Chris@0: var row = rows[--i]; Chris@0: Calendar.removeClass(row, "rowhilite"); Chris@0: var cells = row.getElementsByTagName("td"); Chris@0: for (var j = cells.length; j > 0;) { Chris@0: var cell = cells[--j]; Chris@0: Calendar.removeClass(cell, "hilite"); Chris@0: Calendar.removeClass(cell, "active"); Chris@0: } Chris@0: } Chris@0: this.element.style.display = "block"; Chris@0: this.hidden = false; Chris@0: if (this.isPopup) { Chris@0: window._dynarch_popupCalendar = this; Chris@0: Calendar.addEvent(document, "keydown", Calendar._keyEvent); Chris@0: Calendar.addEvent(document, "keypress", Calendar._keyEvent); Chris@0: Calendar.addEvent(document, "mousedown", Calendar._checkCalendar); Chris@0: } Chris@0: this.hideShowCovered(); Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Hides the calendar. Also removes any "hilite" from the class of any TD Chris@0: * element. Chris@0: */ Chris@0: Calendar.prototype.hide = function () { Chris@0: if (this.isPopup) { Chris@0: Calendar.removeEvent(document, "keydown", Calendar._keyEvent); Chris@0: Calendar.removeEvent(document, "keypress", Calendar._keyEvent); Chris@0: Calendar.removeEvent(document, "mousedown", Calendar._checkCalendar); Chris@0: } Chris@0: this.element.style.display = "none"; Chris@0: this.hidden = true; Chris@0: this.hideShowCovered(); Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Shows the calendar at a given absolute position (beware that, depending on Chris@0: * the calendar element style -- position property -- this might be relative Chris@0: * to the parent's containing rectangle). Chris@0: */ Chris@0: Calendar.prototype.showAt = function (x, y) { Chris@0: var s = this.element.style; Chris@0: s.left = x + "px"; Chris@0: s.top = y + "px"; Chris@0: this.show(); Chris@0: }; Chris@0: Chris@0: /** Shows the calendar near a given element. */ Chris@0: Calendar.prototype.showAtElement = function (el, opts) { Chris@0: var self = this; Chris@0: var p = Calendar.getAbsolutePos(el); Chris@0: if (!opts || typeof opts != "string") { Chris@0: this.showAt(p.x, p.y + el.offsetHeight); Chris@0: return true; Chris@0: } Chris@0: function fixPosition(box) { Chris@0: if (box.x < 0) Chris@0: box.x = 0; Chris@0: if (box.y < 0) Chris@0: box.y = 0; Chris@0: var cp = document.createElement("div"); Chris@0: var s = cp.style; Chris@0: s.position = "absolute"; Chris@0: s.right = s.bottom = s.width = s.height = "0px"; Chris@0: document.body.appendChild(cp); Chris@0: var br = Calendar.getAbsolutePos(cp); Chris@0: document.body.removeChild(cp); Chris@0: if (Calendar.is_ie) { Chris@0: br.y += document.body.scrollTop; Chris@0: br.x += document.body.scrollLeft; Chris@0: } else { Chris@0: br.y += window.scrollY; Chris@0: br.x += window.scrollX; Chris@0: } Chris@0: var tmp = box.x + box.width - br.x; Chris@0: if (tmp > 0) box.x -= tmp; Chris@0: tmp = box.y + box.height - br.y; Chris@0: if (tmp > 0) box.y -= tmp; Chris@0: }; Chris@0: this.element.style.display = "block"; Chris@0: Calendar.continuation_for_the_fucking_khtml_browser = function() { Chris@0: var w = self.element.offsetWidth; Chris@0: var h = self.element.offsetHeight; Chris@0: self.element.style.display = "none"; Chris@0: var valign = opts.substr(0, 1); Chris@0: var halign = "l"; Chris@0: if (opts.length > 1) { Chris@0: halign = opts.substr(1, 1); Chris@0: } Chris@0: // vertical alignment Chris@0: switch (valign) { Chris@0: case "T": p.y -= h; break; Chris@0: case "B": p.y += el.offsetHeight; break; Chris@0: case "C": p.y += (el.offsetHeight - h) / 2; break; Chris@0: case "t": p.y += el.offsetHeight - h; break; Chris@0: case "b": break; // already there Chris@0: } Chris@0: // horizontal alignment Chris@0: switch (halign) { Chris@0: case "L": p.x -= w; break; Chris@0: case "R": p.x += el.offsetWidth; break; Chris@0: case "C": p.x += (el.offsetWidth - w) / 2; break; Chris@0: case "l": p.x += el.offsetWidth - w; break; Chris@0: case "r": break; // already there Chris@0: } Chris@0: p.width = w; Chris@0: p.height = h + 40; Chris@0: self.monthsCombo.style.display = "none"; Chris@0: fixPosition(p); Chris@0: self.showAt(p.x, p.y); Chris@0: }; Chris@0: if (Calendar.is_khtml) Chris@0: setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10); Chris@0: else Chris@0: Calendar.continuation_for_the_fucking_khtml_browser(); Chris@0: }; Chris@0: Chris@0: /** Customizes the date format. */ Chris@0: Calendar.prototype.setDateFormat = function (str) { Chris@0: this.dateFormat = str; Chris@0: }; Chris@0: Chris@0: /** Customizes the tooltip date format. */ Chris@0: Calendar.prototype.setTtDateFormat = function (str) { Chris@0: this.ttDateFormat = str; Chris@0: }; Chris@0: Chris@0: /** Chris@0: * Tries to identify the date represented in a string. If successful it also Chris@0: * calls this.setDate which moves the calendar to the given date. Chris@0: */ Chris@0: Calendar.prototype.parseDate = function(str, fmt) { Chris@0: if (!fmt) Chris@0: fmt = this.dateFormat; Chris@0: this.setDate(Date.parseDate(str, fmt)); Chris@0: }; Chris@0: Chris@0: Calendar.prototype.hideShowCovered = function () { Chris@0: if (!Calendar.is_ie && !Calendar.is_opera) Chris@0: return; Chris@0: function getVisib(obj){ Chris@0: var value = obj.style.visibility; Chris@0: if (!value) { Chris@0: if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C Chris@0: if (!Calendar.is_khtml) Chris@0: value = document.defaultView. Chris@0: getComputedStyle(obj, "").getPropertyValue("visibility"); Chris@0: else Chris@0: value = ''; Chris@0: } else if (obj.currentStyle) { // IE Chris@0: value = obj.currentStyle.visibility; Chris@0: } else Chris@0: value = ''; Chris@0: } Chris@0: return value; Chris@0: }; Chris@0: Chris@0: var tags = new Array("applet", "iframe", "select"); Chris@0: var el = this.element; Chris@0: Chris@0: var p = Calendar.getAbsolutePos(el); Chris@0: var EX1 = p.x; Chris@0: var EX2 = el.offsetWidth + EX1; Chris@0: var EY1 = p.y; Chris@0: var EY2 = el.offsetHeight + EY1; Chris@0: Chris@0: for (var k = tags.length; k > 0; ) { Chris@0: var ar = document.getElementsByTagName(tags[--k]); Chris@0: var cc = null; Chris@0: Chris@0: for (var i = ar.length; i > 0;) { Chris@0: cc = ar[--i]; Chris@0: Chris@0: p = Calendar.getAbsolutePos(cc); Chris@0: var CX1 = p.x; Chris@0: var CX2 = cc.offsetWidth + CX1; Chris@0: var CY1 = p.y; Chris@0: var CY2 = cc.offsetHeight + CY1; Chris@0: Chris@0: if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) { Chris@0: if (!cc.__msh_save_visibility) { Chris@0: cc.__msh_save_visibility = getVisib(cc); Chris@0: } Chris@0: cc.style.visibility = cc.__msh_save_visibility; Chris@0: } else { Chris@0: if (!cc.__msh_save_visibility) { Chris@0: cc.__msh_save_visibility = getVisib(cc); Chris@0: } Chris@0: cc.style.visibility = "hidden"; Chris@0: } Chris@0: } Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Internal function; it displays the bar with the names of the weekday. */ Chris@0: Calendar.prototype._displayWeekdays = function () { Chris@0: var fdow = this.firstDayOfWeek; Chris@0: var cell = this.firstdayname; Chris@0: var weekend = Calendar._TT["WEEKEND"]; Chris@0: for (var i = 0; i < 7; ++i) { Chris@0: cell.className = "day name"; Chris@0: var realday = (i + fdow) % 7; Chris@0: if (i) { Chris@0: cell.ttip = Calendar._TT["DAY_FIRST"].replace("%s", Calendar._DN[realday]); Chris@0: cell.navtype = 100; Chris@0: cell.calendar = this; Chris@0: cell.fdow = realday; Chris@0: Calendar._add_evs(cell); Chris@0: } Chris@0: if (weekend.indexOf(realday.toString()) != -1) { Chris@0: Calendar.addClass(cell, "weekend"); Chris@0: } Chris@0: cell.innerHTML = Calendar._SDN[(i + fdow) % 7]; Chris@0: cell = cell.nextSibling; Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Internal function. Hides all combo boxes that might be displayed. */ Chris@0: Calendar.prototype._hideCombos = function () { Chris@0: this.monthsCombo.style.display = "none"; Chris@0: this.yearsCombo.style.display = "none"; Chris@0: }; Chris@0: Chris@0: /** Internal function. Starts dragging the element. */ Chris@0: Calendar.prototype._dragStart = function (ev) { Chris@0: if (this.dragging) { Chris@0: return; Chris@0: } Chris@0: this.dragging = true; Chris@0: var posX; Chris@0: var posY; Chris@0: if (Calendar.is_ie) { Chris@0: posY = window.event.clientY + document.body.scrollTop; Chris@0: posX = window.event.clientX + document.body.scrollLeft; Chris@0: } else { Chris@0: posY = ev.clientY + window.scrollY; Chris@0: posX = ev.clientX + window.scrollX; Chris@0: } Chris@0: var st = this.element.style; Chris@0: this.xOffs = posX - parseInt(st.left); Chris@0: this.yOffs = posY - parseInt(st.top); Chris@0: with (Calendar) { Chris@0: addEvent(document, "mousemove", calDragIt); Chris@0: addEvent(document, "mouseup", calDragEnd); Chris@0: } Chris@0: }; Chris@0: Chris@0: // BEGIN: DATE OBJECT PATCHES Chris@0: Chris@0: /** Adds the number of days array to the Date object. */ Chris@0: Date._MD = new Array(31,28,31,30,31,30,31,31,30,31,30,31); Chris@0: Chris@0: /** Constants used for time computations */ Chris@0: Date.SECOND = 1000 /* milliseconds */; Chris@0: Date.MINUTE = 60 * Date.SECOND; Chris@0: Date.HOUR = 60 * Date.MINUTE; Chris@0: Date.DAY = 24 * Date.HOUR; Chris@0: Date.WEEK = 7 * Date.DAY; Chris@0: Chris@0: Date.parseDate = function(str, fmt) { Chris@0: var today = new Date(); Chris@0: var y = 0; Chris@0: var m = -1; Chris@0: var d = 0; Chris@0: var a = str.split(/\W+/); Chris@0: var b = fmt.match(/%./g); Chris@0: var i = 0, j = 0; Chris@0: var hr = 0; Chris@0: var min = 0; Chris@0: for (i = 0; i < a.length; ++i) { Chris@0: if (!a[i]) Chris@0: continue; Chris@0: switch (b[i]) { Chris@0: case "%d": Chris@0: case "%e": Chris@0: d = parseInt(a[i], 10); Chris@0: break; Chris@0: Chris@0: case "%m": Chris@0: m = parseInt(a[i], 10) - 1; Chris@0: break; Chris@0: Chris@0: case "%Y": Chris@0: case "%y": Chris@0: y = parseInt(a[i], 10); Chris@0: (y < 100) && (y += (y > 29) ? 1900 : 2000); Chris@0: break; Chris@0: Chris@0: case "%b": Chris@0: case "%B": Chris@0: for (j = 0; j < 12; ++j) { Chris@0: if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; } Chris@0: } Chris@0: break; Chris@0: Chris@0: case "%H": Chris@0: case "%I": Chris@0: case "%k": Chris@0: case "%l": Chris@0: hr = parseInt(a[i], 10); Chris@0: break; Chris@0: Chris@0: case "%P": Chris@0: case "%p": Chris@0: if (/pm/i.test(a[i]) && hr < 12) Chris@0: hr += 12; Chris@0: else if (/am/i.test(a[i]) && hr >= 12) Chris@0: hr -= 12; Chris@0: break; Chris@0: Chris@0: case "%M": Chris@0: min = parseInt(a[i], 10); Chris@0: break; Chris@0: } Chris@0: } Chris@0: if (isNaN(y)) y = today.getFullYear(); Chris@0: if (isNaN(m)) m = today.getMonth(); Chris@0: if (isNaN(d)) d = today.getDate(); Chris@0: if (isNaN(hr)) hr = today.getHours(); Chris@0: if (isNaN(min)) min = today.getMinutes(); Chris@0: if (y != 0 && m != -1 && d != 0) Chris@0: return new Date(y, m, d, hr, min, 0); Chris@0: y = 0; m = -1; d = 0; Chris@0: for (i = 0; i < a.length; ++i) { Chris@0: if (a[i].search(/[a-zA-Z]+/) != -1) { Chris@0: var t = -1; Chris@0: for (j = 0; j < 12; ++j) { Chris@0: if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; } Chris@0: } Chris@0: if (t != -1) { Chris@0: if (m != -1) { Chris@0: d = m+1; Chris@0: } Chris@0: m = t; Chris@0: } Chris@0: } else if (parseInt(a[i], 10) <= 12 && m == -1) { Chris@0: m = a[i]-1; Chris@0: } else if (parseInt(a[i], 10) > 31 && y == 0) { Chris@0: y = parseInt(a[i], 10); Chris@0: (y < 100) && (y += (y > 29) ? 1900 : 2000); Chris@0: } else if (d == 0) { Chris@0: d = a[i]; Chris@0: } Chris@0: } Chris@0: if (y == 0) Chris@0: y = today.getFullYear(); Chris@0: if (m != -1 && d != 0) Chris@0: return new Date(y, m, d, hr, min, 0); Chris@0: return today; Chris@0: }; Chris@0: Chris@0: /** Returns the number of days in the current month */ Chris@0: Date.prototype.getMonthDays = function(month) { Chris@0: var year = this.getFullYear(); Chris@0: if (typeof month == "undefined") { Chris@0: month = this.getMonth(); Chris@0: } Chris@0: if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) { Chris@0: return 29; Chris@0: } else { Chris@0: return Date._MD[month]; Chris@0: } Chris@0: }; Chris@0: Chris@0: /** Returns the number of day in the year. */ Chris@0: Date.prototype.getDayOfYear = function() { Chris@0: var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0); Chris@0: var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0); Chris@0: var time = now - then; Chris@0: return Math.floor(time / Date.DAY); Chris@0: }; Chris@0: Chris@0: /** Returns the number of the week in year, as defined in ISO 8601. Chris@0: This function is only correct if `this` is the first day of the week. */ Chris@0: Date.prototype.getWeekNumber = function() { Chris@0: var d = new Date(this.getFullYear(), this.getMonth(), this.getDate()); Chris@0: var days = 1000*60*60*24; // one day in milliseconds Chris@0: Chris@0: // get the thursday of the current week Chris@0: var this_thursday = new Date( Chris@0: d.valueOf() // selected date Chris@0: - (d.getDay() % 7)*days // previous sunday Chris@0: + 4*days // + 4 days Chris@0: ).valueOf(); Chris@0: Chris@0: // the thursday in the first week of the year Chris@0: var first_thursday = new Date( Chris@0: new Date(this.getFullYear(), 0, 4).valueOf() // January 4 is in the first week by definition Chris@0: - (d.getDay() % 7)*days // previous sunday Chris@0: + 4*days // + 4 days Chris@0: ).valueOf(); Chris@0: Chris@0: return Math.round((this_thursday - first_thursday) / (7*days)) + 1; Chris@0: }; Chris@0: Chris@0: /** Checks date and time equality */ Chris@0: Date.prototype.equalsTo = function(date) { Chris@0: return ((this.getFullYear() == date.getFullYear()) && Chris@0: (this.getMonth() == date.getMonth()) && Chris@0: (this.getDate() == date.getDate()) && Chris@0: (this.getHours() == date.getHours()) && Chris@0: (this.getMinutes() == date.getMinutes())); Chris@0: }; Chris@0: Chris@0: /** Set only the year, month, date parts (keep existing time) */ Chris@0: Date.prototype.setDateOnly = function(date) { Chris@0: var tmp = new Date(date); Chris@0: this.setDate(1); Chris@0: this.setFullYear(tmp.getFullYear()); Chris@0: this.setMonth(tmp.getMonth()); Chris@0: this.setDate(tmp.getDate()); Chris@0: }; Chris@0: Chris@0: /** Prints the date in a string according to the given format. */ Chris@0: Date.prototype.print = function (str) { Chris@0: var m = this.getMonth(); Chris@0: var d = this.getDate(); Chris@0: var y = this.getFullYear(); Chris@0: var wn = this.getWeekNumber(); Chris@0: var w = this.getDay(); Chris@0: var s = {}; Chris@0: var hr = this.getHours(); Chris@0: var pm = (hr >= 12); Chris@0: var ir = (pm) ? (hr - 12) : hr; Chris@0: var dy = this.getDayOfYear(); Chris@0: if (ir == 0) Chris@0: ir = 12; Chris@0: var min = this.getMinutes(); Chris@0: var sec = this.getSeconds(); Chris@0: s["%a"] = Calendar._SDN[w]; // abbreviated weekday name [FIXME: I18N] Chris@0: s["%A"] = Calendar._DN[w]; // full weekday name Chris@0: s["%b"] = Calendar._SMN[m]; // abbreviated month name [FIXME: I18N] Chris@0: s["%B"] = Calendar._MN[m]; // full month name Chris@0: // FIXME: %c : preferred date and time representation for the current locale Chris@0: s["%C"] = 1 + Math.floor(y / 100); // the century number Chris@0: s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31) Chris@0: s["%e"] = d; // the day of the month (range 1 to 31) Chris@0: // FIXME: %D : american date style: %m/%d/%y Chris@0: // FIXME: %E, %F, %G, %g, %h (man strftime) Chris@0: s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format) Chris@0: s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format) Chris@0: s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366) Chris@0: s["%k"] = hr; // hour, range 0 to 23 (24h format) Chris@0: s["%l"] = ir; // hour, range 1 to 12 (12h format) Chris@0: s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12 Chris@0: s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59 Chris@0: s["%n"] = "\n"; // a newline character Chris@0: s["%p"] = pm ? "PM" : "AM"; Chris@0: s["%P"] = pm ? "pm" : "am"; Chris@0: // FIXME: %r : the time in am/pm notation %I:%M:%S %p Chris@0: // FIXME: %R : the time in 24-hour notation %H:%M Chris@0: s["%s"] = Math.floor(this.getTime() / 1000); Chris@0: s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59 Chris@0: s["%t"] = "\t"; // a tab character Chris@0: // FIXME: %T : the time in 24-hour notation (%H:%M:%S) Chris@0: s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn; Chris@0: s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON) Chris@0: s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN) Chris@0: // FIXME: %x : preferred date representation for the current locale without the time Chris@0: // FIXME: %X : preferred time representation for the current locale without the date Chris@0: s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99) Chris@0: s["%Y"] = y; // year with the century Chris@0: s["%%"] = "%"; // a literal '%' character Chris@0: Chris@0: var re = /%./g; Chris@0: if (!Calendar.is_ie5 && !Calendar.is_khtml) Chris@0: return str.replace(re, function (par) { return s[par] || par; }); Chris@0: Chris@0: var a = str.match(re); Chris@0: for (var i = 0; i < a.length; i++) { Chris@0: var tmp = s[a[i]]; Chris@0: if (tmp) { Chris@0: re = new RegExp(a[i], 'g'); Chris@0: str = str.replace(re, tmp); Chris@0: } Chris@0: } Chris@0: Chris@0: return str; Chris@0: }; Chris@0: Chris@0: Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear; Chris@0: Date.prototype.setFullYear = function(y) { Chris@0: var d = new Date(this); Chris@0: d.__msh_oldSetFullYear(y); Chris@0: if (d.getMonth() != this.getMonth()) Chris@0: this.setDate(28); Chris@0: this.__msh_oldSetFullYear(y); Chris@0: }; Chris@0: Chris@0: // END: DATE OBJECT PATCHES Chris@0: Chris@0: Chris@0: // global object that remembers the calendar Chris@0: window._dynarch_popupCalendar = null;