Calendario: A Flexible Calendar Plugin

Today we want to share a flexible calendar concept with you. Calendars can be a very tricky thing when it comes to their layout and responsiveness. This is an experiment for trying out some grid layouts that can be applied to calendars. We’ve created a jQuery plugin for the calendar itself and you can see some examples of how to use it in the demos. The aim is to provide a suitable layout for both, small and big screens and keeping the calendar structure fluid when possible. On large screens we want to show a grid-based layout while on smaller screens, we want to simply stack the days of the month.

Please note that the demos will only work as intended in browsers that support the new CSS properties used here, especially calc().

The calendar designs are based on these two beauties found on Dribbble:

The calendar will consist of a head for the listing of the weekdays and a body with rows for the days of the month. Each “cell” will contain the date and weekday (if applicable) and we control the height of the rows by setting the right class to the container (four, five or six rows). The styling for the default calendar is defined in calendar.css.
Note that a cell that contains some content/event will look as follows:

Note that the weekday of each cell is hidden by default because we have the calendar head with the weekdays. The ones in the cell are especially for the case when we apply media queries to reset the layout of the calendar to be stacked vertically. Here we will want to show the weekdays for each day.

It’s clear that a calendar could/should be represented by a table, but due to some table rendering differences between the browsers (especially IE9), we chose not to use it. You can of course adjust the plugin to output a table, though.

The important part of making the calendar grid fluid is the styling of the row and the div (or the “cell”):

So, we define different heights depending on the amount of rows we’ll have, using calc() where we know that the result is not a round number. For the inner div we will set the width to be 100 divided by 7.

// return the year that is currently being viewed
getYear()
// return the month that is currently being viewed (1-12)
getMonth()
// returns the name of the month that is currently being viewed
getMonthName()
// returns the content division inside the cell associated to day "day"
getCell( day )
// sets the data to the calendar. Merges the contents of the passed caldata with the one already set (if any)
setData( caldata )
// shows the calendar for today's month and year
// month is from 1-12
gotoNow( callback )
// shows the calendar for month "month" and year "year"
// month is from 1-12
goto( month, year, callback )
// goes back one month in the calendar
gotoPreviousMonth( callback )
// goes back one year in the calendar
gotoPreviousYear( callback )
// goes further one month in the calendar
gotoNextMonth( callback )
// goes further one year in the calendar
gotoNextYear( callback )

You can use setData to add content to the calendar. You can see examples for that in the demo files.

The basic styling is defined in the calendar.css file and you can see examples of how to modify the calendar style and add to it in the custom CSS files.

ML is a freelance web designer and developer with a passion for interaction design. She studied Cognitive Science and Computational Logic and has a weakness for the smell of freshly ground peppercorns.

Feedback113

This calendar is great, just one question one i had being a designer i have modified what i want the dates for the empty cells like for EX:july 2013 has 6 empty cells of the week for august i want to fill the dates for august in that

This is great, but adding events dynamically is causing me some trouble. I have a form where the user can enter the date for a new event, so I can’t hard-code the date like in your example. That is, I can’t do this:cal.setData( {"07-15-2013" : "<div >My event here</div>"} );

mary good job, but I need to dynamically create events.
My situation is this, I have pdf files that name with the date format CALDATA and create events and put everything inside a jquery object but when I go to the plugin it does not return anything

Anyone managed to get a popup box working with this? User clicks a date and then clicks the link in that date to get more info on that event. (there could be more than one event on that day so putting the data in the normal slide up box wont really work. Using the demo 2 layout here. thanks

removing the calculations and leaving just the percentage. I guess IE10 doesn’t calculate very accurately, so it pushes the last element in a row on the calendar over to the next line? So modify that chunk to this:

Hi,
the calendar look beautiful!
I still does not understand how you load the data from the data.js or another source?
I am working on django python and would love to know how to implement it on my project.
thank for your help

This isfantastic. I’m tryingt o use demo 1, but with the show events vertical slide like in demo 2 (instead of just direct link), but no success so far. Anybody has tried to do the same with success and would like to share? Thanks in advance.