Skip to content

Commit

Permalink
Update PAGE-calendar.js
Browse files Browse the repository at this point in the history
  • Loading branch information
code-boxx authored Sep 13, 2023
1 parent b14548f commit b0cc490
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions calendar/assets/PAGE-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ var cal = {
nowDay = cal.sMth==nowMth && cal.sYear==nowYear ? now.getDate() : null ;

// (E2) DRAW CALENDAR ROWS & CELLS
// (E2-1) INIT + HELPER FUNCTIONS
let rowA, rowB, rowC, rowMap = {}, rowNum = 1,
cell, cellNum = 1,
// (E2-1) INIT
let rowA, rowB, rowC, rowMap = {}, rowNum = 1, cell, cellNum = 1,

// (E2-2) HELPER - DRAW A NEW ROW
rower = () => {
rowA = document.createElement("div");
rowB = document.createElement("div");
Expand All @@ -109,6 +110,8 @@ var cal = {
rowA.appendChild(rowB);
rowA.appendChild(rowC);
},

// (E2-3) HELPER - DRAW A NEW CELL
celler = day => {
cell = document.createElement("div");
cell.className = "calCell";
Expand All @@ -130,9 +133,11 @@ var cal = {
if (day!==undefined && day==nowDay) { cell.classList.add("calToday"); }
rowC.appendChild(cell);
};

// (E2-4) RESET CALENDAR
cal.hCB.innerHTML = ""; rower();

// (E2-2) BLANK CELLS BEFORE START OF MONTH
// (E2-5) BLANK CELLS BEFORE START OF MONTH
if (cal.mon && startDay != 1) {
let blanks = startDay==0 ? 7 : startDay ;
for (let i=1; i<blanks; i++) { celler(); cellNum++; }
Expand All @@ -141,15 +146,15 @@ var cal = {
for (let i=0; i<startDay; i++) { celler(); cellNum++; }
}

// (E2-3) DAYS OF THE MONTH
// (E2-6) DAYS OF THE MONTH
for (let i=1; i<=daysInMth; i++) {
rowMap[i] = { r : rowNum, c : cellNum };
celler(i);
if (cellNum%7==0 && i!=daysInMth) { rowNum++; rower(); }
cellNum++;
}

// (E2-4) BLANK CELLS AFTER END OF MONTH
// (E2-7) BLANK CELLS AFTER END OF MONTH
if (cal.mon && endDay != 0) {
let blanks = endDay==6 ? 1 : 7-endDay;
for (let i=0; i<blanks; i++) { celler(); cellNum++; }
Expand Down Expand Up @@ -257,4 +262,4 @@ var cal = {
}
}))
};
window.addEventListener("load", cal.init);
window.addEventListener("load", cal.init);

0 comments on commit b0cc490

Please sign in to comment.