annotate .svn/pristine/55/551de1919df18269d3487971094e6e1b67a8e45d.svn-base @ 1327:287f201c2802 redmine-2.2-integration

Add italic
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Wed, 19 Jun 2013 20:56:22 +0100
parents cbb26bc654de
children
rev   line source
Chris@909 1 /* Copyright Mihai Bazon, 2002-2005 | www.bazon.net/mishoo
Chris@909 2 * -----------------------------------------------------------
Chris@909 3 *
Chris@909 4 * The DHTML Calendar, version 1.0 "It is happening again"
Chris@909 5 *
Chris@909 6 * Details and latest version at:
Chris@909 7 * www.dynarch.com/projects/calendar
Chris@909 8 *
Chris@909 9 * This script is developed by Dynarch.com. Visit us at www.dynarch.com.
Chris@909 10 *
Chris@909 11 * This script is distributed under the GNU Lesser General Public License.
Chris@909 12 * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
Chris@909 13 */
Chris@909 14
Chris@909 15 // $Id: calendar.js,v 1.51 2005/03/07 16:44:31 mishoo Exp $
Chris@909 16
Chris@909 17 /** The Calendar object constructor. */
Chris@909 18 Calendar = function (firstDayOfWeek, dateStr, onSelected, onClose) {
Chris@909 19 // member variables
Chris@909 20 this.activeDiv = null;
Chris@909 21 this.currentDateEl = null;
Chris@909 22 this.getDateStatus = null;
Chris@909 23 this.getDateToolTip = null;
Chris@909 24 this.getDateText = null;
Chris@909 25 this.timeout = null;
Chris@909 26 this.onSelected = onSelected || null;
Chris@909 27 this.onClose = onClose || null;
Chris@909 28 this.dragging = false;
Chris@909 29 this.hidden = false;
Chris@909 30 this.minYear = 1970;
Chris@909 31 this.maxYear = 2050;
Chris@909 32 this.dateFormat = Calendar._TT["DEF_DATE_FORMAT"];
Chris@909 33 this.ttDateFormat = Calendar._TT["TT_DATE_FORMAT"];
Chris@909 34 this.isPopup = true;
Chris@909 35 this.weekNumbers = true;
Chris@909 36 this.firstDayOfWeek = typeof firstDayOfWeek == "number" ? firstDayOfWeek : Calendar._FD; // 0 for Sunday, 1 for Monday, etc.
Chris@909 37 this.showsOtherMonths = false;
Chris@909 38 this.dateStr = dateStr;
Chris@909 39 this.ar_days = null;
Chris@909 40 this.showsTime = false;
Chris@909 41 this.time24 = true;
Chris@909 42 this.yearStep = 2;
Chris@909 43 this.hiliteToday = true;
Chris@909 44 this.multiple = null;
Chris@909 45 // HTML elements
Chris@909 46 this.table = null;
Chris@909 47 this.element = null;
Chris@909 48 this.tbody = null;
Chris@909 49 this.firstdayname = null;
Chris@909 50 // Combo boxes
Chris@909 51 this.monthsCombo = null;
Chris@909 52 this.yearsCombo = null;
Chris@909 53 this.hilitedMonth = null;
Chris@909 54 this.activeMonth = null;
Chris@909 55 this.hilitedYear = null;
Chris@909 56 this.activeYear = null;
Chris@909 57 // Information
Chris@909 58 this.dateClicked = false;
Chris@909 59
Chris@909 60 // one-time initializations
Chris@909 61 if (typeof Calendar._SDN == "undefined") {
Chris@909 62 // table of short day names
Chris@909 63 if (typeof Calendar._SDN_len == "undefined")
Chris@909 64 Calendar._SDN_len = 3;
Chris@909 65 var ar = new Array();
Chris@909 66 for (var i = 8; i > 0;) {
Chris@909 67 ar[--i] = Calendar._DN[i].substr(0, Calendar._SDN_len);
Chris@909 68 }
Chris@909 69 Calendar._SDN = ar;
Chris@909 70 // table of short month names
Chris@909 71 if (typeof Calendar._SMN_len == "undefined")
Chris@909 72 Calendar._SMN_len = 3;
Chris@909 73 ar = new Array();
Chris@909 74 for (var i = 12; i > 0;) {
Chris@909 75 ar[--i] = Calendar._MN[i].substr(0, Calendar._SMN_len);
Chris@909 76 }
Chris@909 77 Calendar._SMN = ar;
Chris@909 78 }
Chris@909 79 };
Chris@909 80
Chris@909 81 // ** constants
Chris@909 82
Chris@909 83 /// "static", needed for event handlers.
Chris@909 84 Calendar._C = null;
Chris@909 85
Chris@909 86 /// detect a special case of "web browser"
Chris@909 87 Calendar.is_ie = ( /msie/i.test(navigator.userAgent) &&
Chris@909 88 !/opera/i.test(navigator.userAgent) );
Chris@909 89
Chris@909 90 Calendar.is_ie5 = ( Calendar.is_ie && /msie 5\.0/i.test(navigator.userAgent) );
Chris@909 91
Chris@909 92 /// detect Opera browser
Chris@909 93 Calendar.is_opera = /opera/i.test(navigator.userAgent);
Chris@909 94
Chris@909 95 /// detect KHTML-based browsers
Chris@909 96 Calendar.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
Chris@909 97
Chris@909 98 // BEGIN: UTILITY FUNCTIONS; beware that these might be moved into a separate
Chris@909 99 // library, at some point.
Chris@909 100
Chris@909 101 Calendar.getAbsolutePos = function(el) {
Chris@909 102 var SL = 0, ST = 0;
Chris@909 103 var is_div = /^div$/i.test(el.tagName);
Chris@909 104 if (is_div && el.scrollLeft)
Chris@909 105 SL = el.scrollLeft;
Chris@909 106 if (is_div && el.scrollTop)
Chris@909 107 ST = el.scrollTop;
Chris@909 108 var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
Chris@909 109 if (el.offsetParent) {
Chris@909 110 var tmp = this.getAbsolutePos(el.offsetParent);
Chris@909 111 r.x += tmp.x;
Chris@909 112 r.y += tmp.y;
Chris@909 113 }
Chris@909 114 return r;
Chris@909 115 };
Chris@909 116
Chris@909 117 Calendar.isRelated = function (el, evt) {
Chris@909 118 var related = evt.relatedTarget;
Chris@909 119 if (!related) {
Chris@909 120 var type = evt.type;
Chris@909 121 if (type == "mouseover") {
Chris@909 122 related = evt.fromElement;
Chris@909 123 } else if (type == "mouseout") {
Chris@909 124 related = evt.toElement;
Chris@909 125 }
Chris@909 126 }
Chris@909 127 while (related) {
Chris@909 128 if (related == el) {
Chris@909 129 return true;
Chris@909 130 }
Chris@909 131 related = related.parentNode;
Chris@909 132 }
Chris@909 133 return false;
Chris@909 134 };
Chris@909 135
Chris@909 136 Calendar.removeClass = function(el, className) {
Chris@909 137 if (!(el && el.className)) {
Chris@909 138 return;
Chris@909 139 }
Chris@909 140 var cls = el.className.split(" ");
Chris@909 141 var ar = new Array();
Chris@909 142 for (var i = cls.length; i > 0;) {
Chris@909 143 if (cls[--i] != className) {
Chris@909 144 ar[ar.length] = cls[i];
Chris@909 145 }
Chris@909 146 }
Chris@909 147 el.className = ar.join(" ");
Chris@909 148 };
Chris@909 149
Chris@909 150 Calendar.addClass = function(el, className) {
Chris@909 151 Calendar.removeClass(el, className);
Chris@909 152 el.className += " " + className;
Chris@909 153 };
Chris@909 154
Chris@909 155 // FIXME: the following 2 functions totally suck, are useless and should be replaced immediately.
Chris@909 156 Calendar.getElement = function(ev) {
Chris@909 157 var f = Calendar.is_ie ? window.event.srcElement : ev.currentTarget;
Chris@909 158 while (f.nodeType != 1 || /^div$/i.test(f.tagName))
Chris@909 159 f = f.parentNode;
Chris@909 160 return f;
Chris@909 161 };
Chris@909 162
Chris@909 163 Calendar.getTargetElement = function(ev) {
Chris@909 164 var f = Calendar.is_ie ? window.event.srcElement : ev.target;
Chris@909 165 while (f.nodeType != 1)
Chris@909 166 f = f.parentNode;
Chris@909 167 return f;
Chris@909 168 };
Chris@909 169
Chris@909 170 Calendar.stopEvent = function(ev) {
Chris@909 171 ev || (ev = window.event);
Chris@909 172 if (Calendar.is_ie) {
Chris@909 173 ev.cancelBubble = true;
Chris@909 174 ev.returnValue = false;
Chris@909 175 } else {
Chris@909 176 ev.preventDefault();
Chris@909 177 ev.stopPropagation();
Chris@909 178 }
Chris@909 179 return false;
Chris@909 180 };
Chris@909 181
Chris@909 182 Calendar.addEvent = function(el, evname, func) {
Chris@909 183 if (el.attachEvent) { // IE
Chris@909 184 el.attachEvent("on" + evname, func);
Chris@909 185 } else if (el.addEventListener) { // Gecko / W3C
Chris@909 186 el.addEventListener(evname, func, true);
Chris@909 187 } else {
Chris@909 188 el["on" + evname] = func;
Chris@909 189 }
Chris@909 190 };
Chris@909 191
Chris@909 192 Calendar.removeEvent = function(el, evname, func) {
Chris@909 193 if (el.detachEvent) { // IE
Chris@909 194 el.detachEvent("on" + evname, func);
Chris@909 195 } else if (el.removeEventListener) { // Gecko / W3C
Chris@909 196 el.removeEventListener(evname, func, true);
Chris@909 197 } else {
Chris@909 198 el["on" + evname] = null;
Chris@909 199 }
Chris@909 200 };
Chris@909 201
Chris@909 202 Calendar.createElement = function(type, parent) {
Chris@909 203 var el = null;
Chris@909 204 if (document.createElementNS) {
Chris@909 205 // use the XHTML namespace; IE won't normally get here unless
Chris@909 206 // _they_ "fix" the DOM2 implementation.
Chris@909 207 el = document.createElementNS("http://www.w3.org/1999/xhtml", type);
Chris@909 208 } else {
Chris@909 209 el = document.createElement(type);
Chris@909 210 }
Chris@909 211 if (typeof parent != "undefined") {
Chris@909 212 parent.appendChild(el);
Chris@909 213 }
Chris@909 214 return el;
Chris@909 215 };
Chris@909 216
Chris@909 217 // END: UTILITY FUNCTIONS
Chris@909 218
Chris@909 219 // BEGIN: CALENDAR STATIC FUNCTIONS
Chris@909 220
Chris@909 221 /** Internal -- adds a set of events to make some element behave like a button. */
Chris@909 222 Calendar._add_evs = function(el) {
Chris@909 223 with (Calendar) {
Chris@909 224 addEvent(el, "mouseover", dayMouseOver);
Chris@909 225 addEvent(el, "mousedown", dayMouseDown);
Chris@909 226 addEvent(el, "mouseout", dayMouseOut);
Chris@909 227 if (is_ie) {
Chris@909 228 addEvent(el, "dblclick", dayMouseDblClick);
Chris@909 229 el.setAttribute("unselectable", true);
Chris@909 230 }
Chris@909 231 }
Chris@909 232 };
Chris@909 233
Chris@909 234 Calendar.findMonth = function(el) {
Chris@909 235 if (typeof el.month != "undefined") {
Chris@909 236 return el;
Chris@909 237 } else if (typeof el.parentNode.month != "undefined") {
Chris@909 238 return el.parentNode;
Chris@909 239 }
Chris@909 240 return null;
Chris@909 241 };
Chris@909 242
Chris@909 243 Calendar.findYear = function(el) {
Chris@909 244 if (typeof el.year != "undefined") {
Chris@909 245 return el;
Chris@909 246 } else if (typeof el.parentNode.year != "undefined") {
Chris@909 247 return el.parentNode;
Chris@909 248 }
Chris@909 249 return null;
Chris@909 250 };
Chris@909 251
Chris@909 252 Calendar.showMonthsCombo = function () {
Chris@909 253 var cal = Calendar._C;
Chris@909 254 if (!cal) {
Chris@909 255 return false;
Chris@909 256 }
Chris@909 257 var cal = cal;
Chris@909 258 var cd = cal.activeDiv;
Chris@909 259 var mc = cal.monthsCombo;
Chris@909 260 if (cal.hilitedMonth) {
Chris@909 261 Calendar.removeClass(cal.hilitedMonth, "hilite");
Chris@909 262 }
Chris@909 263 if (cal.activeMonth) {
Chris@909 264 Calendar.removeClass(cal.activeMonth, "active");
Chris@909 265 }
Chris@909 266 var mon = cal.monthsCombo.getElementsByTagName("div")[cal.date.getMonth()];
Chris@909 267 Calendar.addClass(mon, "active");
Chris@909 268 cal.activeMonth = mon;
Chris@909 269 var s = mc.style;
Chris@909 270 s.display = "block";
Chris@909 271 if (cd.navtype < 0)
Chris@909 272 s.left = cd.offsetLeft + "px";
Chris@909 273 else {
Chris@909 274 var mcw = mc.offsetWidth;
Chris@909 275 if (typeof mcw == "undefined")
Chris@909 276 // Konqueror brain-dead techniques
Chris@909 277 mcw = 50;
Chris@909 278 s.left = (cd.offsetLeft + cd.offsetWidth - mcw) + "px";
Chris@909 279 }
Chris@909 280 s.top = (cd.offsetTop + cd.offsetHeight) + "px";
Chris@909 281 };
Chris@909 282
Chris@909 283 Calendar.showYearsCombo = function (fwd) {
Chris@909 284 var cal = Calendar._C;
Chris@909 285 if (!cal) {
Chris@909 286 return false;
Chris@909 287 }
Chris@909 288 var cal = cal;
Chris@909 289 var cd = cal.activeDiv;
Chris@909 290 var yc = cal.yearsCombo;
Chris@909 291 if (cal.hilitedYear) {
Chris@909 292 Calendar.removeClass(cal.hilitedYear, "hilite");
Chris@909 293 }
Chris@909 294 if (cal.activeYear) {
Chris@909 295 Calendar.removeClass(cal.activeYear, "active");
Chris@909 296 }
Chris@909 297 cal.activeYear = null;
Chris@909 298 var Y = cal.date.getFullYear() + (fwd ? 1 : -1);
Chris@909 299 var yr = yc.firstChild;
Chris@909 300 var show = false;
Chris@909 301 for (var i = 12; i > 0; --i) {
Chris@909 302 if (Y >= cal.minYear && Y <= cal.maxYear) {
Chris@909 303 yr.innerHTML = Y;
Chris@909 304 yr.year = Y;
Chris@909 305 yr.style.display = "block";
Chris@909 306 show = true;
Chris@909 307 } else {
Chris@909 308 yr.style.display = "none";
Chris@909 309 }
Chris@909 310 yr = yr.nextSibling;
Chris@909 311 Y += fwd ? cal.yearStep : -cal.yearStep;
Chris@909 312 }
Chris@909 313 if (show) {
Chris@909 314 var s = yc.style;
Chris@909 315 s.display = "block";
Chris@909 316 if (cd.navtype < 0)
Chris@909 317 s.left = cd.offsetLeft + "px";
Chris@909 318 else {
Chris@909 319 var ycw = yc.offsetWidth;
Chris@909 320 if (typeof ycw == "undefined")
Chris@909 321 // Konqueror brain-dead techniques
Chris@909 322 ycw = 50;
Chris@909 323 s.left = (cd.offsetLeft + cd.offsetWidth - ycw) + "px";
Chris@909 324 }
Chris@909 325 s.top = (cd.offsetTop + cd.offsetHeight) + "px";
Chris@909 326 }
Chris@909 327 };
Chris@909 328
Chris@909 329 // event handlers
Chris@909 330
Chris@909 331 Calendar.tableMouseUp = function(ev) {
Chris@909 332 var cal = Calendar._C;
Chris@909 333 if (!cal) {
Chris@909 334 return false;
Chris@909 335 }
Chris@909 336 if (cal.timeout) {
Chris@909 337 clearTimeout(cal.timeout);
Chris@909 338 }
Chris@909 339 var el = cal.activeDiv;
Chris@909 340 if (!el) {
Chris@909 341 return false;
Chris@909 342 }
Chris@909 343 var target = Calendar.getTargetElement(ev);
Chris@909 344 ev || (ev = window.event);
Chris@909 345 Calendar.removeClass(el, "active");
Chris@909 346 if (target == el || target.parentNode == el) {
Chris@909 347 Calendar.cellClick(el, ev);
Chris@909 348 }
Chris@909 349 var mon = Calendar.findMonth(target);
Chris@909 350 var date = null;
Chris@909 351 if (mon) {
Chris@909 352 date = new Date(cal.date);
Chris@909 353 if (mon.month != date.getMonth()) {
Chris@909 354 date.setMonth(mon.month);
Chris@909 355 cal.setDate(date);
Chris@909 356 cal.dateClicked = false;
Chris@909 357 cal.callHandler();
Chris@909 358 }
Chris@909 359 } else {
Chris@909 360 var year = Calendar.findYear(target);
Chris@909 361 if (year) {
Chris@909 362 date = new Date(cal.date);
Chris@909 363 if (year.year != date.getFullYear()) {
Chris@909 364 date.setFullYear(year.year);
Chris@909 365 cal.setDate(date);
Chris@909 366 cal.dateClicked = false;
Chris@909 367 cal.callHandler();
Chris@909 368 }
Chris@909 369 }
Chris@909 370 }
Chris@909 371 with (Calendar) {
Chris@909 372 removeEvent(document, "mouseup", tableMouseUp);
Chris@909 373 removeEvent(document, "mouseover", tableMouseOver);
Chris@909 374 removeEvent(document, "mousemove", tableMouseOver);
Chris@909 375 cal._hideCombos();
Chris@909 376 _C = null;
Chris@909 377 return stopEvent(ev);
Chris@909 378 }
Chris@909 379 };
Chris@909 380
Chris@909 381 Calendar.tableMouseOver = function (ev) {
Chris@909 382 var cal = Calendar._C;
Chris@909 383 if (!cal) {
Chris@909 384 return;
Chris@909 385 }
Chris@909 386 var el = cal.activeDiv;
Chris@909 387 var target = Calendar.getTargetElement(ev);
Chris@909 388 if (target == el || target.parentNode == el) {
Chris@909 389 Calendar.addClass(el, "hilite active");
Chris@909 390 Calendar.addClass(el.parentNode, "rowhilite");
Chris@909 391 } else {
Chris@909 392 if (typeof el.navtype == "undefined" || (el.navtype != 50 && (el.navtype == 0 || Math.abs(el.navtype) > 2)))
Chris@909 393 Calendar.removeClass(el, "active");
Chris@909 394 Calendar.removeClass(el, "hilite");
Chris@909 395 Calendar.removeClass(el.parentNode, "rowhilite");
Chris@909 396 }
Chris@909 397 ev || (ev = window.event);
Chris@909 398 if (el.navtype == 50 && target != el) {
Chris@909 399 var pos = Calendar.getAbsolutePos(el);
Chris@909 400 var w = el.offsetWidth;
Chris@909 401 var x = ev.clientX;
Chris@909 402 var dx;
Chris@909 403 var decrease = true;
Chris@909 404 if (x > pos.x + w) {
Chris@909 405 dx = x - pos.x - w;
Chris@909 406 decrease = false;
Chris@909 407 } else
Chris@909 408 dx = pos.x - x;
Chris@909 409
Chris@909 410 if (dx < 0) dx = 0;
Chris@909 411 var range = el._range;
Chris@909 412 var current = el._current;
Chris@909 413 var count = Math.floor(dx / 10) % range.length;
Chris@909 414 for (var i = range.length; --i >= 0;)
Chris@909 415 if (range[i] == current)
Chris@909 416 break;
Chris@909 417 while (count-- > 0)
Chris@909 418 if (decrease) {
Chris@909 419 if (--i < 0)
Chris@909 420 i = range.length - 1;
Chris@909 421 } else if ( ++i >= range.length )
Chris@909 422 i = 0;
Chris@909 423 var newval = range[i];
Chris@909 424 el.innerHTML = newval;
Chris@909 425
Chris@909 426 cal.onUpdateTime();
Chris@909 427 }
Chris@909 428 var mon = Calendar.findMonth(target);
Chris@909 429 if (mon) {
Chris@909 430 if (mon.month != cal.date.getMonth()) {
Chris@909 431 if (cal.hilitedMonth) {
Chris@909 432 Calendar.removeClass(cal.hilitedMonth, "hilite");
Chris@909 433 }
Chris@909 434 Calendar.addClass(mon, "hilite");
Chris@909 435 cal.hilitedMonth = mon;
Chris@909 436 } else if (cal.hilitedMonth) {
Chris@909 437 Calendar.removeClass(cal.hilitedMonth, "hilite");
Chris@909 438 }
Chris@909 439 } else {
Chris@909 440 if (cal.hilitedMonth) {
Chris@909 441 Calendar.removeClass(cal.hilitedMonth, "hilite");
Chris@909 442 }
Chris@909 443 var year = Calendar.findYear(target);
Chris@909 444 if (year) {
Chris@909 445 if (year.year != cal.date.getFullYear()) {
Chris@909 446 if (cal.hilitedYear) {
Chris@909 447 Calendar.removeClass(cal.hilitedYear, "hilite");
Chris@909 448 }
Chris@909 449 Calendar.addClass(year, "hilite");
Chris@909 450 cal.hilitedYear = year;
Chris@909 451 } else if (cal.hilitedYear) {
Chris@909 452 Calendar.removeClass(cal.hilitedYear, "hilite");
Chris@909 453 }
Chris@909 454 } else if (cal.hilitedYear) {
Chris@909 455 Calendar.removeClass(cal.hilitedYear, "hilite");
Chris@909 456 }
Chris@909 457 }
Chris@909 458 return Calendar.stopEvent(ev);
Chris@909 459 };
Chris@909 460
Chris@909 461 Calendar.tableMouseDown = function (ev) {
Chris@909 462 if (Calendar.getTargetElement(ev) == Calendar.getElement(ev)) {
Chris@909 463 return Calendar.stopEvent(ev);
Chris@909 464 }
Chris@909 465 };
Chris@909 466
Chris@909 467 Calendar.calDragIt = function (ev) {
Chris@909 468 var cal = Calendar._C;
Chris@909 469 if (!(cal && cal.dragging)) {
Chris@909 470 return false;
Chris@909 471 }
Chris@909 472 var posX;
Chris@909 473 var posY;
Chris@909 474 if (Calendar.is_ie) {
Chris@909 475 posY = window.event.clientY + document.body.scrollTop;
Chris@909 476 posX = window.event.clientX + document.body.scrollLeft;
Chris@909 477 } else {
Chris@909 478 posX = ev.pageX;
Chris@909 479 posY = ev.pageY;
Chris@909 480 }
Chris@909 481 cal.hideShowCovered();
Chris@909 482 var st = cal.element.style;
Chris@909 483 st.left = (posX - cal.xOffs) + "px";
Chris@909 484 st.top = (posY - cal.yOffs) + "px";
Chris@909 485 return Calendar.stopEvent(ev);
Chris@909 486 };
Chris@909 487
Chris@909 488 Calendar.calDragEnd = function (ev) {
Chris@909 489 var cal = Calendar._C;
Chris@909 490 if (!cal) {
Chris@909 491 return false;
Chris@909 492 }
Chris@909 493 cal.dragging = false;
Chris@909 494 with (Calendar) {
Chris@909 495 removeEvent(document, "mousemove", calDragIt);
Chris@909 496 removeEvent(document, "mouseup", calDragEnd);
Chris@909 497 tableMouseUp(ev);
Chris@909 498 }
Chris@909 499 cal.hideShowCovered();
Chris@909 500 };
Chris@909 501
Chris@909 502 Calendar.dayMouseDown = function(ev) {
Chris@909 503 var el = Calendar.getElement(ev);
Chris@909 504 if (el.disabled) {
Chris@909 505 return false;
Chris@909 506 }
Chris@909 507 var cal = el.calendar;
Chris@909 508 cal.activeDiv = el;
Chris@909 509 Calendar._C = cal;
Chris@909 510 if (el.navtype != 300) with (Calendar) {
Chris@909 511 if (el.navtype == 50) {
Chris@909 512 el._current = el.innerHTML;
Chris@909 513 addEvent(document, "mousemove", tableMouseOver);
Chris@909 514 } else
Chris@909 515 addEvent(document, Calendar.is_ie5 ? "mousemove" : "mouseover", tableMouseOver);
Chris@909 516 addClass(el, "hilite active");
Chris@909 517 addEvent(document, "mouseup", tableMouseUp);
Chris@909 518 } else if (cal.isPopup) {
Chris@909 519 cal._dragStart(ev);
Chris@909 520 }
Chris@909 521 if (el.navtype == -1 || el.navtype == 1) {
Chris@909 522 if (cal.timeout) clearTimeout(cal.timeout);
Chris@909 523 cal.timeout = setTimeout("Calendar.showMonthsCombo()", 250);
Chris@909 524 } else if (el.navtype == -2 || el.navtype == 2) {
Chris@909 525 if (cal.timeout) clearTimeout(cal.timeout);
Chris@909 526 cal.timeout = setTimeout((el.navtype > 0) ? "Calendar.showYearsCombo(true)" : "Calendar.showYearsCombo(false)", 250);
Chris@909 527 } else {
Chris@909 528 cal.timeout = null;
Chris@909 529 }
Chris@909 530 return Calendar.stopEvent(ev);
Chris@909 531 };
Chris@909 532
Chris@909 533 Calendar.dayMouseDblClick = function(ev) {
Chris@909 534 Calendar.cellClick(Calendar.getElement(ev), ev || window.event);
Chris@909 535 if (Calendar.is_ie) {
Chris@909 536 document.selection.empty();
Chris@909 537 }
Chris@909 538 };
Chris@909 539
Chris@909 540 Calendar.dayMouseOver = function(ev) {
Chris@909 541 var el = Calendar.getElement(ev);
Chris@909 542 if (Calendar.isRelated(el, ev) || Calendar._C || el.disabled) {
Chris@909 543 return false;
Chris@909 544 }
Chris@909 545 if (el.ttip) {
Chris@909 546 if (el.ttip.substr(0, 1) == "_") {
Chris@909 547 el.ttip = el.caldate.print(el.calendar.ttDateFormat) + el.ttip.substr(1);
Chris@909 548 }
Chris@909 549 el.calendar.tooltips.innerHTML = el.ttip;
Chris@909 550 }
Chris@909 551 if (el.navtype != 300) {
Chris@909 552 Calendar.addClass(el, "hilite");
Chris@909 553 if (el.caldate) {
Chris@909 554 Calendar.addClass(el.parentNode, "rowhilite");
Chris@909 555 }
Chris@909 556 }
Chris@909 557 return Calendar.stopEvent(ev);
Chris@909 558 };
Chris@909 559
Chris@909 560 Calendar.dayMouseOut = function(ev) {
Chris@909 561 with (Calendar) {
Chris@909 562 var el = getElement(ev);
Chris@909 563 if (isRelated(el, ev) || _C || el.disabled)
Chris@909 564 return false;
Chris@909 565 removeClass(el, "hilite");
Chris@909 566 if (el.caldate)
Chris@909 567 removeClass(el.parentNode, "rowhilite");
Chris@909 568 if (el.calendar)
Chris@909 569 el.calendar.tooltips.innerHTML = _TT["SEL_DATE"];
Chris@909 570 return stopEvent(ev);
Chris@909 571 }
Chris@909 572 };
Chris@909 573
Chris@909 574 /**
Chris@909 575 * A generic "click" handler :) handles all types of buttons defined in this
Chris@909 576 * calendar.
Chris@909 577 */
Chris@909 578 Calendar.cellClick = function(el, ev) {
Chris@909 579 var cal = el.calendar;
Chris@909 580 var closing = false;
Chris@909 581 var newdate = false;
Chris@909 582 var date = null;
Chris@909 583 if (typeof el.navtype == "undefined") {
Chris@909 584 if (cal.currentDateEl) {
Chris@909 585 Calendar.removeClass(cal.currentDateEl, "selected");
Chris@909 586 Calendar.addClass(el, "selected");
Chris@909 587 closing = (cal.currentDateEl == el);
Chris@909 588 if (!closing) {
Chris@909 589 cal.currentDateEl = el;
Chris@909 590 }
Chris@909 591 }
Chris@909 592 cal.date.setDateOnly(el.caldate);
Chris@909 593 date = cal.date;
Chris@909 594 var other_month = !(cal.dateClicked = !el.otherMonth);
Chris@909 595 if (!other_month && !cal.currentDateEl)
Chris@909 596 cal._toggleMultipleDate(new Date(date));
Chris@909 597 else
Chris@909 598 newdate = !el.disabled;
Chris@909 599 // a date was clicked
Chris@909 600 if (other_month)
Chris@909 601 cal._init(cal.firstDayOfWeek, date);
Chris@909 602 } else {
Chris@909 603 if (el.navtype == 200) {
Chris@909 604 Calendar.removeClass(el, "hilite");
Chris@909 605 cal.callCloseHandler();
Chris@909 606 return;
Chris@909 607 }
Chris@909 608 date = new Date(cal.date);
Chris@909 609 if (el.navtype == 0)
Chris@909 610 date.setDateOnly(new Date()); // TODAY
Chris@909 611 // unless "today" was clicked, we assume no date was clicked so
Chris@909 612 // the selected handler will know not to close the calenar when
Chris@909 613 // in single-click mode.
Chris@909 614 // cal.dateClicked = (el.navtype == 0);
Chris@909 615 cal.dateClicked = false;
Chris@909 616 var year = date.getFullYear();
Chris@909 617 var mon = date.getMonth();
Chris@909 618 function setMonth(m) {
Chris@909 619 var day = date.getDate();
Chris@909 620 var max = date.getMonthDays(m);
Chris@909 621 if (day > max) {
Chris@909 622 date.setDate(max);
Chris@909 623 }
Chris@909 624 date.setMonth(m);
Chris@909 625 };
Chris@909 626 switch (el.navtype) {
Chris@909 627 case 400:
Chris@909 628 Calendar.removeClass(el, "hilite");
Chris@909 629 var text = Calendar._TT["ABOUT"];
Chris@909 630 if (typeof text != "undefined") {
Chris@909 631 text += cal.showsTime ? Calendar._TT["ABOUT_TIME"] : "";
Chris@909 632 } else {
Chris@909 633 // FIXME: this should be removed as soon as lang files get updated!
Chris@909 634 text = "Help and about box text is not translated into this language.\n" +
Chris@909 635 "If you know this language and you feel generous please update\n" +
Chris@909 636 "the corresponding file in \"lang\" subdir to match calendar-en.js\n" +
Chris@909 637 "and send it back to <mihai_bazon@yahoo.com> to get it into the distribution ;-)\n\n" +
Chris@909 638 "Thank you!\n" +
Chris@909 639 "http://dynarch.com/mishoo/calendar.epl\n";
Chris@909 640 }
Chris@909 641 alert(text);
Chris@909 642 return;
Chris@909 643 case -2:
Chris@909 644 if (year > cal.minYear) {
Chris@909 645 date.setFullYear(year - 1);
Chris@909 646 }
Chris@909 647 break;
Chris@909 648 case -1:
Chris@909 649 if (mon > 0) {
Chris@909 650 setMonth(mon - 1);
Chris@909 651 } else if (year-- > cal.minYear) {
Chris@909 652 date.setFullYear(year);
Chris@909 653 setMonth(11);
Chris@909 654 }
Chris@909 655 break;
Chris@909 656 case 1:
Chris@909 657 if (mon < 11) {
Chris@909 658 setMonth(mon + 1);
Chris@909 659 } else if (year < cal.maxYear) {
Chris@909 660 date.setFullYear(year + 1);
Chris@909 661 setMonth(0);
Chris@909 662 }
Chris@909 663 break;
Chris@909 664 case 2:
Chris@909 665 if (year < cal.maxYear) {
Chris@909 666 date.setFullYear(year + 1);
Chris@909 667 }
Chris@909 668 break;
Chris@909 669 case 100:
Chris@909 670 cal.setFirstDayOfWeek(el.fdow);
Chris@909 671 return;
Chris@909 672 case 50:
Chris@909 673 var range = el._range;
Chris@909 674 var current = el.innerHTML;
Chris@909 675 for (var i = range.length; --i >= 0;)
Chris@909 676 if (range[i] == current)
Chris@909 677 break;
Chris@909 678 if (ev && ev.shiftKey) {
Chris@909 679 if (--i < 0)
Chris@909 680 i = range.length - 1;
Chris@909 681 } else if ( ++i >= range.length )
Chris@909 682 i = 0;
Chris@909 683 var newval = range[i];
Chris@909 684 el.innerHTML = newval;
Chris@909 685 cal.onUpdateTime();
Chris@909 686 return;
Chris@909 687 case 0:
Chris@909 688 // TODAY will bring us here
Chris@909 689 if ((typeof cal.getDateStatus == "function") &&
Chris@909 690 cal.getDateStatus(date, date.getFullYear(), date.getMonth(), date.getDate())) {
Chris@909 691 return false;
Chris@909 692 }
Chris@909 693 break;
Chris@909 694 }
Chris@909 695 if (!date.equalsTo(cal.date)) {
Chris@909 696 cal.setDate(date);
Chris@909 697 newdate = true;
Chris@909 698 } else if (el.navtype == 0)
Chris@909 699 newdate = closing = true;
Chris@909 700 }
Chris@909 701 if (newdate) {
Chris@909 702 ev && cal.callHandler();
Chris@909 703 }
Chris@909 704 if (closing) {
Chris@909 705 Calendar.removeClass(el, "hilite");
Chris@909 706 ev && cal.callCloseHandler();
Chris@909 707 }
Chris@909 708 };
Chris@909 709
Chris@909 710 // END: CALENDAR STATIC FUNCTIONS
Chris@909 711
Chris@909 712 // BEGIN: CALENDAR OBJECT FUNCTIONS
Chris@909 713
Chris@909 714 /**
Chris@909 715 * This function creates the calendar inside the given parent. If _par is
Chris@909 716 * null than it creates a popup calendar inside the BODY element. If _par is
Chris@909 717 * an element, be it BODY, then it creates a non-popup calendar (still
Chris@909 718 * hidden). Some properties need to be set before calling this function.
Chris@909 719 */
Chris@909 720 Calendar.prototype.create = function (_par) {
Chris@909 721 var parent = null;
Chris@909 722 if (! _par) {
Chris@909 723 // default parent is the document body, in which case we create
Chris@909 724 // a popup calendar.
Chris@909 725 parent = document.getElementsByTagName("body")[0];
Chris@909 726 this.isPopup = true;
Chris@909 727 } else {
Chris@909 728 parent = _par;
Chris@909 729 this.isPopup = false;
Chris@909 730 }
Chris@909 731 this.date = this.dateStr ? new Date(this.dateStr) : new Date();
Chris@909 732
Chris@909 733 var table = Calendar.createElement("table");
Chris@909 734 this.table = table;
Chris@909 735 table.cellSpacing = 0;
Chris@909 736 table.cellPadding = 0;
Chris@909 737 table.calendar = this;
Chris@909 738 Calendar.addEvent(table, "mousedown", Calendar.tableMouseDown);
Chris@909 739
Chris@909 740 var div = Calendar.createElement("div");
Chris@909 741 this.element = div;
Chris@909 742 div.className = "calendar";
Chris@909 743 if (this.isPopup) {
Chris@909 744 div.style.position = "absolute";
Chris@909 745 div.style.display = "none";
Chris@909 746 }
Chris@909 747 div.appendChild(table);
Chris@909 748
Chris@909 749 var thead = Calendar.createElement("thead", table);
Chris@909 750 var cell = null;
Chris@909 751 var row = null;
Chris@909 752
Chris@909 753 var cal = this;
Chris@909 754 var hh = function (text, cs, navtype) {
Chris@909 755 cell = Calendar.createElement("td", row);
Chris@909 756 cell.colSpan = cs;
Chris@909 757 cell.className = "button";
Chris@909 758 if (navtype != 0 && Math.abs(navtype) <= 2)
Chris@909 759 cell.className += " nav";
Chris@909 760 Calendar._add_evs(cell);
Chris@909 761 cell.calendar = cal;
Chris@909 762 cell.navtype = navtype;
Chris@909 763 cell.innerHTML = "<div unselectable='on'>" + text + "</div>";
Chris@909 764 return cell;
Chris@909 765 };
Chris@909 766
Chris@909 767 row = Calendar.createElement("tr", thead);
Chris@909 768 var title_length = 6;
Chris@909 769 (this.isPopup) && --title_length;
Chris@909 770 (this.weekNumbers) && ++title_length;
Chris@909 771
Chris@909 772 hh("?", 1, 400).ttip = Calendar._TT["INFO"];
Chris@909 773 this.title = hh("", title_length, 300);
Chris@909 774 this.title.className = "title";
Chris@909 775 if (this.isPopup) {
Chris@909 776 this.title.ttip = Calendar._TT["DRAG_TO_MOVE"];
Chris@909 777 this.title.style.cursor = "move";
Chris@909 778 hh("&#x00d7;", 1, 200).ttip = Calendar._TT["CLOSE"];
Chris@909 779 }
Chris@909 780
Chris@909 781 row = Calendar.createElement("tr", thead);
Chris@909 782 row.className = "headrow";
Chris@909 783
Chris@909 784 this._nav_py = hh("&#x00ab;", 1, -2);
Chris@909 785 this._nav_py.ttip = Calendar._TT["PREV_YEAR"];
Chris@909 786
Chris@909 787 this._nav_pm = hh("&#x2039;", 1, -1);
Chris@909 788 this._nav_pm.ttip = Calendar._TT["PREV_MONTH"];
Chris@909 789
Chris@909 790 this._nav_now = hh(Calendar._TT["TODAY"], this.weekNumbers ? 4 : 3, 0);
Chris@909 791 this._nav_now.ttip = Calendar._TT["GO_TODAY"];
Chris@909 792
Chris@909 793 this._nav_nm = hh("&#x203a;", 1, 1);
Chris@909 794 this._nav_nm.ttip = Calendar._TT["NEXT_MONTH"];
Chris@909 795
Chris@909 796 this._nav_ny = hh("&#x00bb;", 1, 2);
Chris@909 797 this._nav_ny.ttip = Calendar._TT["NEXT_YEAR"];
Chris@909 798
Chris@909 799 // day names
Chris@909 800 row = Calendar.createElement("tr", thead);
Chris@909 801 row.className = "daynames";
Chris@909 802 if (this.weekNumbers) {
Chris@909 803 cell = Calendar.createElement("td", row);
Chris@909 804 cell.className = "name wn";
Chris@909 805 cell.innerHTML = Calendar._TT["WK"];
Chris@909 806 }
Chris@909 807 for (var i = 7; i > 0; --i) {
Chris@909 808 cell = Calendar.createElement("td", row);
Chris@909 809 if (!i) {
Chris@909 810 cell.navtype = 100;
Chris@909 811 cell.calendar = this;
Chris@909 812 Calendar._add_evs(cell);
Chris@909 813 }
Chris@909 814 }
Chris@909 815 this.firstdayname = (this.weekNumbers) ? row.firstChild.nextSibling : row.firstChild;
Chris@909 816 this._displayWeekdays();
Chris@909 817
Chris@909 818 var tbody = Calendar.createElement("tbody", table);
Chris@909 819 this.tbody = tbody;
Chris@909 820
Chris@909 821 for (i = 6; i > 0; --i) {
Chris@909 822 row = Calendar.createElement("tr", tbody);
Chris@909 823 if (this.weekNumbers) {
Chris@909 824 cell = Calendar.createElement("td", row);
Chris@909 825 }
Chris@909 826 for (var j = 7; j > 0; --j) {
Chris@909 827 cell = Calendar.createElement("td", row);
Chris@909 828 cell.calendar = this;
Chris@909 829 Calendar._add_evs(cell);
Chris@909 830 }
Chris@909 831 }
Chris@909 832
Chris@909 833 if (this.showsTime) {
Chris@909 834 row = Calendar.createElement("tr", tbody);
Chris@909 835 row.className = "time";
Chris@909 836
Chris@909 837 cell = Calendar.createElement("td", row);
Chris@909 838 cell.className = "time";
Chris@909 839 cell.colSpan = 2;
Chris@909 840 cell.innerHTML = Calendar._TT["TIME"] || "&nbsp;";
Chris@909 841
Chris@909 842 cell = Calendar.createElement("td", row);
Chris@909 843 cell.className = "time";
Chris@909 844 cell.colSpan = this.weekNumbers ? 4 : 3;
Chris@909 845
Chris@909 846 (function(){
Chris@909 847 function makeTimePart(className, init, range_start, range_end) {
Chris@909 848 var part = Calendar.createElement("span", cell);
Chris@909 849 part.className = className;
Chris@909 850 part.innerHTML = init;
Chris@909 851 part.calendar = cal;
Chris@909 852 part.ttip = Calendar._TT["TIME_PART"];
Chris@909 853 part.navtype = 50;
Chris@909 854 part._range = [];
Chris@909 855 if (typeof range_start != "number")
Chris@909 856 part._range = range_start;
Chris@909 857 else {
Chris@909 858 for (var i = range_start; i <= range_end; ++i) {
Chris@909 859 var txt;
Chris@909 860 if (i < 10 && range_end >= 10) txt = '0' + i;
Chris@909 861 else txt = '' + i;
Chris@909 862 part._range[part._range.length] = txt;
Chris@909 863 }
Chris@909 864 }
Chris@909 865 Calendar._add_evs(part);
Chris@909 866 return part;
Chris@909 867 };
Chris@909 868 var hrs = cal.date.getHours();
Chris@909 869 var mins = cal.date.getMinutes();
Chris@909 870 var t12 = !cal.time24;
Chris@909 871 var pm = (hrs > 12);
Chris@909 872 if (t12 && pm) hrs -= 12;
Chris@909 873 var H = makeTimePart("hour", hrs, t12 ? 1 : 0, t12 ? 12 : 23);
Chris@909 874 var span = Calendar.createElement("span", cell);
Chris@909 875 span.innerHTML = ":";
Chris@909 876 span.className = "colon";
Chris@909 877 var M = makeTimePart("minute", mins, 0, 59);
Chris@909 878 var AP = null;
Chris@909 879 cell = Calendar.createElement("td", row);
Chris@909 880 cell.className = "time";
Chris@909 881 cell.colSpan = 2;
Chris@909 882 if (t12)
Chris@909 883 AP = makeTimePart("ampm", pm ? "pm" : "am", ["am", "pm"]);
Chris@909 884 else
Chris@909 885 cell.innerHTML = "&nbsp;";
Chris@909 886
Chris@909 887 cal.onSetTime = function() {
Chris@909 888 var pm, hrs = this.date.getHours(),
Chris@909 889 mins = this.date.getMinutes();
Chris@909 890 if (t12) {
Chris@909 891 pm = (hrs >= 12);
Chris@909 892 if (pm) hrs -= 12;
Chris@909 893 if (hrs == 0) hrs = 12;
Chris@909 894 AP.innerHTML = pm ? "pm" : "am";
Chris@909 895 }
Chris@909 896 H.innerHTML = (hrs < 10) ? ("0" + hrs) : hrs;
Chris@909 897 M.innerHTML = (mins < 10) ? ("0" + mins) : mins;
Chris@909 898 };
Chris@909 899
Chris@909 900 cal.onUpdateTime = function() {
Chris@909 901 var date = this.date;
Chris@909 902 var h = parseInt(H.innerHTML, 10);
Chris@909 903 if (t12) {
Chris@909 904 if (/pm/i.test(AP.innerHTML) && h < 12)
Chris@909 905 h += 12;
Chris@909 906 else if (/am/i.test(AP.innerHTML) && h == 12)
Chris@909 907 h = 0;
Chris@909 908 }
Chris@909 909 var d = date.getDate();
Chris@909 910 var m = date.getMonth();
Chris@909 911 var y = date.getFullYear();
Chris@909 912 date.setHours(h);
Chris@909 913 date.setMinutes(parseInt(M.innerHTML, 10));
Chris@909 914 date.setFullYear(y);
Chris@909 915 date.setMonth(m);
Chris@909 916 date.setDate(d);
Chris@909 917 this.dateClicked = false;
Chris@909 918 this.callHandler();
Chris@909 919 };
Chris@909 920 })();
Chris@909 921 } else {
Chris@909 922 this.onSetTime = this.onUpdateTime = function() {};
Chris@909 923 }
Chris@909 924
Chris@909 925 var tfoot = Calendar.createElement("tfoot", table);
Chris@909 926
Chris@909 927 row = Calendar.createElement("tr", tfoot);
Chris@909 928 row.className = "footrow";
Chris@909 929
Chris@909 930 cell = hh(Calendar._TT["SEL_DATE"], this.weekNumbers ? 8 : 7, 300);
Chris@909 931 cell.className = "ttip";
Chris@909 932 if (this.isPopup) {
Chris@909 933 cell.ttip = Calendar._TT["DRAG_TO_MOVE"];
Chris@909 934 cell.style.cursor = "move";
Chris@909 935 }
Chris@909 936 this.tooltips = cell;
Chris@909 937
Chris@909 938 div = Calendar.createElement("div", this.element);
Chris@909 939 this.monthsCombo = div;
Chris@909 940 div.className = "combo";
Chris@909 941 for (i = 0; i < Calendar._MN.length; ++i) {
Chris@909 942 var mn = Calendar.createElement("div");
Chris@909 943 mn.className = Calendar.is_ie ? "label-IEfix" : "label";
Chris@909 944 mn.month = i;
Chris@909 945 mn.innerHTML = Calendar._SMN[i];
Chris@909 946 div.appendChild(mn);
Chris@909 947 }
Chris@909 948
Chris@909 949 div = Calendar.createElement("div", this.element);
Chris@909 950 this.yearsCombo = div;
Chris@909 951 div.className = "combo";
Chris@909 952 for (i = 12; i > 0; --i) {
Chris@909 953 var yr = Calendar.createElement("div");
Chris@909 954 yr.className = Calendar.is_ie ? "label-IEfix" : "label";
Chris@909 955 div.appendChild(yr);
Chris@909 956 }
Chris@909 957
Chris@909 958 this._init(this.firstDayOfWeek, this.date);
Chris@909 959 parent.appendChild(this.element);
Chris@909 960 };
Chris@909 961
Chris@909 962 /** keyboard navigation, only for popup calendars */
Chris@909 963 Calendar._keyEvent = function(ev) {
Chris@909 964 var cal = window._dynarch_popupCalendar;
Chris@909 965 if (!cal || cal.multiple)
Chris@909 966 return false;
Chris@909 967 (Calendar.is_ie) && (ev = window.event);
Chris@909 968 var act = (Calendar.is_ie || ev.type == "keypress"),
Chris@909 969 K = ev.keyCode;
Chris@909 970 if (ev.ctrlKey) {
Chris@909 971 switch (K) {
Chris@909 972 case 37: // KEY left
Chris@909 973 act && Calendar.cellClick(cal._nav_pm);
Chris@909 974 break;
Chris@909 975 case 38: // KEY up
Chris@909 976 act && Calendar.cellClick(cal._nav_py);
Chris@909 977 break;
Chris@909 978 case 39: // KEY right
Chris@909 979 act && Calendar.cellClick(cal._nav_nm);
Chris@909 980 break;
Chris@909 981 case 40: // KEY down
Chris@909 982 act && Calendar.cellClick(cal._nav_ny);
Chris@909 983 break;
Chris@909 984 default:
Chris@909 985 return false;
Chris@909 986 }
Chris@909 987 } else switch (K) {
Chris@909 988 case 32: // KEY space (now)
Chris@909 989 Calendar.cellClick(cal._nav_now);
Chris@909 990 break;
Chris@909 991 case 27: // KEY esc
Chris@909 992 act && cal.callCloseHandler();
Chris@909 993 break;
Chris@909 994 case 37: // KEY left
Chris@909 995 case 38: // KEY up
Chris@909 996 case 39: // KEY right
Chris@909 997 case 40: // KEY down
Chris@909 998 if (act) {
Chris@909 999 var prev, x, y, ne, el, step;
Chris@909 1000 prev = K == 37 || K == 38;
Chris@909 1001 step = (K == 37 || K == 39) ? 1 : 7;
Chris@909 1002 function setVars() {
Chris@909 1003 el = cal.currentDateEl;
Chris@909 1004 var p = el.pos;
Chris@909 1005 x = p & 15;
Chris@909 1006 y = p >> 4;
Chris@909 1007 ne = cal.ar_days[y][x];
Chris@909 1008 };setVars();
Chris@909 1009 function prevMonth() {
Chris@909 1010 var date = new Date(cal.date);
Chris@909 1011 date.setDate(date.getDate() - step);
Chris@909 1012 cal.setDate(date);
Chris@909 1013 };
Chris@909 1014 function nextMonth() {
Chris@909 1015 var date = new Date(cal.date);
Chris@909 1016 date.setDate(date.getDate() + step);
Chris@909 1017 cal.setDate(date);
Chris@909 1018 };
Chris@909 1019 while (1) {
Chris@909 1020 switch (K) {
Chris@909 1021 case 37: // KEY left
Chris@909 1022 if (--x >= 0)
Chris@909 1023 ne = cal.ar_days[y][x];
Chris@909 1024 else {
Chris@909 1025 x = 6;
Chris@909 1026 K = 38;
Chris@909 1027 continue;
Chris@909 1028 }
Chris@909 1029 break;
Chris@909 1030 case 38: // KEY up
Chris@909 1031 if (--y >= 0)
Chris@909 1032 ne = cal.ar_days[y][x];
Chris@909 1033 else {
Chris@909 1034 prevMonth();
Chris@909 1035 setVars();
Chris@909 1036 }
Chris@909 1037 break;
Chris@909 1038 case 39: // KEY right
Chris@909 1039 if (++x < 7)
Chris@909 1040 ne = cal.ar_days[y][x];
Chris@909 1041 else {
Chris@909 1042 x = 0;
Chris@909 1043 K = 40;
Chris@909 1044 continue;
Chris@909 1045 }
Chris@909 1046 break;
Chris@909 1047 case 40: // KEY down
Chris@909 1048 if (++y < cal.ar_days.length)
Chris@909 1049 ne = cal.ar_days[y][x];
Chris@909 1050 else {
Chris@909 1051 nextMonth();
Chris@909 1052 setVars();
Chris@909 1053 }
Chris@909 1054 break;
Chris@909 1055 }
Chris@909 1056 break;
Chris@909 1057 }
Chris@909 1058 if (ne) {
Chris@909 1059 if (!ne.disabled)
Chris@909 1060 Calendar.cellClick(ne);
Chris@909 1061 else if (prev)
Chris@909 1062 prevMonth();
Chris@909 1063 else
Chris@909 1064 nextMonth();
Chris@909 1065 }
Chris@909 1066 }
Chris@909 1067 break;
Chris@909 1068 case 13: // KEY enter
Chris@909 1069 if (act)
Chris@909 1070 Calendar.cellClick(cal.currentDateEl, ev);
Chris@909 1071 break;
Chris@909 1072 default:
Chris@909 1073 return false;
Chris@909 1074 }
Chris@909 1075 return Calendar.stopEvent(ev);
Chris@909 1076 };
Chris@909 1077
Chris@909 1078 /**
Chris@909 1079 * (RE)Initializes the calendar to the given date and firstDayOfWeek
Chris@909 1080 */
Chris@909 1081 Calendar.prototype._init = function (firstDayOfWeek, date) {
Chris@909 1082 var today = new Date(),
Chris@909 1083 TY = today.getFullYear(),
Chris@909 1084 TM = today.getMonth(),
Chris@909 1085 TD = today.getDate();
Chris@909 1086 this.table.style.visibility = "hidden";
Chris@909 1087 var year = date.getFullYear();
Chris@909 1088 if (year < this.minYear) {
Chris@909 1089 year = this.minYear;
Chris@909 1090 date.setFullYear(year);
Chris@909 1091 } else if (year > this.maxYear) {
Chris@909 1092 year = this.maxYear;
Chris@909 1093 date.setFullYear(year);
Chris@909 1094 }
Chris@909 1095 this.firstDayOfWeek = firstDayOfWeek;
Chris@909 1096 this.date = new Date(date);
Chris@909 1097 var month = date.getMonth();
Chris@909 1098 var mday = date.getDate();
Chris@909 1099 var no_days = date.getMonthDays();
Chris@909 1100
Chris@909 1101 // calendar voodoo for computing the first day that would actually be
Chris@909 1102 // displayed in the calendar, even if it's from the previous month.
Chris@909 1103 // WARNING: this is magic. ;-)
Chris@909 1104 date.setDate(1);
Chris@909 1105 var day1 = (date.getDay() - this.firstDayOfWeek) % 7;
Chris@909 1106 if (day1 < 0)
Chris@909 1107 day1 += 7;
Chris@909 1108 date.setDate(0-day1);
Chris@909 1109 date.setDate(date.getDate() + 1);
Chris@909 1110
Chris@909 1111 var row = this.tbody.firstChild;
Chris@909 1112 var MN = Calendar._SMN[month];
Chris@909 1113 var ar_days = this.ar_days = new Array();
Chris@909 1114 var weekend = Calendar._TT["WEEKEND"];
Chris@909 1115 var dates = this.multiple ? (this.datesCells = {}) : null;
Chris@909 1116 for (var i = 0; i < 6; ++i, row = row.nextSibling) {
Chris@909 1117 var cell = row.firstChild;
Chris@909 1118 if (this.weekNumbers) {
Chris@909 1119 cell.className = "day wn";
Chris@909 1120 cell.innerHTML = date.getWeekNumber();
Chris@909 1121 cell = cell.nextSibling;
Chris@909 1122 }
Chris@909 1123 row.className = "daysrow";
Chris@909 1124 var hasdays = false, iday, dpos = ar_days[i] = [];
Chris@909 1125 for (var j = 0; j < 7; ++j, cell = cell.nextSibling, date.setDate(iday + 1)) {
Chris@909 1126 iday = date.getDate();
Chris@909 1127 var wday = date.getDay();
Chris@909 1128 cell.className = "day";
Chris@909 1129 cell.pos = i << 4 | j;
Chris@909 1130 dpos[j] = cell;
Chris@909 1131 var current_month = (date.getMonth() == month);
Chris@909 1132 if (!current_month) {
Chris@909 1133 if (this.showsOtherMonths) {
Chris@909 1134 cell.className += " othermonth";
Chris@909 1135 cell.otherMonth = true;
Chris@909 1136 } else {
Chris@909 1137 cell.className = "emptycell";
Chris@909 1138 cell.innerHTML = "&nbsp;";
Chris@909 1139 cell.disabled = true;
Chris@909 1140 continue;
Chris@909 1141 }
Chris@909 1142 } else {
Chris@909 1143 cell.otherMonth = false;
Chris@909 1144 hasdays = true;
Chris@909 1145 }
Chris@909 1146 cell.disabled = false;
Chris@909 1147 cell.innerHTML = this.getDateText ? this.getDateText(date, iday) : iday;
Chris@909 1148 if (dates)
Chris@909 1149 dates[date.print("%Y%m%d")] = cell;
Chris@909 1150 if (this.getDateStatus) {
Chris@909 1151 var status = this.getDateStatus(date, year, month, iday);
Chris@909 1152 if (this.getDateToolTip) {
Chris@909 1153 var toolTip = this.getDateToolTip(date, year, month, iday);
Chris@909 1154 if (toolTip)
Chris@909 1155 cell.title = toolTip;
Chris@909 1156 }
Chris@909 1157 if (status === true) {
Chris@909 1158 cell.className += " disabled";
Chris@909 1159 cell.disabled = true;
Chris@909 1160 } else {
Chris@909 1161 if (/disabled/i.test(status))
Chris@909 1162 cell.disabled = true;
Chris@909 1163 cell.className += " " + status;
Chris@909 1164 }
Chris@909 1165 }
Chris@909 1166 if (!cell.disabled) {
Chris@909 1167 cell.caldate = new Date(date);
Chris@909 1168 cell.ttip = "_";
Chris@909 1169 if (!this.multiple && current_month
Chris@909 1170 && iday == mday && this.hiliteToday) {
Chris@909 1171 cell.className += " selected";
Chris@909 1172 this.currentDateEl = cell;
Chris@909 1173 }
Chris@909 1174 if (date.getFullYear() == TY &&
Chris@909 1175 date.getMonth() == TM &&
Chris@909 1176 iday == TD) {
Chris@909 1177 cell.className += " today";
Chris@909 1178 cell.ttip += Calendar._TT["PART_TODAY"];
Chris@909 1179 }
Chris@909 1180 if (weekend.indexOf(wday.toString()) != -1)
Chris@909 1181 cell.className += cell.otherMonth ? " oweekend" : " weekend";
Chris@909 1182 }
Chris@909 1183 }
Chris@909 1184 if (!(hasdays || this.showsOtherMonths))
Chris@909 1185 row.className = "emptyrow";
Chris@909 1186 }
Chris@909 1187 this.title.innerHTML = Calendar._MN[month] + ", " + year;
Chris@909 1188 this.onSetTime();
Chris@909 1189 this.table.style.visibility = "visible";
Chris@909 1190 this._initMultipleDates();
Chris@909 1191 // PROFILE
Chris@909 1192 // this.tooltips.innerHTML = "Generated in " + ((new Date()) - today) + " ms";
Chris@909 1193 };
Chris@909 1194
Chris@909 1195 Calendar.prototype._initMultipleDates = function() {
Chris@909 1196 if (this.multiple) {
Chris@909 1197 for (var i in this.multiple) {
Chris@909 1198 var cell = this.datesCells[i];
Chris@909 1199 var d = this.multiple[i];
Chris@909 1200 if (!d)
Chris@909 1201 continue;
Chris@909 1202 if (cell)
Chris@909 1203 cell.className += " selected";
Chris@909 1204 }
Chris@909 1205 }
Chris@909 1206 };
Chris@909 1207
Chris@909 1208 Calendar.prototype._toggleMultipleDate = function(date) {
Chris@909 1209 if (this.multiple) {
Chris@909 1210 var ds = date.print("%Y%m%d");
Chris@909 1211 var cell = this.datesCells[ds];
Chris@909 1212 if (cell) {
Chris@909 1213 var d = this.multiple[ds];
Chris@909 1214 if (!d) {
Chris@909 1215 Calendar.addClass(cell, "selected");
Chris@909 1216 this.multiple[ds] = date;
Chris@909 1217 } else {
Chris@909 1218 Calendar.removeClass(cell, "selected");
Chris@909 1219 delete this.multiple[ds];
Chris@909 1220 }
Chris@909 1221 }
Chris@909 1222 }
Chris@909 1223 };
Chris@909 1224
Chris@909 1225 Calendar.prototype.setDateToolTipHandler = function (unaryFunction) {
Chris@909 1226 this.getDateToolTip = unaryFunction;
Chris@909 1227 };
Chris@909 1228
Chris@909 1229 /**
Chris@909 1230 * Calls _init function above for going to a certain date (but only if the
Chris@909 1231 * date is different than the currently selected one).
Chris@909 1232 */
Chris@909 1233 Calendar.prototype.setDate = function (date) {
Chris@909 1234 if (!date.equalsTo(this.date)) {
Chris@909 1235 this._init(this.firstDayOfWeek, date);
Chris@909 1236 }
Chris@909 1237 };
Chris@909 1238
Chris@909 1239 /**
Chris@909 1240 * Refreshes the calendar. Useful if the "disabledHandler" function is
Chris@909 1241 * dynamic, meaning that the list of disabled date can change at runtime.
Chris@909 1242 * Just * call this function if you think that the list of disabled dates
Chris@909 1243 * should * change.
Chris@909 1244 */
Chris@909 1245 Calendar.prototype.refresh = function () {
Chris@909 1246 this._init(this.firstDayOfWeek, this.date);
Chris@909 1247 };
Chris@909 1248
Chris@909 1249 /** Modifies the "firstDayOfWeek" parameter (pass 0 for Synday, 1 for Monday, etc.). */
Chris@909 1250 Calendar.prototype.setFirstDayOfWeek = function (firstDayOfWeek) {
Chris@909 1251 this._init(firstDayOfWeek, this.date);
Chris@909 1252 this._displayWeekdays();
Chris@909 1253 };
Chris@909 1254
Chris@909 1255 /**
Chris@909 1256 * Allows customization of what dates are enabled. The "unaryFunction"
Chris@909 1257 * parameter must be a function object that receives the date (as a JS Date
Chris@909 1258 * object) and returns a boolean value. If the returned value is true then
Chris@909 1259 * the passed date will be marked as disabled.
Chris@909 1260 */
Chris@909 1261 Calendar.prototype.setDateStatusHandler = Calendar.prototype.setDisabledHandler = function (unaryFunction) {
Chris@909 1262 this.getDateStatus = unaryFunction;
Chris@909 1263 };
Chris@909 1264
Chris@909 1265 /** Customization of allowed year range for the calendar. */
Chris@909 1266 Calendar.prototype.setRange = function (a, z) {
Chris@909 1267 this.minYear = a;
Chris@909 1268 this.maxYear = z;
Chris@909 1269 };
Chris@909 1270
Chris@909 1271 /** Calls the first user handler (selectedHandler). */
Chris@909 1272 Calendar.prototype.callHandler = function () {
Chris@909 1273 if (this.onSelected) {
Chris@909 1274 this.onSelected(this, this.date.print(this.dateFormat));
Chris@909 1275 }
Chris@909 1276 };
Chris@909 1277
Chris@909 1278 /** Calls the second user handler (closeHandler). */
Chris@909 1279 Calendar.prototype.callCloseHandler = function () {
Chris@909 1280 if (this.onClose) {
Chris@909 1281 this.onClose(this);
Chris@909 1282 }
Chris@909 1283 this.hideShowCovered();
Chris@909 1284 };
Chris@909 1285
Chris@909 1286 /** Removes the calendar object from the DOM tree and destroys it. */
Chris@909 1287 Calendar.prototype.destroy = function () {
Chris@909 1288 var el = this.element.parentNode;
Chris@909 1289 el.removeChild(this.element);
Chris@909 1290 Calendar._C = null;
Chris@909 1291 window._dynarch_popupCalendar = null;
Chris@909 1292 };
Chris@909 1293
Chris@909 1294 /**
Chris@909 1295 * Moves the calendar element to a different section in the DOM tree (changes
Chris@909 1296 * its parent).
Chris@909 1297 */
Chris@909 1298 Calendar.prototype.reparent = function (new_parent) {
Chris@909 1299 var el = this.element;
Chris@909 1300 el.parentNode.removeChild(el);
Chris@909 1301 new_parent.appendChild(el);
Chris@909 1302 };
Chris@909 1303
Chris@909 1304 // This gets called when the user presses a mouse button anywhere in the
Chris@909 1305 // document, if the calendar is shown. If the click was outside the open
Chris@909 1306 // calendar this function closes it.
Chris@909 1307 Calendar._checkCalendar = function(ev) {
Chris@909 1308 var calendar = window._dynarch_popupCalendar;
Chris@909 1309 if (!calendar) {
Chris@909 1310 return false;
Chris@909 1311 }
Chris@909 1312 var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
Chris@909 1313 for (; el != null && el != calendar.element; el = el.parentNode);
Chris@909 1314 if (el == null) {
Chris@909 1315 // calls closeHandler which should hide the calendar.
Chris@909 1316 window._dynarch_popupCalendar.callCloseHandler();
Chris@909 1317 return Calendar.stopEvent(ev);
Chris@909 1318 }
Chris@909 1319 };
Chris@909 1320
Chris@909 1321 /** Shows the calendar. */
Chris@909 1322 Calendar.prototype.show = function () {
Chris@909 1323 var rows = this.table.getElementsByTagName("tr");
Chris@909 1324 for (var i = rows.length; i > 0;) {
Chris@909 1325 var row = rows[--i];
Chris@909 1326 Calendar.removeClass(row, "rowhilite");
Chris@909 1327 var cells = row.getElementsByTagName("td");
Chris@909 1328 for (var j = cells.length; j > 0;) {
Chris@909 1329 var cell = cells[--j];
Chris@909 1330 Calendar.removeClass(cell, "hilite");
Chris@909 1331 Calendar.removeClass(cell, "active");
Chris@909 1332 }
Chris@909 1333 }
Chris@909 1334 this.element.style.display = "block";
Chris@909 1335 this.hidden = false;
Chris@909 1336 if (this.isPopup) {
Chris@909 1337 window._dynarch_popupCalendar = this;
Chris@909 1338 Calendar.addEvent(document, "keydown", Calendar._keyEvent);
Chris@909 1339 Calendar.addEvent(document, "keypress", Calendar._keyEvent);
Chris@909 1340 Calendar.addEvent(document, "mousedown", Calendar._checkCalendar);
Chris@909 1341 }
Chris@909 1342 this.hideShowCovered();
Chris@909 1343 };
Chris@909 1344
Chris@909 1345 /**
Chris@909 1346 * Hides the calendar. Also removes any "hilite" from the class of any TD
Chris@909 1347 * element.
Chris@909 1348 */
Chris@909 1349 Calendar.prototype.hide = function () {
Chris@909 1350 if (this.isPopup) {
Chris@909 1351 Calendar.removeEvent(document, "keydown", Calendar._keyEvent);
Chris@909 1352 Calendar.removeEvent(document, "keypress", Calendar._keyEvent);
Chris@909 1353 Calendar.removeEvent(document, "mousedown", Calendar._checkCalendar);
Chris@909 1354 }
Chris@909 1355 this.element.style.display = "none";
Chris@909 1356 this.hidden = true;
Chris@909 1357 this.hideShowCovered();
Chris@909 1358 };
Chris@909 1359
Chris@909 1360 /**
Chris@909 1361 * Shows the calendar at a given absolute position (beware that, depending on
Chris@909 1362 * the calendar element style -- position property -- this might be relative
Chris@909 1363 * to the parent's containing rectangle).
Chris@909 1364 */
Chris@909 1365 Calendar.prototype.showAt = function (x, y) {
Chris@909 1366 var s = this.element.style;
Chris@909 1367 s.left = x + "px";
Chris@909 1368 s.top = y + "px";
Chris@909 1369 this.show();
Chris@909 1370 };
Chris@909 1371
Chris@909 1372 /** Shows the calendar near a given element. */
Chris@909 1373 Calendar.prototype.showAtElement = function (el, opts) {
Chris@909 1374 var self = this;
Chris@909 1375 var p = Calendar.getAbsolutePos(el);
Chris@909 1376 if (!opts || typeof opts != "string") {
Chris@909 1377 this.showAt(p.x, p.y + el.offsetHeight);
Chris@909 1378 return true;
Chris@909 1379 }
Chris@909 1380 function fixPosition(box) {
Chris@909 1381 if (box.x < 0)
Chris@909 1382 box.x = 0;
Chris@909 1383 if (box.y < 0)
Chris@909 1384 box.y = 0;
Chris@909 1385 var cp = document.createElement("div");
Chris@909 1386 var s = cp.style;
Chris@909 1387 s.position = "absolute";
Chris@909 1388 s.right = s.bottom = s.width = s.height = "0px";
Chris@909 1389 document.body.appendChild(cp);
Chris@909 1390 var br = Calendar.getAbsolutePos(cp);
Chris@909 1391 document.body.removeChild(cp);
Chris@909 1392 if (Calendar.is_ie) {
Chris@909 1393 br.y += document.body.scrollTop;
Chris@909 1394 br.x += document.body.scrollLeft;
Chris@909 1395 } else {
Chris@909 1396 br.y += window.scrollY;
Chris@909 1397 br.x += window.scrollX;
Chris@909 1398 }
Chris@909 1399 var tmp = box.x + box.width - br.x;
Chris@909 1400 if (tmp > 0) box.x -= tmp;
Chris@909 1401 tmp = box.y + box.height - br.y;
Chris@909 1402 if (tmp > 0) box.y -= tmp;
Chris@909 1403 };
Chris@909 1404 this.element.style.display = "block";
Chris@909 1405 Calendar.continuation_for_the_fucking_khtml_browser = function() {
Chris@909 1406 var w = self.element.offsetWidth;
Chris@909 1407 var h = self.element.offsetHeight;
Chris@909 1408 self.element.style.display = "none";
Chris@909 1409 var valign = opts.substr(0, 1);
Chris@909 1410 var halign = "l";
Chris@909 1411 if (opts.length > 1) {
Chris@909 1412 halign = opts.substr(1, 1);
Chris@909 1413 }
Chris@909 1414 // vertical alignment
Chris@909 1415 switch (valign) {
Chris@909 1416 case "T": p.y -= h; break;
Chris@909 1417 case "B": p.y += el.offsetHeight; break;
Chris@909 1418 case "C": p.y += (el.offsetHeight - h) / 2; break;
Chris@909 1419 case "t": p.y += el.offsetHeight - h; break;
Chris@909 1420 case "b": break; // already there
Chris@909 1421 }
Chris@909 1422 // horizontal alignment
Chris@909 1423 switch (halign) {
Chris@909 1424 case "L": p.x -= w; break;
Chris@909 1425 case "R": p.x += el.offsetWidth; break;
Chris@909 1426 case "C": p.x += (el.offsetWidth - w) / 2; break;
Chris@909 1427 case "l": p.x += el.offsetWidth - w; break;
Chris@909 1428 case "r": break; // already there
Chris@909 1429 }
Chris@909 1430 p.width = w;
Chris@909 1431 p.height = h + 40;
Chris@909 1432 self.monthsCombo.style.display = "none";
Chris@909 1433 fixPosition(p);
Chris@909 1434 self.showAt(p.x, p.y);
Chris@909 1435 };
Chris@909 1436 if (Calendar.is_khtml)
Chris@909 1437 setTimeout("Calendar.continuation_for_the_fucking_khtml_browser()", 10);
Chris@909 1438 else
Chris@909 1439 Calendar.continuation_for_the_fucking_khtml_browser();
Chris@909 1440 };
Chris@909 1441
Chris@909 1442 /** Customizes the date format. */
Chris@909 1443 Calendar.prototype.setDateFormat = function (str) {
Chris@909 1444 this.dateFormat = str;
Chris@909 1445 };
Chris@909 1446
Chris@909 1447 /** Customizes the tooltip date format. */
Chris@909 1448 Calendar.prototype.setTtDateFormat = function (str) {
Chris@909 1449 this.ttDateFormat = str;
Chris@909 1450 };
Chris@909 1451
Chris@909 1452 /**
Chris@909 1453 * Tries to identify the date represented in a string. If successful it also
Chris@909 1454 * calls this.setDate which moves the calendar to the given date.
Chris@909 1455 */
Chris@909 1456 Calendar.prototype.parseDate = function(str, fmt) {
Chris@909 1457 if (!fmt)
Chris@909 1458 fmt = this.dateFormat;
Chris@909 1459 this.setDate(Date.parseDate(str, fmt));
Chris@909 1460 };
Chris@909 1461
Chris@909 1462 Calendar.prototype.hideShowCovered = function () {
Chris@909 1463 if (!Calendar.is_ie && !Calendar.is_opera)
Chris@909 1464 return;
Chris@909 1465 function getVisib(obj){
Chris@909 1466 var value = obj.style.visibility;
Chris@909 1467 if (!value) {
Chris@909 1468 if (document.defaultView && typeof (document.defaultView.getComputedStyle) == "function") { // Gecko, W3C
Chris@909 1469 if (!Calendar.is_khtml)
Chris@909 1470 value = document.defaultView.
Chris@909 1471 getComputedStyle(obj, "").getPropertyValue("visibility");
Chris@909 1472 else
Chris@909 1473 value = '';
Chris@909 1474 } else if (obj.currentStyle) { // IE
Chris@909 1475 value = obj.currentStyle.visibility;
Chris@909 1476 } else
Chris@909 1477 value = '';
Chris@909 1478 }
Chris@909 1479 return value;
Chris@909 1480 };
Chris@909 1481
Chris@909 1482 var tags = new Array("applet", "iframe", "select");
Chris@909 1483 var el = this.element;
Chris@909 1484
Chris@909 1485 var p = Calendar.getAbsolutePos(el);
Chris@909 1486 var EX1 = p.x;
Chris@909 1487 var EX2 = el.offsetWidth + EX1;
Chris@909 1488 var EY1 = p.y;
Chris@909 1489 var EY2 = el.offsetHeight + EY1;
Chris@909 1490
Chris@909 1491 for (var k = tags.length; k > 0; ) {
Chris@909 1492 var ar = document.getElementsByTagName(tags[--k]);
Chris@909 1493 var cc = null;
Chris@909 1494
Chris@909 1495 for (var i = ar.length; i > 0;) {
Chris@909 1496 cc = ar[--i];
Chris@909 1497
Chris@909 1498 p = Calendar.getAbsolutePos(cc);
Chris@909 1499 var CX1 = p.x;
Chris@909 1500 var CX2 = cc.offsetWidth + CX1;
Chris@909 1501 var CY1 = p.y;
Chris@909 1502 var CY2 = cc.offsetHeight + CY1;
Chris@909 1503
Chris@909 1504 if (this.hidden || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) {
Chris@909 1505 if (!cc.__msh_save_visibility) {
Chris@909 1506 cc.__msh_save_visibility = getVisib(cc);
Chris@909 1507 }
Chris@909 1508 cc.style.visibility = cc.__msh_save_visibility;
Chris@909 1509 } else {
Chris@909 1510 if (!cc.__msh_save_visibility) {
Chris@909 1511 cc.__msh_save_visibility = getVisib(cc);
Chris@909 1512 }
Chris@909 1513 cc.style.visibility = "hidden";
Chris@909 1514 }
Chris@909 1515 }
Chris@909 1516 }
Chris@909 1517 };
Chris@909 1518
Chris@909 1519 /** Internal function; it displays the bar with the names of the weekday. */
Chris@909 1520 Calendar.prototype._displayWeekdays = function () {
Chris@909 1521 var fdow = this.firstDayOfWeek;
Chris@909 1522 var cell = this.firstdayname;
Chris@909 1523 var weekend = Calendar._TT["WEEKEND"];
Chris@909 1524 for (var i = 0; i < 7; ++i) {
Chris@909 1525 cell.className = "day name";
Chris@909 1526 var realday = (i + fdow) % 7;
Chris@909 1527 if (i) {
Chris@909 1528 cell.ttip = Calendar._TT["DAY_FIRST"].replace("%s", Calendar._DN[realday]);
Chris@909 1529 cell.navtype = 100;
Chris@909 1530 cell.calendar = this;
Chris@909 1531 cell.fdow = realday;
Chris@909 1532 Calendar._add_evs(cell);
Chris@909 1533 }
Chris@909 1534 if (weekend.indexOf(realday.toString()) != -1) {
Chris@909 1535 Calendar.addClass(cell, "weekend");
Chris@909 1536 }
Chris@909 1537 cell.innerHTML = Calendar._SDN[(i + fdow) % 7];
Chris@909 1538 cell = cell.nextSibling;
Chris@909 1539 }
Chris@909 1540 };
Chris@909 1541
Chris@909 1542 /** Internal function. Hides all combo boxes that might be displayed. */
Chris@909 1543 Calendar.prototype._hideCombos = function () {
Chris@909 1544 this.monthsCombo.style.display = "none";
Chris@909 1545 this.yearsCombo.style.display = "none";
Chris@909 1546 };
Chris@909 1547
Chris@909 1548 /** Internal function. Starts dragging the element. */
Chris@909 1549 Calendar.prototype._dragStart = function (ev) {
Chris@909 1550 if (this.dragging) {
Chris@909 1551 return;
Chris@909 1552 }
Chris@909 1553 this.dragging = true;
Chris@909 1554 var posX;
Chris@909 1555 var posY;
Chris@909 1556 if (Calendar.is_ie) {
Chris@909 1557 posY = window.event.clientY + document.body.scrollTop;
Chris@909 1558 posX = window.event.clientX + document.body.scrollLeft;
Chris@909 1559 } else {
Chris@909 1560 posY = ev.clientY + window.scrollY;
Chris@909 1561 posX = ev.clientX + window.scrollX;
Chris@909 1562 }
Chris@909 1563 var st = this.element.style;
Chris@909 1564 this.xOffs = posX - parseInt(st.left);
Chris@909 1565 this.yOffs = posY - parseInt(st.top);
Chris@909 1566 with (Calendar) {
Chris@909 1567 addEvent(document, "mousemove", calDragIt);
Chris@909 1568 addEvent(document, "mouseup", calDragEnd);
Chris@909 1569 }
Chris@909 1570 };
Chris@909 1571
Chris@909 1572 // BEGIN: DATE OBJECT PATCHES
Chris@909 1573
Chris@909 1574 /** Adds the number of days array to the Date object. */
Chris@909 1575 Date._MD = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
Chris@909 1576
Chris@909 1577 /** Constants used for time computations */
Chris@909 1578 Date.SECOND = 1000 /* milliseconds */;
Chris@909 1579 Date.MINUTE = 60 * Date.SECOND;
Chris@909 1580 Date.HOUR = 60 * Date.MINUTE;
Chris@909 1581 Date.DAY = 24 * Date.HOUR;
Chris@909 1582 Date.WEEK = 7 * Date.DAY;
Chris@909 1583
Chris@909 1584 Date.parseDate = function(str, fmt) {
Chris@909 1585 var today = new Date();
Chris@909 1586 var y = 0;
Chris@909 1587 var m = -1;
Chris@909 1588 var d = 0;
Chris@909 1589 var a = str.split(/\W+/);
Chris@909 1590 var b = fmt.match(/%./g);
Chris@909 1591 var i = 0, j = 0;
Chris@909 1592 var hr = 0;
Chris@909 1593 var min = 0;
Chris@909 1594 for (i = 0; i < a.length; ++i) {
Chris@909 1595 if (!a[i])
Chris@909 1596 continue;
Chris@909 1597 switch (b[i]) {
Chris@909 1598 case "%d":
Chris@909 1599 case "%e":
Chris@909 1600 d = parseInt(a[i], 10);
Chris@909 1601 break;
Chris@909 1602
Chris@909 1603 case "%m":
Chris@909 1604 m = parseInt(a[i], 10) - 1;
Chris@909 1605 break;
Chris@909 1606
Chris@909 1607 case "%Y":
Chris@909 1608 case "%y":
Chris@909 1609 y = parseInt(a[i], 10);
Chris@909 1610 (y < 100) && (y += (y > 29) ? 1900 : 2000);
Chris@909 1611 break;
Chris@909 1612
Chris@909 1613 case "%b":
Chris@909 1614 case "%B":
Chris@909 1615 for (j = 0; j < 12; ++j) {
Chris@909 1616 if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
Chris@909 1617 }
Chris@909 1618 break;
Chris@909 1619
Chris@909 1620 case "%H":
Chris@909 1621 case "%I":
Chris@909 1622 case "%k":
Chris@909 1623 case "%l":
Chris@909 1624 hr = parseInt(a[i], 10);
Chris@909 1625 break;
Chris@909 1626
Chris@909 1627 case "%P":
Chris@909 1628 case "%p":
Chris@909 1629 if (/pm/i.test(a[i]) && hr < 12)
Chris@909 1630 hr += 12;
Chris@909 1631 else if (/am/i.test(a[i]) && hr >= 12)
Chris@909 1632 hr -= 12;
Chris@909 1633 break;
Chris@909 1634
Chris@909 1635 case "%M":
Chris@909 1636 min = parseInt(a[i], 10);
Chris@909 1637 break;
Chris@909 1638 }
Chris@909 1639 }
Chris@909 1640 if (isNaN(y)) y = today.getFullYear();
Chris@909 1641 if (isNaN(m)) m = today.getMonth();
Chris@909 1642 if (isNaN(d)) d = today.getDate();
Chris@909 1643 if (isNaN(hr)) hr = today.getHours();
Chris@909 1644 if (isNaN(min)) min = today.getMinutes();
Chris@909 1645 if (y != 0 && m != -1 && d != 0)
Chris@909 1646 return new Date(y, m, d, hr, min, 0);
Chris@909 1647 y = 0; m = -1; d = 0;
Chris@909 1648 for (i = 0; i < a.length; ++i) {
Chris@909 1649 if (a[i].search(/[a-zA-Z]+/) != -1) {
Chris@909 1650 var t = -1;
Chris@909 1651 for (j = 0; j < 12; ++j) {
Chris@909 1652 if (Calendar._MN[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
Chris@909 1653 }
Chris@909 1654 if (t != -1) {
Chris@909 1655 if (m != -1) {
Chris@909 1656 d = m+1;
Chris@909 1657 }
Chris@909 1658 m = t;
Chris@909 1659 }
Chris@909 1660 } else if (parseInt(a[i], 10) <= 12 && m == -1) {
Chris@909 1661 m = a[i]-1;
Chris@909 1662 } else if (parseInt(a[i], 10) > 31 && y == 0) {
Chris@909 1663 y = parseInt(a[i], 10);
Chris@909 1664 (y < 100) && (y += (y > 29) ? 1900 : 2000);
Chris@909 1665 } else if (d == 0) {
Chris@909 1666 d = a[i];
Chris@909 1667 }
Chris@909 1668 }
Chris@909 1669 if (y == 0)
Chris@909 1670 y = today.getFullYear();
Chris@909 1671 if (m != -1 && d != 0)
Chris@909 1672 return new Date(y, m, d, hr, min, 0);
Chris@909 1673 return today;
Chris@909 1674 };
Chris@909 1675
Chris@909 1676 /** Returns the number of days in the current month */
Chris@909 1677 Date.prototype.getMonthDays = function(month) {
Chris@909 1678 var year = this.getFullYear();
Chris@909 1679 if (typeof month == "undefined") {
Chris@909 1680 month = this.getMonth();
Chris@909 1681 }
Chris@909 1682 if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
Chris@909 1683 return 29;
Chris@909 1684 } else {
Chris@909 1685 return Date._MD[month];
Chris@909 1686 }
Chris@909 1687 };
Chris@909 1688
Chris@909 1689 /** Returns the number of day in the year. */
Chris@909 1690 Date.prototype.getDayOfYear = function() {
Chris@909 1691 var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
Chris@909 1692 var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
Chris@909 1693 var time = now - then;
Chris@909 1694 return Math.floor(time / Date.DAY);
Chris@909 1695 };
Chris@909 1696
Chris@909 1697 /** Returns the number of the week in year, as defined in ISO 8601.
Chris@909 1698 This function is only correct if `this` is the first day of the week. */
Chris@909 1699 Date.prototype.getWeekNumber = function() {
Chris@909 1700 var d = new Date(this.getFullYear(), this.getMonth(), this.getDate());
Chris@909 1701 var days = 1000*60*60*24; // one day in milliseconds
Chris@909 1702
Chris@909 1703 // get the thursday of the current week
Chris@909 1704 var this_thursday = new Date(
Chris@909 1705 d.valueOf() // selected date
Chris@909 1706 - (d.getDay() % 7)*days // previous sunday
Chris@909 1707 + 4*days // + 4 days
Chris@909 1708 ).valueOf();
Chris@909 1709
Chris@909 1710 // the thursday in the first week of the year
Chris@909 1711 var first_thursday = new Date(
Chris@909 1712 new Date(this.getFullYear(), 0, 4).valueOf() // January 4 is in the first week by definition
Chris@909 1713 - (d.getDay() % 7)*days // previous sunday
Chris@909 1714 + 4*days // + 4 days
Chris@909 1715 ).valueOf();
Chris@909 1716
Chris@909 1717 return Math.round((this_thursday - first_thursday) / (7*days)) + 1;
Chris@909 1718 };
Chris@909 1719
Chris@909 1720 /** Checks date and time equality */
Chris@909 1721 Date.prototype.equalsTo = function(date) {
Chris@909 1722 return ((this.getFullYear() == date.getFullYear()) &&
Chris@909 1723 (this.getMonth() == date.getMonth()) &&
Chris@909 1724 (this.getDate() == date.getDate()) &&
Chris@909 1725 (this.getHours() == date.getHours()) &&
Chris@909 1726 (this.getMinutes() == date.getMinutes()));
Chris@909 1727 };
Chris@909 1728
Chris@909 1729 /** Set only the year, month, date parts (keep existing time) */
Chris@909 1730 Date.prototype.setDateOnly = function(date) {
Chris@909 1731 var tmp = new Date(date);
Chris@909 1732 this.setDate(1);
Chris@909 1733 this.setFullYear(tmp.getFullYear());
Chris@909 1734 this.setMonth(tmp.getMonth());
Chris@909 1735 this.setDate(tmp.getDate());
Chris@909 1736 };
Chris@909 1737
Chris@909 1738 /** Prints the date in a string according to the given format. */
Chris@909 1739 Date.prototype.print = function (str) {
Chris@909 1740 var m = this.getMonth();
Chris@909 1741 var d = this.getDate();
Chris@909 1742 var y = this.getFullYear();
Chris@909 1743 var wn = this.getWeekNumber();
Chris@909 1744 var w = this.getDay();
Chris@909 1745 var s = {};
Chris@909 1746 var hr = this.getHours();
Chris@909 1747 var pm = (hr >= 12);
Chris@909 1748 var ir = (pm) ? (hr - 12) : hr;
Chris@909 1749 var dy = this.getDayOfYear();
Chris@909 1750 if (ir == 0)
Chris@909 1751 ir = 12;
Chris@909 1752 var min = this.getMinutes();
Chris@909 1753 var sec = this.getSeconds();
Chris@909 1754 s["%a"] = Calendar._SDN[w]; // abbreviated weekday name [FIXME: I18N]
Chris@909 1755 s["%A"] = Calendar._DN[w]; // full weekday name
Chris@909 1756 s["%b"] = Calendar._SMN[m]; // abbreviated month name [FIXME: I18N]
Chris@909 1757 s["%B"] = Calendar._MN[m]; // full month name
Chris@909 1758 // FIXME: %c : preferred date and time representation for the current locale
Chris@909 1759 s["%C"] = 1 + Math.floor(y / 100); // the century number
Chris@909 1760 s["%d"] = (d < 10) ? ("0" + d) : d; // the day of the month (range 01 to 31)
Chris@909 1761 s["%e"] = d; // the day of the month (range 1 to 31)
Chris@909 1762 // FIXME: %D : american date style: %m/%d/%y
Chris@909 1763 // FIXME: %E, %F, %G, %g, %h (man strftime)
Chris@909 1764 s["%H"] = (hr < 10) ? ("0" + hr) : hr; // hour, range 00 to 23 (24h format)
Chris@909 1765 s["%I"] = (ir < 10) ? ("0" + ir) : ir; // hour, range 01 to 12 (12h format)
Chris@909 1766 s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy; // day of the year (range 001 to 366)
Chris@909 1767 s["%k"] = hr; // hour, range 0 to 23 (24h format)
Chris@909 1768 s["%l"] = ir; // hour, range 1 to 12 (12h format)
Chris@909 1769 s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m); // month, range 01 to 12
Chris@909 1770 s["%M"] = (min < 10) ? ("0" + min) : min; // minute, range 00 to 59
Chris@909 1771 s["%n"] = "\n"; // a newline character
Chris@909 1772 s["%p"] = pm ? "PM" : "AM";
Chris@909 1773 s["%P"] = pm ? "pm" : "am";
Chris@909 1774 // FIXME: %r : the time in am/pm notation %I:%M:%S %p
Chris@909 1775 // FIXME: %R : the time in 24-hour notation %H:%M
Chris@909 1776 s["%s"] = Math.floor(this.getTime() / 1000);
Chris@909 1777 s["%S"] = (sec < 10) ? ("0" + sec) : sec; // seconds, range 00 to 59
Chris@909 1778 s["%t"] = "\t"; // a tab character
Chris@909 1779 // FIXME: %T : the time in 24-hour notation (%H:%M:%S)
Chris@909 1780 s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
Chris@909 1781 s["%u"] = w + 1; // the day of the week (range 1 to 7, 1 = MON)
Chris@909 1782 s["%w"] = w; // the day of the week (range 0 to 6, 0 = SUN)
Chris@909 1783 // FIXME: %x : preferred date representation for the current locale without the time
Chris@909 1784 // FIXME: %X : preferred time representation for the current locale without the date
Chris@909 1785 s["%y"] = ('' + y).substr(2, 2); // year without the century (range 00 to 99)
Chris@909 1786 s["%Y"] = y; // year with the century
Chris@909 1787 s["%%"] = "%"; // a literal '%' character
Chris@909 1788
Chris@909 1789 var re = /%./g;
Chris@909 1790 if (!Calendar.is_ie5 && !Calendar.is_khtml)
Chris@909 1791 return str.replace(re, function (par) { return s[par] || par; });
Chris@909 1792
Chris@909 1793 var a = str.match(re);
Chris@909 1794 for (var i = 0; i < a.length; i++) {
Chris@909 1795 var tmp = s[a[i]];
Chris@909 1796 if (tmp) {
Chris@909 1797 re = new RegExp(a[i], 'g');
Chris@909 1798 str = str.replace(re, tmp);
Chris@909 1799 }
Chris@909 1800 }
Chris@909 1801
Chris@909 1802 return str;
Chris@909 1803 };
Chris@909 1804
Chris@909 1805 Date.prototype.__msh_oldSetFullYear = Date.prototype.setFullYear;
Chris@909 1806 Date.prototype.setFullYear = function(y) {
Chris@909 1807 var d = new Date(this);
Chris@909 1808 d.__msh_oldSetFullYear(y);
Chris@909 1809 if (d.getMonth() != this.getMonth())
Chris@909 1810 this.setDate(28);
Chris@909 1811 this.__msh_oldSetFullYear(y);
Chris@909 1812 };
Chris@909 1813
Chris@909 1814 // END: DATE OBJECT PATCHES
Chris@909 1815
Chris@909 1816
Chris@909 1817 // global object that remembers the calendar
Chris@909 1818 window._dynarch_popupCalendar = null;