2 * Copyright 2007 Jesse Andrews, Manish Singh, Ian Fischer
4 * This file may be used under the terms of of the
5 * GNU General Public License Version 2 or later (the "GPL"),
6 * http://www.gnu.org/licenses/gpl.html
8 * Software distributed under the License is distributed on an "AS IS" basis,
9 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10 * for the specific language governing rights and limitations under the
14 function daysOf(year
, month
) {
15 // determine number of days in month
16 // by adding 1 month, then subtracting 1 second
17 // and looking at the current date
19 var date
= new Date(year
, month
+1, 1);
20 return new Date(date
- 1).getDate();
23 function Calendar(container
) {
25 document
.body
.className
= 'calendar';
27 var table
= document
.createElement('table');
28 container
.appendChild(table
);
33 this.add = function(tab
) {
34 var date
= new Date(tab
.updated
);
35 var Y
= date
.getFullYear();
36 var M
= date
.getMonth();
37 var D
= date
.getDate();
38 if (!_db
[Y
]) { _db
[Y
] = {}; }
39 if (!_db
[Y
][M
]) { _db
[Y
][M
] = {}; }
40 if (!_db
[Y
][M
][D
]) { _db
[Y
][M
][D
] = []; }
41 _db
[Y
][M
][D
].push(tab
);
44 this.clear = function() {
48 this.getTabs = function(Y
,M
,D
) {
58 function addTabsToTD(year
, month
, date
, td
) {
59 var tabs
= db
.getTabs(year
, month
, date
);
60 if (tabs
&& tabs
.length
> 0) {
61 var img
= document
.createElement('img');
62 img
.setAttribute('src', tabs
[0].thumbURL
);
64 td
.onclick = function() {
65 var div
= document
.createElement('div');
66 div
.setAttribute('class', 'tabs');
67 tabs
.forEach(function(tab
) {
68 var img
= document
.createElement('img');
69 img
.setAttribute('src', tab
.thumbURL
);
70 img
.setAttribute('title', tab
.title
);
71 img
.onclick = function(event
) {
72 SVC
.open(tab
.url
, whereToOpenLink(event
));
76 container
.appendChild(div
);
77 var remover = function(event
) {
78 if (event
.target
!= div
) {
79 container
.removeChild(div
);
80 document
.removeEventListener('click', remover
, true);
83 document
.addEventListener('click', remover
, true);
87 td
.setAttribute('class', 'empty')
88 td
.appendChild(document
.createTextNode(date
));
92 this.start = function() {
94 container
.removeChild(table
);
95 table
= document
.createElement('table');
96 container
.appendChild(table
);
99 this.finish = function(year
, month
) {
100 var year
= year
|| new Date().getFullYear(); // default to current year
101 var month
= month
|| new Date().getMonth(); // default to current month
102 var days
= daysOf(year
, month
);
104 table
.innerHTML
= "<tr><th colspan='7' id='date_nav'><span id='nav_left'>←</span>" + (month
+1) + ' / ' + year
+ '<span id="nav_right">→</span></th></tr>' +
105 "<tr><th>SUN</th><th>MON</th><th>TUE</th><th>WED</th><th>THUR</th><th>FRI</th><th>SAT</th></tr>";
107 var left
= document
.getElementById('nav_left');
108 left
.onclick = function() {
109 var new_month
= month
- 1;
115 self
.finish(new_year
, new_month
);
118 var right
= document
.getElementById('nav_right');
119 right
.onclick = function() {
120 var new_month
= month
+ 1;
122 if (new_month
> 11) {
126 self
.finish(new_year
, new_month
);
131 for (var date
=1; date
<=days
; date
++) {
132 var curDate
= new Date(year
, month
, date
);
135 tr
= document
.createElement('tr');
136 for (var i
=0; i
<curDate
.getDay(); i
++) {
137 var td
= document
.createElement('td');
138 td
.setAttribute('class', 'blank')
141 table
.appendChild(tr
);
144 var td
= document
.createElement('td');
146 addTabsToTD(year
, month
, date
, td
);
149 if (curDate
.getDay() == 6) {
155 this.add = function(tab
) {