-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-mycal.html
713 lines (636 loc) · 29.9 KB
/
simple-mycal.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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Myanmar Calendar</title>
<!-- Favicon links -->
<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png" />
<link rel="manifest" href="/favicon/site.webmanifest" />
<link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#5bbad5" />
<link rel="shortcut icon" href="/favicon/favicon.ico" />
<meta name="msapplication-TileColor" content="#da532c" />
<meta name="msapplication-TileImage" content="/favicon/mstile-150x150.png" />
<meta name="theme-color" content="#ffffff" />
<meta property="og:image" content="/icon.jpg" />
<meta property="og:image:width" content="1024" />
<meta property="og:image:height" content="1024" />
<meta property="og:image:alt" content="Myanmar Calendar" />
<meta property="og:title" content="Myanmar Calendar" />
<meta property="og:description" content="Myanmar Calendar is a simple calendar application that displays Myanmar dates." />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="Myanmar Calendar" />
<!-- Tailwind CSS Configuration -->
<script>
tailwind.config = {
darkMode: "class",
};
</script>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Custom Scripts -->
<script src="https://unpkg.com/mycal@latest/dist/client/mycal.min.js"></script>
<script src="https://unpkg.com/baydin@latest/dist/client/baydin.min.js"></script>
</head>
<body class="bg-gray-900 text-gray-100 flex items-center justify-center min-h-screen">
<main class="bg-gray-800 p-6 rounded-lg shadow-lg w-full max-w-5xl mx-4">
<header class="flex flex-col sm:flex-row justify-center items-center mb-6 space-y-4 sm:space-y-0 sm:space-x-6">
<div class="flex items-center space-x-4">
<button
id="prevMonth"
class="bg-blue-600 text-white p-2 rounded-full hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
aria-label="Previous Month"
>
<!-- Left Arrow SVG -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
</svg>
</button>
<!-- Month Picker -->
<div class="relative">
<div
id="monthPicker"
class="bg-blue-600 text-white p-2 rounded-full cursor-pointer hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 flex items-center justify-between w-32"
>
<span id="selectedMonth">Select Month</span>
<!-- Down Arrow SVG -->
<svg class="h-4 w-4 text-white ml-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" stroke="currentColor">
<path d="M7 7l3 3 3-3" />
</svg>
</div>
<!-- Month Dropdown -->
<div id="monthDropdown" class="absolute mt-2 w-48 bg-white dark:bg-gray-700 text-black dark:text-white rounded shadow-lg overflow-hidden z-20 hidden">
<input
type="text"
id="monthSearch"
placeholder="Search Month"
class="w-full p-2 border-b border-gray-200 dark:border-gray-600 outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-black dark:text-white"
/>
<ul id="monthList" class="max-h-60 overflow-y-auto">
<!-- Month options will be populated here -->
</ul>
</div>
</div>
<!-- Year Picker -->
<div class="relative">
<div
id="yearPicker"
class="bg-blue-600 text-white p-2 rounded-full cursor-pointer hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500 flex items-center justify-between w-32"
>
<span id="selectedYear">Select Year</span>
<!-- Down Arrow SVG -->
<svg class="h-4 w-4 text-white ml-2" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20" stroke="currentColor">
<path d="M7 7l3 3 3-3" />
</svg>
</div>
<!-- Year Dropdown -->
<div id="yearDropdown" class="absolute mt-2 w-48 bg-white dark:bg-gray-700 text-black dark:text-white rounded shadow-lg overflow-hidden z-20 hidden">
<input
type="number"
id="yearSearch"
placeholder="Search Year"
inputmode="numeric"
class="w-full p-2 border-b border-gray-200 dark:border-gray-600 outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-black dark:text-white"
/>
<ul id="yearList" class="max-h-60 overflow-y-auto">
<!-- Year options will be populated here -->
</ul>
</div>
</div>
<button
id="nextMonth"
class="bg-blue-600 text-white p-2 rounded-full hover:bg-blue-700 transition duration-300 focus:outline-none focus:ring-2 focus:ring-blue-500"
aria-label="Next Month"
>
<!-- Right Arrow SVG -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
</svg>
</button>
</div>
</header>
<h1 id="calendarTitle" class="text-3xl font-bold text-center mb-6 text-gray-100"></h1>
<div id="weekdayNames" class="grid grid-cols-7 gap-2 sm:gap-4 text-center font-semibold text-gray-300"></div>
<section id="calendar" class="grid grid-cols-7 gap-2 sm:gap-4"></section>
<footer class="flex justify-center mt-6">
<button
id="goToToday"
class="bg-green-600 text-white py-2 px-4 rounded hover:bg-green-700 transition duration-300 hidden focus:outline-none focus:ring-2 focus:ring-green-500"
>
Go to Today
</button>
</footer>
</main>
<!-- Modal -->
<div id="myModal" class="fixed inset-0 bg-gray-900 bg-opacity-50 flex items-center justify-center hidden z-50">
<div
class="bg-gray-800 p-6 rounded-lg shadow-lg max-w-md w-full mx-4 sm:mx-auto transform transition-all duration-300 ease-out scale-95 opacity-0 flex flex-col items-center"
>
<h2 class="text-2xl font-semibold mb-4 text-center text-gray-100">
<span id="modalDate" class="text-blue-400"></span>
</h2>
<div id="modalMyanmarDate" class="text-lg leading-relaxed mb-4 flex flex-col items-center text-gray-300"></div>
<button
id="closeModal"
class="bg-blue-600 text-white py-2 px-6 rounded-full mt-4 mx-auto block hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 transition duration-300"
>
Close
</button>
</div>
</div>
<!-- Month Picker Modal -->
<div id="monthPickerModal" class="fixed inset-0 bg-gray-900 bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 p-6 rounded-lg shadow-lg max-w-md w-full mx-4 transform transition-all duration-300 ease-out scale-95 opacity-0">
<h2 class="text-2xl font-semibold mb-4 text-center text-gray-100">Select Month</h2>
<input
type="text"
id="monthSearchModal"
placeholder="Search Month"
class="w-full p-2 border-b border-gray-200 dark:border-gray-600 outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-black dark:text-white mb-4"
/>
<ul id="monthListModal" class="max-h-60 overflow-y-auto">
<!-- Month options will be populated here -->
</ul>
<button
id="closeMonthModal"
class="bg-blue-600 text-white py-2 px-6 rounded-full mt-4 mx-auto block hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 transition duration-300"
>
Close
</button>
</div>
</div>
<!-- Year Picker Modal -->
<div id="yearPickerModal" class="fixed inset-0 bg-gray-900 bg-opacity-50 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 p-6 rounded-lg shadow-lg max-w-md w-full mx-4 transform transition-all duration-300 ease-out scale-95 opacity-0">
<h2 class="text-2xl font-semibold mb-4 text-center text-gray-100">Select Year</h2>
<input
type="number"
id="yearSearchModal"
placeholder="Search Year"
inputmode="numeric"
class="w-full p-2 border-b border-gray-200 dark:border-gray-600 outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-700 text-black dark:text-white mb-4"
/>
<ul id="yearListModal" class="max-h-60 overflow-y-auto">
<!-- Year options will be populated here -->
</ul>
<button
id="closeYearModal"
class="bg-blue-600 text-white py-2 px-6 rounded-full mt-4 mx-auto block hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 transition duration-300"
>
Close
</button>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
// Your existing JavaScript variables
const calendarElement = document.getElementById("calendar");
const calendarTitle = document.getElementById("calendarTitle");
const prevMonthButton = document.getElementById("prevMonth");
const nextMonthButton = document.getElementById("nextMonth");
const monthPicker = document.getElementById("monthPicker");
const yearPicker = document.getElementById("yearPicker");
const goToTodayButton = document.getElementById("goToToday");
const myModal = document.getElementById("myModal");
const closeModal = document.getElementById("closeModal");
const modalDate = document.getElementById("modalDate");
const modalMyanmarDate = document.getElementById("modalMyanmarDate");
const weekdayNamesElement = document.getElementById("weekdayNames");
// New variables for custom dropdowns
const monthDropdown = document.getElementById("monthDropdown");
const monthList = document.getElementById("monthList");
const monthSearch = document.getElementById("monthSearch");
const selectedMonthElement = document.getElementById("selectedMonth");
const yearDropdown = document.getElementById("yearDropdown");
const yearList = document.getElementById("yearList");
const yearSearch = document.getElementById("yearSearch");
const selectedYearElement = document.getElementById("selectedYear");
// Variables for modals
const monthPickerModal = document.getElementById("monthPickerModal");
const monthListModal = document.getElementById("monthListModal");
const monthSearchModal = document.getElementById("monthSearchModal");
const closeMonthModal = document.getElementById("closeMonthModal");
const yearPickerModal = document.getElementById("yearPickerModal");
const yearListModal = document.getElementById("yearListModal");
const yearSearchModal = document.getElementById("yearSearchModal");
const closeYearModal = document.getElementById("closeYearModal");
let today = new Date();
let currentYear = today.getFullYear();
let currentMonth = today.getMonth();
// Variable to check if the device is mobile
let isMobile = window.innerWidth <= 640;
window.addEventListener("resize", () => {
isMobile = window.innerWidth <= 640;
});
// Initialize selected month and year
selectedMonthElement.textContent = getMonthName(currentMonth);
selectedYearElement.textContent = currentYear;
// Populate month and year dropdowns
function populateMonthDropdown() {
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
monthList.innerHTML = monthNames
.map(
(month, index) => `
<li class="p-2 hover:bg-gray-200 dark:hover:bg-gray-600 cursor-pointer ${index === currentMonth ? "bg-gray-300 dark:bg-gray-600" : ""}" data-month="${index}">
${month}
</li>
`,
)
.join("");
}
function populateYearDropdown() {
const minYear = 1885;
const maxYear = today.getFullYear() + 100;
let years = "";
for (let year = maxYear; year >= minYear; year--) {
years += `
<li class="p-2 hover:bg-gray-200 dark:hover:bg-gray-600 cursor-pointer ${year === currentYear ? "bg-gray-300 dark:bg-gray-600" : ""}" data-year="${year}">
${year}
</li>
`;
}
yearList.innerHTML = years;
}
// Initialize the dropdowns
populateMonthDropdown();
populateYearDropdown();
// Event listeners for opening and closing dropdowns
monthPicker.addEventListener("click", (e) => {
e.stopPropagation();
if (isMobile) {
showMonthModal();
} else {
monthDropdown.classList.toggle("hidden");
yearDropdown.classList.add("hidden");
monthSearch.value = "";
filterMonthOptions();
const selectedOption = monthList.querySelector(`li[data-month="${currentMonth}"]`);
if (selectedOption) {
selectedOption.scrollIntoView({ block: "nearest" });
}
}
});
yearPicker.addEventListener("click", (e) => {
e.stopPropagation();
if (isMobile) {
showYearModal();
} else {
yearDropdown.classList.toggle("hidden");
monthDropdown.classList.add("hidden");
yearSearch.value = "";
filterYearOptions();
const selectedOption = yearList.querySelector(`li[data-year="${currentYear}"]`);
if (selectedOption) {
selectedOption.scrollIntoView({ block: "nearest" });
}
}
});
// Close dropdowns when clicking outside
document.addEventListener("click", () => {
monthDropdown.classList.add("hidden");
yearDropdown.classList.add("hidden");
});
// Event listeners for selecting month and year
monthList.addEventListener("click", (e) => {
const li = e.target.closest("li[data-month]");
if (li) {
currentMonth = parseInt(li.getAttribute("data-month"));
selectedMonthElement.textContent = li.textContent;
monthDropdown.classList.add("hidden");
renderCalendar(currentYear, currentMonth);
}
});
yearList.addEventListener("click", (e) => {
const li = e.target.closest("li[data-year]");
if (li) {
currentYear = parseInt(li.getAttribute("data-year"));
selectedYearElement.textContent = li.textContent;
yearDropdown.classList.add("hidden");
renderCalendar(currentYear, currentMonth);
}
});
// Prevent event propagation inside the dropdowns
monthDropdown.addEventListener("click", (e) => {
e.stopPropagation();
});
yearDropdown.addEventListener("click", (e) => {
e.stopPropagation();
});
// Search functionality for month and year
function filterMonthOptions() {
const filter = monthSearch.value.toLowerCase();
const options = monthList.querySelectorAll("li");
options.forEach((option) => {
const text = option.textContent.toLowerCase();
option.style.display = text.includes(filter) ? "" : "none";
});
}
function filterYearOptions() {
const filter = yearSearch.value;
const options = yearList.querySelectorAll("li");
options.forEach((option) => {
const text = option.textContent;
option.style.display = text.includes(filter) ? "" : "none";
});
}
monthSearch.addEventListener("keyup", filterMonthOptions);
yearSearch.addEventListener("keyup", filterYearOptions);
// Modal show and hide functions
function showMonthModal() {
// Populate the modal with month options
monthListModal.innerHTML = monthList.innerHTML;
monthSearchModal.value = "";
filterMonthOptionsModal();
// Scroll to the selected month
setTimeout(() => {
const selectedOption = monthListModal.querySelector(`li[data-month="${currentMonth}"]`);
if (selectedOption) {
selectedOption.scrollIntoView({ block: "nearest", behavior: "smooth" });
}
}, 0);
monthPickerModal.classList.remove("hidden");
const modalContent = monthPickerModal.querySelector("div");
setTimeout(() => {
modalContent.classList.remove("scale-95", "opacity-0");
modalContent.classList.add("scale-100", "opacity-100");
}, 10);
}
function hideMonthModal() {
const modalContent = monthPickerModal.querySelector("div");
modalContent.classList.remove("scale-100", "opacity-100");
modalContent.classList.add("scale-95", "opacity-0");
setTimeout(() => {
monthPickerModal.classList.add("hidden");
}, 300);
}
function showYearModal() {
// Populate the modal with year options
yearListModal.innerHTML = yearList.innerHTML;
yearSearchModal.value = "";
filterYearOptionsModal();
// Scroll to the selected year
setTimeout(() => {
const selectedOption = yearListModal.querySelector(`li[data-year="${currentYear}"]`);
if (selectedOption) {
selectedOption.scrollIntoView({ block: "nearest", behavior: "smooth" });
}
}, 0);
yearPickerModal.classList.remove("hidden");
const modalContent = yearPickerModal.querySelector("div");
setTimeout(() => {
modalContent.classList.remove("scale-95", "opacity-0");
modalContent.classList.add("scale-100", "opacity-100");
}, 10);
}
function hideYearModal() {
const modalContent = yearPickerModal.querySelector("div");
modalContent.classList.remove("scale-100", "opacity-100");
modalContent.classList.add("scale-95", "opacity-0");
setTimeout(() => {
yearPickerModal.classList.add("hidden");
}, 300);
}
// Event Listeners for Modals
closeMonthModal.addEventListener("click", hideMonthModal);
closeYearModal.addEventListener("click", hideYearModal);
monthPickerModal.addEventListener("click", (e) => {
if (e.target === monthPickerModal) {
hideMonthModal();
}
});
yearPickerModal.addEventListener("click", (e) => {
if (e.target === yearPickerModal) {
hideYearModal();
}
});
// Close modal on Escape key press
document.addEventListener("keydown", (e) => {
if (e.key === "Escape") {
if (!monthPickerModal.classList.contains("hidden")) {
hideMonthModal();
}
if (!yearPickerModal.classList.contains("hidden")) {
hideYearModal();
}
}
});
// Filtering functions for modals
function filterMonthOptionsModal() {
const filter = monthSearchModal.value.toLowerCase();
const options = monthListModal.querySelectorAll("li");
options.forEach((option) => {
const text = option.textContent.toLowerCase();
option.style.display = text.includes(filter) ? "" : "none";
});
}
function filterYearOptionsModal() {
const filter = yearSearchModal.value;
const options = yearListModal.querySelectorAll("li");
options.forEach((option) => {
const text = option.textContent;
option.style.display = text.includes(filter) ? "" : "none";
});
}
monthSearchModal.addEventListener("keyup", filterMonthOptionsModal);
yearSearchModal.addEventListener("keyup", filterYearOptionsModal);
// Handle selection in modals
monthListModal.addEventListener("click", (e) => {
const li = e.target.closest("li[data-month]");
if (li) {
currentMonth = parseInt(li.getAttribute("data-month"));
selectedMonthElement.textContent = li.textContent;
hideMonthModal();
renderCalendar(currentYear, currentMonth);
}
});
yearListModal.addEventListener("click", (e) => {
const li = e.target.closest("li[data-year]");
if (li) {
currentYear = parseInt(li.getAttribute("data-year"));
selectedYearElement.textContent = li.textContent;
hideYearModal();
renderCalendar(currentYear, currentMonth);
}
});
// Render calendar
function renderCalendar(year, month) {
calendarElement.innerHTML = "";
calendarTitle.innerText = `${getMonthName(month)} ${year}`;
const daysInMonth = new Date(year, month + 1, 0).getDate();
const firstDay = new Date(year, month, 1).getDay();
fillWeekdayNames();
fillInitialEmptyCells(firstDay);
fillDaysOfMonth(year, month, daysInMonth);
if (year !== today.getFullYear() || month !== today.getMonth()) {
goToTodayButton.classList.remove("hidden");
} else {
goToTodayButton.classList.add("hidden");
}
// Update the highlighting in the dropdowns
updateDropdownHighlighting();
}
function fillWeekdayNames() {
const weekdayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
weekdayNamesElement.innerHTML = "";
for (const name of weekdayNames) {
const cell = document.createElement("div");
cell.className = "p-2 text-sm text-gray-300";
cell.innerText = name;
weekdayNamesElement.appendChild(cell);
}
}
function fillInitialEmptyCells(firstDay) {
for (let i = 0; i < firstDay; i++) {
calendarElement.appendChild(createEmptyCell());
}
}
function fillDaysOfMonth(year, month, daysInMonth) {
for (let day = 1; day <= daysInMonth; day++) {
calendarElement.appendChild(createCalendarCell(year, month, day));
}
}
function createEmptyCell() {
const cell = document.createElement("div");
cell.className = "bg-transparent p-4 rounded-lg shadow-md";
return cell;
}
function createCalendarCell(year, month, day) {
const cell = document.createElement("div");
const isToday = year === today.getFullYear() && month === today.getMonth() && day === today.getDate();
// Updated color scheme
const baseCellClass = "p-4 rounded-lg shadow-md transition duration-300 cursor-pointer flex flex-col items-center justify-center";
const todayCellClass = isToday ? "bg-indigo-600 text-white hover:bg-indigo-700" : "bg-gray-700 text-gray-100 hover:bg-gray-600";
cell.className = `${baseCellClass} ${todayCellClass} calendar-cell`;
const date = new Date(year, month, day);
const dateString = `${month + 1}/${day}/${year}`;
const myanmarDate = new mycal(dateString);
cell.innerHTML = `
<div class="text-xl font-bold">${day}</div>
<div class="hidden lg:block">
<p class="text-center text-sm">${myanmarDate.month.my} ${myanmarDate.day.mp.my}</p>
<p class="text-center text-sm">${myanmarDate.day.fd.my}</p>
</div>
`;
cell.addEventListener("click", () => {
showModal(myanmarDate, date.toDateString());
});
return cell;
}
function showModal(myanmarDate, dateString) {
modalDate.innerText = dateString;
const weekDayNumber = new Date(dateString).getDay() + 1;
const dateNumber = new Date(dateString).getDate();
const yearNumber = new Date(dateString).getFullYear();
const monthNumber = new Date(dateString).getMonth() + 1;
modalMyanmarDate.innerHTML = `
<p class="text-center mb-2">${myanmarDate.month.my} ${myanmarDate.day.mp.my} ${myanmarDate.day.fd.my} ရက် ${myanmarDate.weekday.my} နေ့ ${myanmarDate.year.my}</p>
<p class="text-center mb-2">${baydin.maharbote(myanmarDate.year.en, weekDayNumber)} ဖွား</p>
<p class="text-center mb-2">${baydin.numFormat(baydin.numerology(dateNumber))} ဂဏန်း သမား</p>
<p class="text-center mb-2">${baydin.chineseZodiac(yearNumber).signInBurmese} နှစ်</p>
<p class="text-center">${baydin.zodiac(dateNumber, monthNumber).sign_mm} ရာသီ</p>
`;
myModal.classList.remove("hidden");
const modalContent = myModal.querySelector("div");
setTimeout(() => {
modalContent.classList.remove("scale-95", "opacity-0");
modalContent.classList.add("scale-100", "opacity-100");
}, 10);
}
function hideModal() {
const modalContent = myModal.querySelector("div");
modalContent.classList.remove("scale-100", "opacity-100");
modalContent.classList.add("scale-95", "opacity-0");
setTimeout(() => {
myModal.classList.add("hidden");
}, 300);
}
function getMonthName(month) {
const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return monthNames[month];
}
function updateDropdownHighlighting() {
// Update month highlighting
const monthOptions = monthList.querySelectorAll("li");
monthOptions.forEach((option) => {
const monthValue = parseInt(option.getAttribute("data-month"));
if (monthValue === currentMonth) {
option.classList.add("bg-gray-300", "dark:bg-gray-600");
} else {
option.classList.remove("bg-gray-300", "dark:bg-gray-600");
}
});
// Update year highlighting
const yearOptions = yearList.querySelectorAll("li");
yearOptions.forEach((option) => {
const yearValue = parseInt(option.getAttribute("data-year"));
if (yearValue === currentYear) {
option.classList.add("bg-gray-300", "dark:bg-gray-600");
} else {
option.classList.remove("bg-gray-300", "dark:bg-gray-600");
}
});
}
// Event Listeners for navigation buttons
prevMonthButton.addEventListener("click", () => {
currentMonth--;
if (currentMonth < 0) {
currentMonth = 11;
currentYear--;
if (currentYear < 1885) {
currentYear = 1885;
currentMonth = 0;
}
}
selectedMonthElement.textContent = getMonthName(currentMonth);
selectedYearElement.textContent = currentYear;
renderCalendar(currentYear, currentMonth);
});
nextMonthButton.addEventListener("click", () => {
currentMonth++;
if (currentMonth > 11) {
currentMonth = 0;
currentYear++;
if (currentYear > today.getFullYear() + 100) {
currentYear = today.getFullYear() + 100;
currentMonth = 11;
}
}
selectedMonthElement.textContent = getMonthName(currentMonth);
selectedYearElement.textContent = currentYear;
renderCalendar(currentYear, currentMonth);
});
goToTodayButton.addEventListener("click", () => {
currentYear = today.getFullYear();
currentMonth = today.getMonth();
selectedYearElement.textContent = currentYear;
selectedMonthElement.textContent = getMonthName(currentMonth);
renderCalendar(currentYear, currentMonth);
});
closeModal.addEventListener("click", hideModal);
// Close modal when clicking outside the modal content
myModal.addEventListener("click", (e) => {
if (e.target === myModal) {
hideModal();
}
});
// Close modal on Escape key press
document.addEventListener("keydown", (e) => {
if (e.key === "Escape" && !myModal.classList.contains("hidden")) {
hideModal();
}
});
// Initial Render
renderCalendar(currentYear, currentMonth);
// Make the application responsive for mobile devices
function adjustForMobile() {
isMobile = window.innerWidth <= 640;
}
// Call the function on load and on window resize
adjustForMobile();
window.addEventListener("resize", adjustForMobile);
});
</script>
</body>
</html>