Skip to content
Permalink
Browse files

add view endDate option and methods

this enables a user to set the end of a range of selectable dates
  • Loading branch information...
Corey Holland
Corey Holland committed Oct 24, 2015
1 parent 35f21cc commit 295546405ae61d43680a017a90a8783b616d0091
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/main.js
@@ -19,7 +19,7 @@ var Kalendae = function (targetElement, options) {
$container = self.container = util.make('div', {'class':classes.container}),
calendars = self.calendars = [],
startDay = moment().day(opts.weekStart),
vsd,
vsd, ved,
columnHeaders = [],
$cal,
$title,
@@ -55,6 +55,12 @@ var Kalendae = function (targetElement, options) {
}
self.viewStartDate = vsd.date(1);

//set the end range
if (!!opts.endDate) {
ved = moment(opts.endDate, opts.format);
self.endDate = ved;
}

//process default selected dates
self._sel = [];
if (!!opts.selected) {
@@ -245,6 +251,7 @@ Kalendae.prototype = {
direction :'any', /* past, today-past, any, today-future, future */
directionScrolling :true, /* if a direction other than any is defined, prevent scrolling out of range */
viewStartDate :null, /* date in the month to display. When multiple months, this is the left most */
endDate :null, /* date calendar cannot scroll or select past */
blackout :null, /* array of dates, or function to be passed a date */
selected :null, /* dates already selected. can be string, date, or array of strings or dates. */
mode :'single', /* single, multiple, range */
@@ -414,6 +421,8 @@ Kalendae.prototype = {
addSelected : function (date, draw) {
date = moment(date, this.settings.format).hours(12);

if (date.isAfter(this.endDate, 'day')) return false; // safety for when it wasnt a click

if(this.settings.dayOutOfMonthClickable && this.settings.mode !== 'range'){ this.makeSelectedDateVisible(date); }

switch (this.settings.mode) {
@@ -535,8 +544,8 @@ Kalendae.prototype = {
klass.push(classes.dayOutOfMonth);
else klass.push(classes.dayInMonth);

if (!(this.blackout(day) || this.direction(day) || (day.month() != month.month() && opts.dayOutOfMonthClickable === false)) || s>0 )
klass.push(classes.dayActive);
if (!(this.blackout(day) || this.direction(day) || day.isAfter(this.endDate, 'day') || (day.month() != month.month() && opts.dayOutOfMonthClickable === false)) || s>0 )
klass.push(classes.dayActive);

if (this.blackout(day))
klass.push(classes.dayBlackout);
@@ -555,6 +564,19 @@ Kalendae.prototype = {

day.add(1, 'days');
} while (++j < 42);

if (opts.endDate && month.isSame(this.endDate, 'month')) {
this.disableNextMonth = true;
this.disableNextYear = true;
util.addClassName(this.container, classes.disableNextMonth);
util.addClassName(this.container, classes.disableNextYear);
} else {
this.disableNextMonth = false;
this.disableNextYear = false;
util.removeClassName(this.container, classes.disableNextMonth);
util.removeClassName(this.container, classes.disableNextYear);
}

month.add(1, 'months');
} while (++i < c);

0 comments on commit 2955464

Please sign in to comment.
You can’t perform that action at this time.