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

enhancement: fill empty days of week with next month. #44 #80

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Settings | Type | Default | Description | Options
theme | string | Default | Define calendar's theme | Default, Midnight Blue, Orange Coral, Royal Navy
format | string | 'mm/dd/yyyy' | Date format | Date string format
titleFormat | string | 'MM yyyy' | Date format for calendar title | Date string format
fillEmptyDays | boolean | false | fills the empty spaces if any present at start and end of the month with previous and next month dates respectively | true, false
eventHeaderFormat | string | 'MM d, yyyy' | Date format for calendar event's title | Date string format
firstDayOfWeek | number | 0 | Displayed first day of the week | 0 (Sunday) - 6 (Saturday)
language | string | 'en' | Calendar's language | en, es, de, pt, fr, nl
Expand Down
49 changes: 47 additions & 2 deletions evo-calendar/js/evo-calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
sidebarToggler: true,
eventDisplayDefault: true,
eventListToggler: true,
calendarEvents: null
calendarEvents: null,
fillEmptyDays: false,
};
_.options = $.extend({}, _.defaults, settings);

Expand Down Expand Up @@ -725,6 +726,9 @@

markup += '<tr class="calendar-body">';
var day = 1;
var prev_day = _.$label.days_in_month[_.$active.month - 1]
? _.$label.days_in_month[_.$active.month - 1] - _.startingDay
: _.$label.days_in_month[11] - _.startingDay;
for (var i = 0; i < 9; i++) { // this loop is for is weeks (rows)
for (var j = 0; j < _.$label.days.length; j++) { // this loop is for weekdays (cells)
if (day <= _.monthLength && (i > 0 || j >= _.startingDay)) {
Expand All @@ -737,8 +741,49 @@
var thisDay = _.formatDate(_.$label.months[_.$active.month]+' '+day+' '+_.$active.year, _.options.format);
markup += '<div class="day" role="button" data-date-val="'+thisDay+'">'+day+'</div>';
day++;
prev_day=0
} else {
markup += '<td>';

var current_month = _.$active.month;
var current_year = _.$active.year;
if (prev_day > 15) {
//assuming that startingDay will not exceed 15 days i.e we don't have to build empty divs more tham 15 per month
if (current_month - 1 < 0) {
current_month = 11;
current_year -= 1;
} else current_month -= 1;
} else {
var current_month = _.$active.month;
var current_year = _.$active.year;
if (current_month + 1 > 11) {
current_month = 0;
current_year += 1;
} else current_month += 1;
}
var dayClass = "calendar-day";
if (
_.$label.days[j] === _.initials.weekends.sat ||
_.$label.days[j] === _.initials.weekends.sun
) {
dayClass += " --weekend"; // add '--weekend' to sat sun
}
if (_.options.fillEmptyDays) {
markup += '<td class="' + dayClass + '">';
var thisDay = _.formatDate(
_.$label.months[current_month] +
" " +
(prev_day + 1) +
" " +
current_year,
_.options.format
);
markup += `<div class="day" style="opacity:0.5" role="button" data-date-val="${thisDay}">${
prev_day + 1
}</div>`;
prev_day++;
} else {
markup += "<td>";
}
}
markup += '</td>';
}
Expand Down
Loading