-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection-handler.js
More file actions
30 lines (26 loc) · 1.24 KB
/
Copy pathselection-handler.js
File metadata and controls
30 lines (26 loc) · 1.24 KB
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
export const selectCellsBetween = (timeTable, start, end, shouldRemove = false) => {
if (!start || !end) return;
const startTimeSlot = parseInt(start.dataset.timeSlot);
const startDay = parseInt(start.dataset.day);
const endTimeSlot = parseInt(end.dataset.timeSlot);
const endDay = parseInt(end.dataset.day);
const minTimeSlot = Math.min(startTimeSlot, endTimeSlot);
const maxTimeSlot = Math.max(startTimeSlot, endTimeSlot);
const minDay = Math.min(startDay, endDay);
const maxDay = Math.max(startDay, endDay);
updateCellsInRange(timeTable, minTimeSlot, maxTimeSlot, minDay, maxDay, shouldRemove);
};
const updateCellsInRange = (timeTable, minTimeSlot, maxTimeSlot, minDay, maxDay, shouldRemove) => {
for (let timeSlot = minTimeSlot; timeSlot <= maxTimeSlot; timeSlot++) {
for (let day = minDay; day <= maxDay; day++) {
const cell = timeTable.querySelector(`[data-time-slot="${timeSlot}"][data-day="${day}"]`);
if (cell && !cell.classList.contains('disabled')) {
if (shouldRemove) {
cell.classList.remove('selected');
} else {
cell.classList.add('selected');
}
}
}
}
};