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