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

Last change on this file since 17374 was 16812, checked in by tbretz, 11 years ago
When a user was logged in, the setting of a collaborator failed.. this is fixed now.
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
495 if (user!="Shift" && user!="Debug")
496 uri += "&u="+user;
497
498 uri += "&x="+(user=="Debug"?1:0);
499
500 var xmlHttp = new XMLHttpRequest();
501 xmlHttp.open('POST', uri, true);
502 xmlHttp.onload = function ()
503 {
504 if (xmlHttp.status!=200)
505 {
506 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
507 return;
508 }
509
510 var lines = xmlHttp.responseText.split('\n');
511 if (lines.length==0)
512 return;
513
514 while (td.childNodes.length>1)
515 td.removeChild(td.lastChild);
516
517 for (var i=0; i<lines.length; i++)
518 {
519 var x = lines[i].split('\t');
520 if (x.length!=3)
521 continue;
522
523 var div = document.createElement("div");
524 div.style.fontWeight="normal";
525 div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
526 td.appendChild(div);
527
528 for (var j=0; j<institutes.length; j++)
529 if (x[1]==institutes[j])
530 {
531 div.className += " institute";
532 break;
533 }
534 }
535
536 if (td.childNodes.length>1)
537 td.className += " enabled";
538 else
539 td.className = td.className.replace(/enabled/g, "");
540 };
541
542 xmlHttp.send();
543 }
544
545 function logout()
546 {
547 var xmlHttp = new XMLHttpRequest();
548 xmlHttp.open('POST', "calendar.php?logout", true);
549 xmlHttp.onload = function ()
550 {
551 if (xmlHttp.status!=401)
552 {
553 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
554 return;
555 }
556
557 alert(xmlHttp.statusText);
558 };
559
560 xmlHttp.send();
561 }
562
563 function pushComment()
564 {
565 var c = document.getElementById("comment");
566
567 var y = c.getAttribute("data-y");
568 var m = c.getAttribute("data-m");
569 var d = c.getAttribute("data-d");
570 var v = c.value;
571
572 var uri = "calendar.php?y="+y+"&m="+m+"&d="+d+"&c="+encodeURIComponent(v);
573
574 var xmlHttp = new XMLHttpRequest();
575 xmlHttp.open('POST', uri, true);
576 xmlHttp.onload = function()
577 {
578 if (xmlHttp.status!=200)
579 {
580 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
581 return;
582 }
583
584 alert("Comment inserted successfully.");
585
586 var td = document.getElementById(m+"-"+d);
587 var sp = td.firstChild.firstChild.lastChild.lastChild;
588 if (v=="")
589 {
590 sp.style.display="none";
591 td.title="Click to select this date.";
592 }
593 else
594 {
595 sp.style.display="";
596 td.title=v;
597 }
598
599 };
600
601 xmlHttp.send();
602 }
603
604 function requestComment(yy, mm, dd)
605 {
606 var c = document.getElementById("comment");
607
608 var y = c.getAttribute("data-y");
609 var m = c.getAttribute("data-m");
610 var d = c.getAttribute("data-d");
611
612 if (y==yy && m==mm && d==dd)
613 return;
614
615 var uri = "calendar.php?comment&y="+yy+"&m="+mm+"&d="+dd;
616 var xmlHttp = new XMLHttpRequest();
617 xmlHttp.open('POST', uri, true);
618 xmlHttp.onload = function ()
619 {
620 if (xmlHttp.status!=200)
621 {
622 alert("ERROR - HTTP request: "+xmlHttp.statusText+" ["+xmlHttp.status+"]");
623 return;
624 }
625
626 var td = document.getElementById(mm+"-"+dd);
627 var sp = td.firstChild.firstChild.lastChild.lastChild;
628
629 if (sp!=undefined)
630 {
631 c.color="#888";
632 if (xmlHttp.responseText=="")
633 {
634 c.value="enter comment here";
635 sp.style.display="none";
636 td.title="";
637 }
638 else
639 {
640 c.value = xmlHttp.responseText;
641 sp.style.display="";
642 td.title=xmlHttp.responseText;
643 }
644 }
645
646 c.setAttribute("data-y", yy);
647 c.setAttribute("data-m", mm);
648 c.setAttribute("data-d", dd);
649 };
650
651 xmlHttp.send();
652 }
653
654 var xmlReqAll = null;
655 function requestAll(yy, mm)
656 {
657 if (xmlReqAll)
658 xmlReqAll.abort();
659
660 var uri = "calendar.php?y="+yy+"&m="+mm;
661
662 xmlReqAll = new XMLHttpRequest();
663 xmlReqAll.open('POST', uri, true);
664 xmlReqAll.onload = function ()
665 {
666 if (xmlReqAll.status!=200)
667 {
668 alert("ERROR - HTTP request: "+xmlReqAll.statusText+" ["+xmlReqAll.status+"]");
669 return;
670 }
671
672 var lines = xmlReqAll.responseText.split('\n');
673 if (lines.length==0)
674 return;
675
676 for (var i=0; i<lines.length; i++)
677 {
678 var x = lines[i].split('\t');
679 if (x.length!=3)
680 continue;
681
682 var td = document.getElementById(mm+"-"+x[0]);
683
684 var div = document.createElement("div");
685 div.style.fontWeight="normal";
686 div.appendChild(document.createTextNode(x[2]=="1"?'('+x[1]+')':x[1]));
687 td.appendChild(div);
688
689 for (var j=0; j<institutes.length; j++)
690 if (x[1]==institutes[j])
691 {
692 div.className += " institute";
693 break;
694 }
695
696 td.className += " enabled";
697 }
698 };
699
700 xmlReqAll.send();
701 }
702
703 var xmlReqCom = null;
704 function requestAllComments(yy, mm)
705 {
706 if (xmlReqCom)
707 xmlReqCom.abort();
708
709 var uri = "calendar.php?comment&y="+yy+"&m="+mm;
710 xmlReqCom = new XMLHttpRequest();
711 xmlReqCom.open('POST', uri, true);
712 xmlReqCom.onload = function ()
713 {
714 if (xmlReqCom.status!=200)
715 {
716 alert("ERROR - HTTP request: "+xmlReqCom.statusText+" ["+xmlReqCom.status+"]");
717 return;
718 }
719
720 if (xmlReqCom.responseText<4)
721 return;
722
723 var pos = 6;
724
725 while (pos<xmlReqCom.responseText.length)
726 {
727 var len = parseInt(xmlReqCom.responseText.substr(pos-6, 4), 10);
728 var dd = parseInt(xmlReqCom.responseText.substr(pos-2, 2), 10);
729 var com = xmlReqCom.responseText.substr(pos, len);
730 pos += len+6;
731
732 if (com!="")
733 {
734 var td = document.getElementById(mm+"-"+dd);
735 var sp = td.firstChild.firstChild.lastChild.lastChild;
736 sp.style.display="";
737 td.title=com;
738 }
739 }
740 };
741
742 xmlReqCom.send();
743 }
744
745 this.setDate = function()
746 {
747 request(this);
748 };
749
750 this.changeUser = function()
751 {
752 var sib = this.nextSibling;
753 while (sib)
754 {
755 sib.style.backgroundColor = "";
756 sib = sib.nextSibling;
757 }
758
759 sib = this.previousSibling;
760 while (sib)
761 {
762 sib.style.backgroundColor = "";
763 sib = sib.previousSibling;
764 }
765
766 this.style.backgroundColor = "yellow";
767
768 document.getElementById("body").setAttribute("data-user", this.firstChild.textContent);
769 };
770
771 this.chooseDate = function()
772 {
773 while (document.getElementsByClassName("choosen")[0])
774 {
775 var e = document.getElementsByClassName("choosen")[0];
776 e.title = "Click to select this date.";
777 e.className = e.className.replace(/choosen/g, "");
778 e.onclick = function() {
779 this.chooseDate();
780 };
781 }
782
783 this.className += " choosen";
784 this.title = "Click again to add or remove your name.";
785
786 requestComment(this.yy, this.mm, this.dd);
787
788 this.onclick = function() {
789 this.setDate();
790 };
791 };
792
793 this.timeTrigger = function()
794 {
795 var now = new Date();
796 var ss = (now.getSeconds()<10)?"0"+now.getSeconds():now.getSeconds();
797 var mm = (now.getMinutes()<10)?"0"+now.getMinutes():now.getMinutes();
798 var hh = (now.getHours() <10)?"0"+now.getHours() :now.getHours();
799
800 var kw = "KW" + this.getCalendarWeek(this.year, this.month, this.date);
801 var str = hh+":"+mm+":"+ss+"\u00a0["+kw+"]";
802 return str;
803 };
804
805 this.getCell = function(tag, str, cssClass)
806 {
807 var El = document.createElement( tag );
808 El.appendChild(document.createTextNode( str ));
809 if (cssClass != null)
810 El.className = cssClass;
811 return El;
812 },
813
814 this.switchMonth = function( s )
815 {
816 switch (s)
817 {
818 case "prev":
819 this.yy = (this.mm == 0) ? this.yy-1 : this.yy;
820 this.mm = (this.mm == 0) ? 11 : this.mm-1;
821 break;
822
823 case "next":
824 this.yy = (this.mm == 11) ? this.yy+1 : this.yy;
825 this.mm = (this.mm == 11) ? 0 : this.mm+1;
826 break;
827
828 case "prev_year":
829 this.yy = this.yy-1;
830 break;
831
832 case "next_year":
833 this.yy = this.yy+1;
834 break;
835
836 case "current":
837 this.yy = this.year;
838 this.mm = this.month;
839 break;
840 }
841 this.show();
842 }
843
844 this.getMoonPhase = function(Y, M, D)
845 {
846 // M=0..11 --> 1..12
847 M += 1;
848
849 // calculate the Julian date at 12h UT
850 var YY = Y - Math.floor( ( 12 - M ) / 10 );
851 var MM = ( M + 9 ) % 12;
852
853 var K1 = Math.floor( 365.25 * ( YY + 4712 ) );
854 var K2 = Math.floor( 30.6 * MM + 0.5 );
855 var K3 = Math.floor( Math.floor( ( YY / 100 ) + 49 ) * 0.75 ) - 38;
856
857 var JD = K1 + K2 + D + 59; // for dates in Julian calendar
858 if ( JD > 2299160 ) // for Gregorian calendar
859 JD = JD - K3;
860
861 // calculate moon's age in days
862 var IP = ( ( JD - 2451550.1 ) / 29.530588853 ) % 1;
863
864 return IP;
865
866 // Moon's age
867 //var AG = IP*29.53;
868 }
869
870 this.getMoonPhaseStr = function(IP)
871 {
872 var phase = " ("+(100-Math.abs(IP-0.5)*200).toPrecision(2)+"%)";
873
874 if (IP*16 < 1) return "New moon" + phase;
875 if (IP*16 < 3) return "Evening crescent" + phase;
876 if (IP*16 < 5) return "First quarter" + phase;
877 if (IP*16 < 7) return "Waxing gibbous" + phase;
878 if (IP*16 < 9) return "Full moon" + phase;
879 if (IP*16 <11) return "Waning gibbous" + phase;
880 if (IP*16 <13) return "Last quarter" + phase;
881 if (IP*16 <15) return "Morning crescent" + phase;
882
883 return "New moon"+phase;
884 }
885}
886
887var DOMContentLoaded = false;
888function addContentLoadListener (func)
889{
890 if (document.addEventListener)
891 {
892 var DOMContentLoadFunction = function ()
893 {
894 window.DOMContentLoaded = true;
895 func();
896 };
897
898 document.addEventListener("DOMContentLoaded", DOMContentLoadFunction, false);
899 }
900
901 var oldfunc = (window.onload || new Function());
902
903 window.onload = function ()
904 {
905 if (!window.DOMContentLoaded)
906 {
907 oldfunc();
908 func();
909 }
910 };
911}
912
913addContentLoadListener( function() {
914new CalendarJS().init("calendar");
915//new CalendarJS().init("calendar", new Date(2009, 1, 15));
916} );
Note: See TracBrowser for help on using the repository browser.