-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
176 lines (105 loc) · 3.26 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
var d = new Date();
//var year = d.getFullYear();//2018
var totalyears=[2017,2018,2019];//0-2
var cyear=totalyears.indexOf(year);//1
function previousyear(year)
{
year -= 1;
console.log("yr:"+year);
$(document).ready(function() { /// Wait till page is loaded
$("#calendar-dates0").load(location.href + " #calendar-dates1");
});
// for(let x=0;x<12;x++)
// {
// calen(x,year);
// }
//calen(month,year);
}
function nextyear()
{
year=year+1;
}
function calen(month,year){
var month_name = ['January','February','March','April','May','June','July','August','September','October','November','December'];
//0-11
var first_date = month_name[month] + " " + 1 + " " +year;
//January 1 2018
var tmp = new Date(first_date).toDateString();
//Mon jan 01 2018 ...
var first_day = tmp.substring(0, 3); //Mon
var day_name = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var day_no = day_name.indexOf(first_day); //1
var days = new Date(year, month+1, 0).getDate(); //31
//Wed jan 30 2018 ...
var calendar = get_calendar(day_no, days);
document.getElementById("calendar-dates0").appendChild(calendar);
document.getElementById("calendar-dates1").appendChild(calendar);
document.getElementById("calendar-dates2").appendChild(calendar);
document.getElementById("calendar-dates3").appendChild(calendar);
document.getElementById("calendar-dates4").appendChild(calendar);
document.getElementById("calendar-dates5").appendChild(calendar);
document.getElementById("calendar-dates6").appendChild(calendar);
document.getElementById("calendar-dates7").appendChild(calendar);
document.getElementById("calendar-dates8").appendChild(calendar);
document.getElementById("calendar-dates9").appendChild(calendar);
document.getElementById("calendar-dates10").appendChild(calendar);
document.getElementById("calendar-dates11").appendChild(calendar);
}
function get_calendar(day_no, days)
{
var table = document.createElement('table');
var tr = document.createElement('tr');
//row for the day letters
for(var c=0; c<=6; c++)
{
var td1 = document.createElement('td');
td1.setAttribute("id","week");
td1.innerHTML = "SMTWTFS"[c];
tr.appendChild(td1);
}
table.appendChild(tr);
//create 2nd row
tr = document.createElement('tr');
var c;
for(c=0; c<=6; c++){
if(c == day_no){
break;
}
var td = document.createElement('td');
td.innerHTML = "";
tr.appendChild(td);
}
var count = 1;
for(; c<=6; c++){
var td = document.createElement('td');
var a = document.createElement('a');
a.setAttribute("id",c);
a.setAttribute("href","colour.php")
a.innerHTML = count;
count++;
td.appendChild(a);
tr.appendChild(td);
}
table.appendChild(tr);
//rest of the date rows
for(var r=3; r<=7; r++)
{
tr = document.createElement('tr');
for(var c=0; c<=6; c++){
if(count > days){
table.appendChild(tr);
return table;
}
var td = document.createElement('td');
var a = document.createElement('a');
a.setAttribute("id",c);
a.setAttribute("href","colour.php")
a.innerHTML = count;
count++;
td.appendChild(a);
tr.appendChild(td);
}
table.appendChild(tr);
}
return table;
}