forked from Va16hav07/Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdash.js
64 lines (54 loc) · 1.89 KB
/
dash.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
const calendarGrid = document.getElementById("calendar-grid");
const monthYearDisplay = document.getElementById("month-year");
const taskList = document.getElementById("task-list");
let currentDate = new Date();
// Initialize the calendar
function loadCalendar(date) {
const year = date.getFullYear();
const month = date.getMonth();
monthYearDisplay.textContent = `${date.toLocaleString("default", {
month: "long",
})} ${year}`;
const firstDay = new Date(year, month, 1).getDay();
const daysInMonth = new Date(year, month + 1, 0).getDate();
calendarGrid.innerHTML = "";
// Fill empty cells for days of the previous month
for (let i = 0; i < firstDay; i++) {
const emptyCell = document.createElement("div");
emptyCell.classList.add("calendar-cell");
calendarGrid.appendChild(emptyCell);
}
// Fill actual days
for (let day = 1; day <= daysInMonth; day++) {
const cell = document.createElement("div");
cell.classList.add("calendar-cell");
cell.textContent = day;
cell.addEventListener("dragover", (e) => e.preventDefault());
cell.addEventListener("drop", (e) => {
e.preventDefault();
const task = document.querySelector(".dragging");
cell.appendChild(task);
});
calendarGrid.appendChild(cell);
}
}
// Drag and Drop Functionality
document.querySelectorAll(".task").forEach((task) => {
task.addEventListener("dragstart", () => {
task.classList.add("dragging");
});
task.addEventListener("dragend", () => {
task.classList.remove("dragging");
});
});
// Navigation Controls
document.getElementById("prev-month").addEventListener("click", () => {
currentDate.setMonth(currentDate.getMonth() - 1);
loadCalendar(currentDate);
});
document.getElementById("next-month").addEventListener("click", () => {
currentDate.setMonth(currentDate.getMonth() + 1);
loadCalendar(currentDate);
});
// Initial Load
loadCalendar(currentDate);