-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
292 lines (237 loc) · 11.1 KB
/
index.html
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calendar</title>
<link rel="stylesheet" href="tailwind.css">
<link rel="stylesheet" href="style.css">
<!-- <link rel="stylesheet" href="fontawesome-free-v5-web/css/all.css"> -->
<link href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" rel="stylesheet">
</head>
<body class="flex justify-center items-center box-border pt-10">
<div class="width-1400 h-auto rounded shadow-xl box-border">
<div class="head flex justify-between items-center border-2 border-gray-200 rounded-t p-6">
<div class="flex gap-4 items-center">
<div class="flex">
<button
class="w-10 h-10 border text-center rounded-l-md text-gray-500 text-xl hover:border-black transition hover:bg-gray-100 hover:text-white flex justify-center items-center"
id="left"> <i class="fas fa-angle-left"></i> </button>
<button
class="w-10 h-10 border text-center rounded-r-md text-gray-500 text-xl hover:border-black transition hover:bg-gray-100 hover:text-white flex justify-center items-center"
id="right"><i class="fas fa-angle-right"></i></button>
</div>
<div>
<button
class="w-14 h-10 border border-gray-400 text-center bg-gray-400 rounded-md text-gray-500 text-sm hover:border-black transition hover:bg-gray-100 hover:text-gray-400 flex justify-center items-center"
id="today">today</button>
</div>
</div>
<div class="flex items-center h-10">
<p class="text-center text-3xl pr-2" id="month"></p> <span class="text-center text-3xl"
id="year"></span>
</div>
<div class="flex gap-4 items-center">
<div class="flex">
<button class="w-16 h-10 border border-black text-center bg-black rounded-l-md text-gray-500 " id="btn-month">month
</button>
<button
class="w-16 h-10 text-center border border-black-200 bg-white text-gray-500 hover:border-black transition hover:bg-gray-100 hover:text-white" id="btn-week">week</button>
<button
class="w-16 h-10 text-center border border-black-200 bg-white rounded-r-md text-gray-500 hover:border-black transition hover:bg-gray-100 hover:text-white" id="btn-day">day</button>
</div>
</div>
</div>
<div class="weekdays">
<div>Sun</div>
<div>Mon</div>
<div>Tue</div>
<div>Wed</div>
<div>Thu</div>
<div>Fri</div>
<div>Sat</div>
</div>
<div class="alldays"></div>
</div>
<script>
var date = new Date();
function renderCalendar() {
date.setDate(1);
const DAY_OF_MONTH = document.querySelector(".alldays");
const LAST_DAY = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
const FIRST_DAY_INDEX = date.getDay();
const LAST_DAY_INDEX = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDay();
const PREV_LAST_DAY = new Date(date.getFullYear(), date.getMonth(), 0).getDate();
const NEXT_DAY = 7 - LAST_DAY_INDEX - 1;
const MONTH = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
document.querySelector("#month").innerHTML = MONTH[date.getMonth()];
document.querySelector("#year").innerHTML = date.getFullYear();
var Even =
[
{
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2021-11-15T00:00:00.000Z"
, "end_datetime": ""
, "color": "#004e92"
}
, {
"title": "Conference"
, "sub_title": ""
, "start_datetime": "2021-11-10T00:00:00.000Z"
, "end_datetime": ""
, "color": "#42275a"
}
, {
"title": "Launch with customer"
, "sub_title": ""
, "start_datetime": "2021-11-21T00:00:00.000Z"
, "end_datetime": ""
, "color": "#734b6d"
}
, {
"title": "Happy Hour"
, "sub_title": "fasldkfalsdkfldlfksdf"
, "start_datetime": "2021-12-02T00:00:00.000Z"
, "end_datetime": ""
, "color": "#243B55"
}
, {
"title": "Birthday Party"
, "sub_title": "fasldkfalsdkfldlfksdf"
, "start_datetime": "2021-12-01T00:00:00.000Z"
, "end_datetime": ""
, "color": "#F00000"
}
, {
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2021-12-17T00:00:00.000Z"
, "end_datetime": ""
, "color": "#FD746C"
}
, {
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2021-12-30T00:00:00.000Z"
, "end_datetime": ""
, "color": "#004e92"
}
, {
"title": "Conference"
, "sub_title": ""
, "start_datetime": "2021-12-31T00:00:00.000Z"
, "end_datetime": ""
, "color": "#42275a"
}
, {
"title": "Launch with customer"
, "sub_title": ""
, "start_datetime": "2021-12-23T00:00:00.000Z"
, "end_datetime": ""
, "color": "#734b6d"
}
, {
"title": "Happy Hour"
, "sub_title": "fasldkfalsdkfldlfksdf"
, "start_datetime": "2021-12-23T00:00:00.000Z"
, "end_datetime": ""
, "color": "#243B55"
}
, {
"title": "Birthday Party"
, "sub_title": "fasldkfalsdkfldlfksdf"
, "start_datetime": "2022-01-21T00:00:00.000Z"
, "end_datetime": ""
, "color": "#F00000"
}
, {
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2022-02-18T00:00:00.000Z"
, "end_datetime": ""
, "color": "#FD746C"
}
,
{
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2022-02-18T00:00:00.000Z"
, "end_datetime": ""
, "color": "#FD746C"
}
,
{
"title": "Metting"
, "sub_title": ""
, "start_datetime": "2022-04-30T00:00:00.000Z"
, "end_datetime": ""
, "color": "#FD746C"
}
];
var myEven = '';
let days = "";
for (let x = FIRST_DAY_INDEX; x > 0; x--) {
days +=
`
<div class="days prev-date">
<span>${PREV_LAST_DAY - x + 1}</span>
</div>
`;
}
for (let i = 1; i <= LAST_DAY; i++) {
if (i === new Date().getDate() && date.getMonth() === new Date().getMonth()) {
for (let x = 0; x < Even.length; x++) {
if (i.toString() === new Date(Even[x].start_datetime).getDate().toString() && date.getMonth().toString() === new Date(Even[x].start_datetime).getMonth().toString()) {
myEven += `<span class="even text-white font-black text-center" style="background-color: ${Even[x].color}" >${Even[x].title}</span> `;
}
else {
myEven += ' ';
}
}
days +=
`
<div class="days today">
<span>${i}</span>
${myEven}
</div>
`;
myEven = ' ';
}
else {
for (let x = 0; x < Even.length; x++) {
if (i.toString() === new Date(Even[x].start_datetime).getDate().toString() && date.getMonth().toString() === new Date(Even[x].start_datetime).getMonth().toString()) {
myEven += `<span class="even text-white font-black text-center" style="background-color: ${Even[x].color}">${Even[x].title}</span> `;
}
else {
myEven += ' ';
}
}
days += `<div class="days"><span>${i}</span> ${myEven}</div>`;
myEven = '';
}
}
for (let j = 1; j <= NEXT_DAY; j++) {
days += `<div class="days next-date"><span class="d">${j}</span></div>`;
}
DAY_OF_MONTH.innerHTML = days;
};
document.querySelector("#left").addEventListener("click", () => {
date.setMonth(date.getMonth() - 1);
renderCalendar();
});
document.querySelector("#right").addEventListener("click", () => {
date.setMonth(date.getMonth() + 1);
renderCalendar();
});
document.querySelector("#today").addEventListener("click", () => {
date.setMonth(new Date().getMonth());
date.setFullYear(new Date().getFullYear());
date.setDate(new Date().getDate());
renderCalendar();
})
renderCalendar();
</script>
</body>
</html>