Calendar. A lightweight calendar builder

About

What is this about?

Calendar is a javascript component for creating calendars.
Unlike most calendar plugins, this one doesn't generate markup, it just generates the calendar data as a javascript object.
You need to provide a view (function, backbone view, angular directive, etc) and render the data in whichever way you want.

This is not ment to be an out-of-the-box solution, instead the goal is to provide a solid fundation where to build a calendar widget.
The Calendar builder is build using pure javascript so you don't need to depend on any 3rd party libraries.

Get Started

Here's How You Use It

Just create a new Calendar object and call build

         
var model = new Calendar();
clndr = model.build();
          
        

This will generate the following object:

          
/* clndr = */ { 
  prev: true,  // Can be moved to the previous month?
  next: true,  // Can be moved to the next month?
  month: 10,   // Current month number (1 to 12)
  year: 2014,  // Year
  weeks: [     // Array of weeks
    {
      num: 44, // Number of the week in the year
      days: [  // Array of days in this week (7)
        {
          day:        27, // day number of the month
          wkDay:      1, // Day of the week [0-6]
          disabled:   false, // Days outisde min-max limits are disabled
          otherMonth: false,
          selected:   false,
          timestamp:  1414364400000,
          weekend:    false // Sa or Su
        },
        ...
      ]
    },
    ...
  ], 
}
          
        

Cofiguration

What about the configuration options?

Here they are.

NameTypeDescription
cursorDateThe starting page of the calendar, only month and year are taken into account
selectedDateThe selected date
minDateDateThe minimum allowed date
maxDateDateThe maximum allowed date
firstDayNumberThe starting day of the week, by default is 0=Sunday, you can change it to 1=Mon, 2=Tue, etc;
numMonthsNumberThe number of months to generate, by default = 1
numWeeksNumberForce each calendar page to have 'n' weeks, use 'auto' for dynamic calculation
onDayInfoFunctionCallback decorator to add extra info for a day.
                
function(dayData, date) {
  dayData.newField = date.toString(); 
}
                
              
onWeekInfoFunctionCallback decorator to add extra info for a week.
                
function(weekData) {
  weekData.cloudy = false; 
}
                
              

Example:
Select the 25th of December.
Min date 1st Dec.
Max date 31st Dec.

          
var christmas = new Date();
christmas.setMonth(11);
christmas.setDate(25);

var decStart = new Date( christmas.getFullYear(), 11, 1);
var decEnd   = new Date( christmas.getFullYear(), 11, 31);

var clndr = new Calendar({
  firstDay: 1,
  numWeeks: 6, 
  selected: christmas,
  minDate:  decStart,
  maxDate:  decEnd
}),