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