Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format code with standardrb and standardjs #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 62 additions & 71 deletions assets/js/calendar.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
today = new Date();
currentMonth = today.getMonth();
currentYear = today.getFullYear();
selectYear = document.getElementById("year");
selectMonth = document.getElementById("month");
today = new Date()
currentMonth = today.getMonth()
currentYear = today.getFullYear()
selectYear = document.getElementById('year')
selectMonth = document.getElementById('month')

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

monthAndYear = document.getElementById("monthAndYear");
showCalendar(currentMonth, currentYear);
monthAndYear = document.getElementById('monthAndYear')
showCalendar(currentMonth, currentYear)


function next() {
currentYear = (currentMonth === 11) ? currentYear + 1 : currentYear;
currentMonth = (currentMonth + 1) % 12;
showCalendar(currentMonth, currentYear);
function next () {
currentYear = (currentMonth === 11) ? currentYear + 1 : currentYear
currentMonth = (currentMonth + 1) % 12
showCalendar(currentMonth, currentYear)
}

function previous() {
currentYear = (currentMonth === 0) ? currentYear - 1 : currentYear;
currentMonth = (currentMonth === 0) ? 11 : currentMonth - 1;
showCalendar(currentMonth, currentYear);
function previous () {
currentYear = (currentMonth === 0) ? currentYear - 1 : currentYear
currentMonth = (currentMonth === 0) ? 11 : currentMonth - 1
showCalendar(currentMonth, currentYear)
}

function jump() {
currentYear = parseInt(selectYear.value);
currentMonth = parseInt(selectMonth.value);
showCalendar(currentMonth, currentYear);
function jump () {
currentYear = parseInt(selectYear.value)
currentMonth = parseInt(selectMonth.value)
showCalendar(currentMonth, currentYear)
}

function showCalendar(month, year) {

let firstDay = (new Date(year, month)).getDay();

tbl = document.getElementById("calendar-body"); // body of the calendar

// clearing all previous cells
tbl.innerHTML = "";

// filing data about month and in the page via DOM.
monthAndYear.innerHTML = months[month] + " " + year;
selectYear.value = year;
selectMonth.value = month;

// creating all cells
let date = 1;
for (let i = 0; i < 6; i++) {
// creates a table row
let row = document.createElement("tr");

//creating individual cells, filing them up with data.
for (let j = 0; j < 7; j++) {
if (i === 0 && j < firstDay) {
cell = document.createElement("td");
cellText = document.createTextNode("");
cell.appendChild(cellText);
row.appendChild(cell);
}
else if (date > daysInMonth(month, year)) {
break;
}

else {
cell = document.createElement("td");
cellText = document.createTextNode(date);
if (date === today.getDate() && year === today.getFullYear() && month === today.getMonth()) {
cell.classList.add("bg-primary", "text-white", "shadow-lg");
} // color today's date
cell.appendChild(cellText);
row.appendChild(cell);
date++;
}


}

tbl.appendChild(row); // appending each row into calendar body.
function showCalendar (month, year) {
const firstDay = (new Date(year, month)).getDay()

tbl = document.getElementById('calendar-body') // body of the calendar

// clearing all previous cells
tbl.innerHTML = ''

// filing data about month and in the page via DOM.
monthAndYear.innerHTML = months[month] + ' ' + year
selectYear.value = year
selectMonth.value = month

// creating all cells
let date = 1
for (let i = 0; i < 6; i++) {
// creates a table row
const row = document.createElement('tr')

// creating individual cells, filing them up with data.
for (let j = 0; j < 7; j++) {
if (i === 0 && j < firstDay) {
cell = document.createElement('td')
cellText = document.createTextNode('')
cell.appendChild(cellText)
row.appendChild(cell)
} else if (date > daysInMonth(month, year)) {
break
} else {
cell = document.createElement('td')
cellText = document.createTextNode(date)
if (date === today.getDate() && year === today.getFullYear() && month === today.getMonth()) {
cell.classList.add('bg-primary', 'text-white', 'shadow-lg')
} // color today's date
cell.appendChild(cellText)
row.appendChild(cell)
date++
}
}

tbl.appendChild(row) // appending each row into calendar body.
}
}


// check how many days in a month code from https://dzone.com/articles/determining-number-days-month
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
function daysInMonth (iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate()
}
Loading