Files
Calendar/script.js
2025-01-23 21:16:02 +01:00

64 lines
1.4 KiB
JavaScript

const WEEKDAYS = Object.freeze({
MONDAY: 0,
TUESDAY: 1,
WEDNESDAY: 2,
THURSDAY: 3,
FRIDAY: 4,
SATURDAY: 5,
SUNDAY: 6
});
const MONTHS = Object.freeze({
JANUARY: 0,
FEBRUARY: 1,
MARCH: 2,
APRIL: 3,
MAY: 4,
JUNE: 5,
JULY: 6,
AUGUST: 7,
SEPTEMBER: 8,
OCTOBER: 9,
NOVEMBER: 10,
DEZEMBER: 11
})
function generateDays() {
const visibleDays = 42 // 7 col, 5 row
const calendarBody = document.getElementById('calendar__body')
if (calendarBody) {
for (let i = 0; i < visibleDays; i++) {
const day = document.createElement('div')
day.classList.add('day')
if (i < Object.keys(WEEKDAYS).length) {
day.classList.add('weekday')
day.textContent = Object.keys(WEEKDAYS)[i]
} else {
const dayId = i % 7 + 1
day.classList.add('day-' + dayId)
}
calendarBody.appendChild(day)
}
}
}
function addCalendarDays() {
const date = new Date()
console.log(date.getMonth())
}
function setHeaderInfo(month, year) {
const yearDOM = document.querySelector('#calendar__header .year')
const monthDOM = document.querySelector('#calendar__header .month')
if (month) {
month.textContent = month
}
}
document.addEventListener('DOMContentLoaded', () => {
generateDays()
addCalendarDays()
})