source: trunk/FACT++/www/shift/calendar.js@ 15369

Last change on this file since 15369 was 15155, checked in by tbretz, 12 years ago
Implemented a new 'user' which can be used to add entries for debugging to be able to seperate them from normal shift entries.
File size: 28.7 KB
Line 
1/**********************************************************************
2* Calendar JavaScript [DOM] v3.11 by Michael Loesler *
3************************************************************************
4* Copyright (C) 2005-09 by Michael Loesler, http//derletztekick.com *
5* *
6* *
7* This program is free software; you can redistribute it and/or modify *
8* it under the terms of the GNU General Public License as published by *
9* the Free Software Foundation; either version 3 of the License, or *
10* (at your option) any later version. *
11* *
12* This program is distributed in the hope that it will be useful, *
13* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15* GNU General Public License for more details. *
16* *
17* You should have received a copy of the GNU General Public License *
18* along with this program; if not, see <http://www.gnu.org/licenses/> *
19* or write to the *
20* Free Software Foundation, Inc., *
21* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22* *
23 **********************************************************************/
24/*
25function logout()
26{
27 var xmlHttp = new XMLHttpRequest();
28 xmlHttp.open('POST', "calendar.php?logout=1", true);
29 xmlHttp.onload = function ()
30 {
31 if (xmlHttp.status!=200)
32 {
33 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
34 return;
35 }
36
37 alert("Logout successful!");
38 };
39
40 xmlHttp.send();
41}
42*/
43function resize()
44{
45 var table = document.getElementById("table");
46
47 var W = window.innerWidth;
48 var H = window.innerHeight;
49
50 table.style.width =W+"px";
51 table.style.height=H+"px";
52}
53
54var institutes= ["Shift", "Debug", "EPFL", "ETHZ", "ISDC", "UNIDO", "UNIGE", "UNIWUE" ];
55
56function CalendarJS()
57{
58 this.now = new Date();
59 this.dayname = ["Mo","Tu","We","Th","Fr","Sa","So"];
60 this.monthname = ["January","February","March","April","May","June","July","August","September","October","November","December"];
61 this.tooltip = ["previous month","next month","current date","last year","next year"];
62 this.monthCell = document.createElement("th");
63 this.tableHead = null;
64 this.tableFoot = null;
65 this.parEl = null;
66
67 this.init = function( id, initDate )
68 {
69 this.now = initDate ? initDate : new Date();
70 this.date = this.now.getDate();
71 this.month = this.mm = this.now.getMonth();
72 this.year = this.yy = this.now.getFullYear();
73 this.monthCell.appendChild(document.createTextNode( this.monthname[this.mm]+"\u00a0"+this.yy ));
74
75 this.tableHead = this.createTableHead();
76 this.tableFoot = this.createTableFoot();
77
78 this.parEl = document.getElementById( id );
79 this.show();
80
81 if (!initDate)
82 this.checkDate();
83 };
84
85 this.checkDate = function()
86 {
87 var self = this;
88 var today = new Date();
89
90 if (this.date != today.getDate())
91 {
92 this.tableHead = this.createTableHead();
93 this.tableFoot = this.createTableFoot();
94
95 this.date = today.getDate();
96 if (this.mm == this.month && this.yy == this.year)
97 this.switchMonth("current");
98
99 this.month = today.getMonth();
100 if (this.mm == this.month && this.yy == this.year)
101 this.switchMonth("current");
102
103 this.year = today.getFullYear();
104 if (this.mm == this.month && this.yy == this.year)
105 this.switchMonth("current");
106 }
107 window.setTimeout(function() { self.checkDate(); }, Math.abs(new Date(this.year, this.month, this.date, 24, 0, 0)-this.now));
108 },
109
110 this.removeElements = function( Obj )
111 {
112 while( Obj.childNodes.length > 0)
113 Obj.removeChild(Obj.lastChild);
114
115 return Obj;
116 };
117
118 this.show = function()
119 {
120 this.parEl = this.removeElements( this.parEl );
121 this.monthCell.firstChild.replaceData(0, this.monthCell.firstChild.nodeValue.length, this.monthname[this.mm]+"\u00a0"+this.yy);
122
123 var table = document.createElement("table");
124 table.id = "table";
125
126 this.parEl.appendChild( table );
127
128 table.appendChild( this.tableHead );
129 table.appendChild( this.tableFoot );
130
131 table.appendChild( this.createTableBody(window.innerHeight-table.offsetHeight) );
132
133 resize();
134 };
135
136 this.createTableFoot = function()
137 {
138 var tfoot = document.createElement("tfoot");
139
140 var tr = document.createElement("tr");
141 var td = document.createElement("td");
142 td.height = "1%";
143 td.colSpan = 7;
144 td.style.padding="3px 3px";
145 tfoot.appendChild(tr);
146 tr.appendChild(td);
147 var table = document.createElement("table");
148 table.width="100%";
149 td.appendChild(table);
150 tr = document.createElement("tr");
151 table.appendChild(tr);
152 for (var i=0; i<institutes.length; i++)
153 {
154 td = document.createElement("td");
155 td.width=100/institutes.length+"%";
156 td.setAttribute("style", "text-align:center;font-size:1em;border:solid #112A5D 2px;padding:3px 3px;");
157 td.changeUser = this.changeUser;
158 td.onclick = function(e) { this.changeUser(); }
159 td.appendChild(document.createTextNode(institutes[i]));
160 tr.appendChild(td);
161
162 if (i==0)
163 td.style.backgroundColor = "yellow";
164 }
165 document.getElementById("body").setAttribute("data-user", institutes[0]);
166
167
168 tr = document.createElement("tr");
169 td = document.createElement("td");
170 td.colSpan = 7;
171 td.style.paddingLeft = "0px";
172 td.style.paddingTop = "0px";
173 td.height = "1%";
174 var form = document.createElement("form");
175 var input = document.createElement("textarea");
176 input.overflow = "auto";
177 input.wrap = "virtual";
178 input.id = "comment";
179 input.value = "enter comment here";
180 input.style.color = "#888";
181 input.style.width = "100%";
182 input.rows = 5;
183 input.title = "Enter a comment. Click somewhere in the calender to store the comment.";
184 input.onchange = function() { pushComment(); };
185 input.onfocus = function() { if (input.value=="enter comment here" && input.style.color!="black") input.value=""; input.style.color="black"; };
186 input.onblur = function() { input.style.color="#888"; if (input.value=="") input.value="enter comment here"; };
187 form.appendChild(input);
188 td.appendChild( form );
189 tr.appendChild( td );
190 tfoot.appendChild(tr);
191
192 tr = document.createElement("tr");
193
194 var td = document.createElement("td");
195 td.height="1%";
196 td.colSpan=7;
197 tr.appendChild(td);
198
199 var tab = document.createElement("table");
200 var tr2 = document.createElement("tr");
201 tab.width="100%";
202 tab.cellSpacing=0;
203 tab.cellPadding=0;
204 tab.style.borderWidth = 0;
205 tab.style.fontSize = "1.5em";
206 tab.style.marginBottom = "2px";
207 td.appendChild(tab);
208 tab.appendChild(tr2);
209
210 var tm = this.getCell( "td", this.timeTrigger(), "clock" );
211 tm.style.whiteSpace="nowrap";
212 tm.style.paddingLeft = "0px";
213 tm.style.width="33%";
214 tr2.appendChild( tm );
215
216 var self = this;
217 window.setInterval(function() { tm.firstChild.nodeValue = self.timeTrigger(); }, 500);
218
219 var td = document.createElement("td");
220 td.style.width="33%";
221 td.style.textAlign="center";
222 var a = document.createElement("a");
223 a.href = "overview.png";
224 a.style.whiteSpace="nowrap";
225 a.appendChild(document.createTextNode("click here for help"));
226 td.appendChild(a);
227 tr2.appendChild( td );
228
229 td = this.getCell( "td", "logout", "logout");
230 td.style.width="33%";
231 td.onclick = function(e) { logout(); }
232 td.style.paddingRight = "0px";
233 tr2.appendChild( td );
234
235 tfoot.appendChild( tr );
236
237 return tfoot;
238 }
239
240 this.createTableHead = function()
241 {
242 var thead = document.createElement("thead");
243 thead.style.height="1%";
244 var tr = document.createElement("tr");
245 var th = this.getCell( "th", "\u00AB", "prev_month" );
246
247 th.rowSpan = 2;
248 th.Instanz = this;
249 th.onclick = function() { this.Instanz.switchMonth("prev"); };
250 th.title = this.tooltip[0];
251
252 try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
253 tr.appendChild( th );
254
255 this.monthCell.Instanz = this;
256 this.monthCell.rowSpan = 2;
257 this.monthCell.colSpan = 4;
258 this.monthCell.onclick = function() { this.Instanz.switchMonth("current"); };
259 this.monthCell.title = this.tooltip[2];
260
261 try { this.monthCell.style.cursor = "pointer"; } catch(e){ this.monthCell.style.cursor = "hand"; }
262 tr.appendChild( this.monthCell );
263
264 th = this.getCell( "th", "\u00BB", "next_month" );
265 th.rowSpan = 2;
266 th.Instanz = this;
267 th.onclick = function() { this.Instanz.switchMonth("next"); };
268 th.title = this.tooltip[1];
269
270 try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
271 tr.appendChild( th );
272
273 th = this.getCell( "th", "\u02c4", "prev_year" );
274 th.Instanz = this;
275 th.onclick = function() { this.Instanz.switchMonth("prev_year"); };
276 th.title = this.tooltip[3];
277
278 try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
279 tr.appendChild( th );
280
281 thead.appendChild( tr );
282
283 tr = document.createElement("tr");
284 th = this.getCell( "th", "\u02c5", "next_year" );
285 th.Instanz = this;
286 th.onclick = function() { this.Instanz.switchMonth("next_year"); };
287 th.title = this.tooltip[4];
288
289 try { th.style.cursor = "pointer"; } catch(e){ th.style.cursor = "hand"; }
290 tr.appendChild( th );
291
292 thead.appendChild( tr );
293
294 tr = document.createElement('tr');
295 for (var i=0; i<this.dayname.length; i++)
296 {
297 var th = this.getCell("th", this.dayname[i], "weekday" );
298 th.width=100/7+"%";
299 tr.appendChild( th );
300 }
301
302 thead.appendChild( tr );
303
304 return thead;
305 },
306
307 this.createTableBody = function(height)
308 {
309 var dayspermonth = [31,28,31,30,31,30,31,31,30,31,30,31];
310 var sevendaysaweek = 0;
311 var begin = new Date(this.yy, this.mm, 1);
312 var firstday = begin.getDay()-1;
313 if (firstday < 0)
314 firstday = 6;
315 if ((this.yy%4==0) && ((this.yy%100!=0) || (this.yy%400==0)))
316 dayspermonth[1] = 29;
317
318 var tbody = document.createElement("tbody");
319 var tr = document.createElement('tr');
320
321 tbody.height="100%";
322
323 var height="";//"20%";//100/8+"%";
324
325 if (firstday == 0)
326 {
327 for (var i=0; i<this.dayname.length; i++)
328 {
329 var prevMonth = (this.mm == 0)?11:this.mm-1;
330 var td = this.getCell( "td", dayspermonth[prevMonth]-6+i, "last_month" );
331 td.style.height=height;
332 tr.appendChild( td );
333 }
334 tbody.appendChild( tr );
335 tr = document.createElement('tr');
336 }
337
338 for (var i=0; i<firstday; i++, sevendaysaweek++)
339 {
340 var prevMonth = (this.mm == 0)?11:this.mm-1;
341 var td = this.getCell( "td", dayspermonth[prevMonth]-firstday+i+1, "last_month" );
342 td.style.height=height;
343 tr.appendChild( td );
344 }
345
346 for (var i=1; i<=dayspermonth[this.mm]; i++, sevendaysaweek++)
347 {
348 if (this.dayname.length == sevendaysaweek)
349 {
350 tbody.appendChild( tr );
351 tr = document.createElement('tr');
352 sevendaysaweek = 0;
353 }
354
355 var td = null;
356 if (i==this.date && this.mm==this.month && this.yy==this.year && (sevendaysaweek == 5 || sevendaysaweek == 6))
357 td = this.getCell( "td", i, "today weekend" );
358 else
359 if (i==this.date && this.mm==this.month && this.yy==this.year)
360 td = this.getCell( "td", i, "today" );
361 else
362 if (sevendaysaweek == 5 || sevendaysaweek == 6)
363 td = this.getCell( "td", i, "weekend" );
364 else
365 td = this.getCell( "td", i, null);
366
367 td.setDate = this.setDate;
368 td.chooseDate = this.chooseDate;
369 td.dd = i;
370 td.mm = this.mm;
371 td.yy = this.yy;
372 td.id = this.mm+"-"+i;
373 td.title = "Click to select this date.";
374
375 td.style.height=height;
376
377 td.onclick = function(e) {
378 this.chooseDate();
379 };
380
381 var tab = document.createElement("table");
382 tab.width="100%";
383 tab.style.border = 0;
384 tab.style.padding = 0;
385 tab.style.margin = 0;
386 tab.style.fontSize = "1.5em";
387 tab.style.backgroundColor = "transparent";
388 var tr0 = document.createElement("tr");
389 var td0 = document.createElement("td");
390 var td1 = document.createElement("td");
391 td0.style.textAlign = "left";
392 td1.style.textAlign = "right";
393 td1.style.textWeight= "normal";
394 td0.style.color = "lightgray";
395 td0.style.border=0;
396 td1.style.border=0;
397 td0.style.padding=0;
398 td1.style.padding=0;
399 tab.appendChild(tr0);
400 tr0.appendChild(td0);
401 tr0.appendChild(td1);
402 //td0.appendChild(document.createTextNode(txt));
403
404 td1.appendChild(td.firstChild);
405 td.appendChild(tab);
406
407 var IP = this.getMoonPhase(this.yy, this.mm, i);
408 var str = this.getMoonPhaseStr(IP);
409 var phase = 100-Math.abs(IP-0.5)*200;
410 var txt = parseInt(phase+0.5,10)+"%";
411 if (phase>50)
412 td0.style.color = "gray";
413 if (phase<3.4)
414 {
415 txt = "o";
416 td0.style.textWeight = "bolder";
417 td0.style.fontSize = "0.7em";
418 td0.style.color = "darkgreen";
419 }
420 if (phase>96.6)
421 {
422 txt = "&bull;";
423 td0.style.textWeight = "bolder";
424 td0.style.fontSize = "0.8em";
425 td0.style.color = "darkred";
426 }
427 tab.title = str;
428 td0.innerHTML = txt;
429
430 var sp = document.createElement("span");
431 sp.appendChild(document.createTextNode("*"));
432 sp.style.color="darkred";
433 sp.style.display="none";
434 td1.appendChild(sp);
435
436
437 tr.appendChild( td );
438 }
439
440 var daysNextMonth = 1;
441 for (var i=sevendaysaweek; i<this.dayname.length; i++)
442 tr.appendChild( this.getCell( "td", daysNextMonth++, "next_month" ) );
443
444 tbody.appendChild( tr );
445
446 while (tbody.getElementsByTagName("tr").length<6) {
447 tr = document.createElement('tr');
448 for (var i=0; i<this.dayname.length; i++)
449 {
450 var td = this.getCell( "td", daysNextMonth++, "next_month" );
451 td.style.height=height;
452 tr.appendChild( td );
453 }
454 tbody.appendChild( tr );
455 }
456
457 requestAll(this.yy, this.mm);
458 requestAllComments(this.yy, this.mm);
459 if (this.year==this.yy && this.month==this.mm)
460 requestComment(this.year, this.month, this.date);
461 else
462 {
463 var c = document.getElementById("comment");
464 c.color="#888";
465 c.value="enter comment here";
466 }
467
468 return tbody;
469 };
470
471 this.getCalendarWeek = function(j,m,t)
472 {
473 var cwDate = this.now;
474 if (!t)
475 {
476 j = cwDate.getFullYear();
477 m = cwDate.getMonth();
478 t = cwDate.getDate();
479 }
480 cwDate = new Date(j,m,t);
481
482 var doDat = new Date(cwDate.getTime() + (3-((cwDate.getDay()+6) % 7)) * 86400000);
483 cwYear = doDat.getFullYear();
484
485 var doCW = new Date(new Date(cwYear,0,4).getTime() + (3-((new Date(cwYear,0,4).getDay()+6) % 7)) * 86400000);
486 cw = Math.floor(1.5+(doDat.getTime()-doCW.getTime())/86400000/7);
487 return cw;
488 };
489
490 function request(td)
491 {
492 var user = document.getElementById("body").getAttribute("data-user");
493 var uri = "calendar.php?toggle&y="+td.yy+"&m="+td.mm+"&d="+td.dd;
494 if (user!="Shift" && user!="Debug")
495 uri += "&u="+user;
496 else
497 uri += "&x="+(user=="Debug"?1:0);
498
499 var xmlHttp = new XMLHttpRequest();
500 xmlHttp.open('POST', uri, true);
501 xmlHttp.onload = function ()
502 {
503 if (xmlHttp.status!=200)
504 {
505 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
506 return;
507 }
508
509 var lines = xmlHttp.responseText.split('\n');
510 if (lines.length==0)
511 return;
512
513 while (td.childNodes.length>1)
514 td.removeChild(td.lastChild);
515
516 for (var i=0; i<lines.length; i++)
517 {
518 var x = lines[i].split('\t');
519 if (x.length!=3)
520 continue;
521
522 var div = document.createElement("div");
523 div.style.fontWeight="normal";
524 div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
525 td.appendChild(div);
526
527 for (var j=0; j<institutes.length; j++)
528 if (x[1]==institutes[j])
529 {
530 div.className += " institute";
531 break;
532 }
533 }
534
535 if (td.childNodes.length>1)
536 td.className += " enabled";
537 else
538 td.className = td.className.replace(/enabled/g, "");
539 };
540
541 xmlHttp.send();
542 }
543
544 function logout()
545 {
546 var xmlHttp = new XMLHttpRequest();
547 xmlHttp.open('POST', "calendar.php?logout", true);
548 xmlHttp.onload = function ()
549 {
550 if (xmlHttp.status!=401)
551 {
552 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
553 return;
554 }
555
556 alert(xmlHttp.statusText);
557 };
558
559 xmlHttp.send();
560 }
561
562 function pushComment()
563 {
564 var c = document.getElementById("comment");
565
566 var y = c.getAttribute("data-y");
567 var m = c.getAttribute("data-m");
568 var d = c.getAttribute("data-d");
569 var v = c.value;
570
571 var uri = "calendar.php?y="+y+"&m="+m+"&d="+d+"&c="+encodeURIComponent(v);
572
573 var xmlHttp = new XMLHttpRequest();
574 xmlHttp.open('POST', uri, true);
575 xmlHttp.onload = function()
576 {
577 if (xmlHttp.status!=200)
578 {
579 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
580 return;
581 }
582
583 alert("Comment inserted successfully.");
584
585 var td = document.getElementById(m+"-"+d);
586 var sp = td.firstChild.firstChild.lastChild.lastChild;
587 if (v=="")
588 {
589 sp.style.display="none";
590 td.title="Click to select this date.";
591 }
592 else
593 {
594 sp.style.display="";
595 td.title=v;
596 }
597
598 };
599
600 xmlHttp.send();
601 }
602
603 function requestComment(yy, mm, dd)
604 {
605 var c = document.getElementById("comment");
606
607 var y = c.getAttribute("data-y");
608 var m = c.getAttribute("data-m");
609 var d = c.getAttribute("data-d");
610
611 if (y==yy && m==mm && d==dd)
612 return;
613
614 var uri = "calendar.php?comment&y="+yy+"&m="+mm+"&d="+dd;
615 var xmlHttp = new XMLHttpRequest();
616 xmlHttp.open('POST', uri, true);
617 xmlHttp.onload = function ()
618 {
619 if (xmlHttp.status!=200)
620 {
621 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
622 return;
623 }
624
625 var td = document.getElementById(mm+"-"+dd);
626 var sp = td.firstChild.firstChild.lastChild.lastChild;
627
628 if (sp!=undefined)
629 {
630 c.color="#888";
631 if (xmlHttp.responseText=="")
632 {
633 c.value="enter comment here";
634 sp.style.display="none";
635 td.title="";
636 }
637 else
638 {
639 c.value = xmlHttp.responseText;
640 sp.style.display="";
641 td.title=xmlHttp.responseText;
642 }
643 }
644
645 c.setAttribute("data-y", yy);
646 c.setAttribute("data-m", mm);
647 c.setAttribute("data-d", dd);
648 };
649
650 xmlHttp.send();
651 }
652
653 var xmlReqAll = null;
654 function requestAll(yy, mm)
655 {
656 if (xmlReqAll)
657 xmlReqAll.abort();
658
659 var uri = "calendar.php?y="+yy+"&m="+mm;
660
661 xmlReqAll = new XMLHttpRequest();
662 xmlReqAll.open('POST', uri, true);
663 xmlReqAll.onload = function ()
664 {
665 if (xmlReqAll.status!=200)
666 {
667 alert("ERROR - HTTP request: "+xmlReqAll.statusText+" ["+xmlReqAll.status+"]");
668 return;
669 }
670
671 var lines = xmlReqAll.responseText.split('\n');
672 if (lines.length==0)
673 return;
674
675 for (var i=0; i<lines.length; i++)
676 {
677 var x = lines[i].split('\t');
678 if (x.length!=3)
679 continue;
680
681 var td = document.getElementById(mm+"-"+x[0]);
682
683 var div = document.createElement("div");
684 div.style.fontWeight="normal";
685 div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
686 td.appendChild(div);
687
688 for (var j=0; j<institutes.length; j++)
689 if (x[1]==institutes[j])
690 {
691 div.className += " institute";
692 break;
693 }
694
695 td.className += " enabled";
696 }
697 };
698
699 xmlReqAll.send();
700 }
701
702 var xmlReqCom = null;
703 function requestAllComments(yy, mm)
704 {
705 if (xmlReqCom)
706 xmlReqCom.abort();
707
708 var uri = "calendar.php?comment&y="+yy+"&m="+mm;
709 xmlReqCom = new XMLHttpRequest();
710 xmlReqCom.open('POST', uri, true);
711 xmlReqCom.onload = function ()
712 {
713 if (xmlReqCom.status!=200)
714 {
715 alert("ERROR - HTTP request: "+xmlReqCom.statusText+" ["+xmlReqCom.status+"]");
716 return;
717 }
718
719 if (xmlReqCom.responseText<4)
720 return;
721
722 var pos = 6;
723
724 while (pos<xmlReqCom.responseText.length)
725 {
726 var len = parseInt(xmlReqCom.responseText.substr(pos-6, 4), 10);
727 var dd = parseInt(xmlReqCom.responseText.substr(pos-2, 2), 10);
728 var com = xmlReqCom.responseText.substr(pos, len);
729 pos += len+6;
730
731 if (com!="")
732 {
733 var td = document.getElementById(mm+"-"+dd);
734 var sp = td.firstChild.firstChild.lastChild.lastChild;
735 sp.style.display="";
736 td.title=com;
737 }
738 }
739 };
740
741 xmlReqCom.send();
742 }
743
744 this.setDate = function()
745 {
746 request(this);
747 };
748
749 this.changeUser = function()
750 {
751 var sib = this.nextSibling;
752 while (sib)
753 {
754 sib.style.backgroundColor = "";
755 sib = sib.nextSibling;
756 }
757
758 sib = this.previousSibling;
759 while (sib)
760 {
761 sib.style.backgroundColor = "";
762 sib = sib.previousSibling;
763 }
764
765 this.style.backgroundColor = "yellow";
766
767 document.getElementById("body").setAttribute("data-user", this.firstChild.textContent);
768 };
769
770 this.chooseDate = function()
771 {
772 while (document.getElementsByClassName("choosen")[0])
773 {
774 var e = document.getElementsByClassName("choosen")[0];
775 e.title = "Click to select this date.";
776 e.className = e.className.replace(/choosen/g, "");
777 e.onclick = function() {
778 this.chooseDate();
779 };
780 }
781
782 this.className += " choosen";
783 this.title = "Click again to add or remove your name.";
784
785 requestComment(this.yy, this.mm, this.dd);
786
787 this.onclick = function() {
788 this.setDate();
789 };
790 };
791
792 this.timeTrigger = function()
793 {
794 var now = new Date();
795 var ss = (now.getSeconds()<10)?"0"+now.getSeconds():now.getSeconds();
796 var mm = (now.getMinutes()<10)?"0"+now.getMinutes():now.getMinutes();
797 var hh = (now.getHours() <10)?"0"+now.getHours() :now.getHours();
798
799 var kw = "KW" + this.getCalendarWeek(this.year, this.month, this.date);
800 var str = hh+":"+mm+":"+ss+"\u00a0["+kw+"]";
801 return str;
802 };
803
804 this.getCell = function(tag, str, cssClass)
805 {
806 var El = document.createElement( tag );
807 El.appendChild(document.createTextNode( str ));
808 if (cssClass != null)
809 El.className = cssClass;
810 return El;
811 },
812
813 this.switchMonth = function( s )
814 {
815 switch (s)
816 {
817 case "prev":
818 this.yy = (this.mm == 0) ? this.yy-1 : this.yy;
819 this.mm = (this.mm == 0) ? 11 : this.mm-1;
820 break;
821
822 case "next":
823 this.yy = (this.mm == 11) ? this.yy+1 : this.yy;
824 this.mm = (this.mm == 11) ? 0 : this.mm+1;
825 break;
826
827 case "prev_year":
828 this.yy = this.yy-1;
829 break;
830
831 case "next_year":
832 this.yy = this.yy+1;
833 break;
834
835 case "current":
836 this.yy = this.year;
837 this.mm = this.month;
838 break;
839 }
840 this.show();
841 }
842
843 this.getMoonPhase = function(Y, M, D)
844 {
845 // M=0..11 --> 1..12
846 M += 1;
847
848 // calculate the Julian date at 12h UT
849 var YY = Y - Math.floor( ( 12 - M ) / 10 );
850 var MM = ( M + 9 ) % 12;
851
852 var K1 = Math.floor( 365.25 * ( YY + 4712 ) );
853 var K2 = Math.floor( 30.6 * MM + 0.5 );
854 var K3 = Math.floor( Math.floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38;
855
856 var JD = K1 + K2 + D + 59; // for dates in Julian calendar
857 if ( JD > 2299160 ) // for Gregorian calendar
858 JD = JD - K3;
859
860 // calculate moon's age in days
861 var IP = ( ( JD - 2451550.1 ) / 29.530588853 ) % 1;
862
863 return IP;
864
865 // Moon's age
866 //var AG = IP*29.53;
867 }
868
869 this.getMoonPhaseStr = function(IP)
870 {
871 var phase = " ("+(100-Math.abs(IP-0.5)*200).toPrecision(2)+"%)";
872
873 if (IP*16 < 1) return "New moon" + phase;
874 if (IP*16 < 3) return "Evening crescent" + phase;
875 if (IP*16 < 5) return "First quarter" + phase;
876 if (IP*16 < 7) return "Waxing gibbous" + phase;
877 if (IP*16 < 9) return "Full moon" + phase;
878 if (IP*16 <11) return "Waning gibbous" + phase;
879 if (IP*16 <13) return "Last quarter" + phase;
880 if (IP*16 <15) return "Morning crescent" + phase;
881
882 return "New moon"+phase;
883 }
884}
885
886var DOMContentLoaded = false;
887function addContentLoadListener (func)
888{
889 if (document.addEventListener)
890 {
891 var DOMContentLoadFunction = function ()
892 {
893 window.DOMContentLoaded = true;
894 func();
895 };
896
897 document.addEventListener("DOMContentLoaded", DOMContentLoadFunction, false);
898 }
899
900 var oldfunc = (window.onload || new Function());
901
902 window.onload = function ()
903 {
904 if (!window.DOMContentLoaded)
905 {
906 oldfunc();
907 func();
908 }
909 };
910}
911
912addContentLoadListener( function() {
913new CalendarJS().init("calendar");
914//new CalendarJS().init("calendar", new Date(2009, 1, 15));
915} );
Note: See TracBrowser for help on using the repository browser.