JavaScript Calendar

There are a lot of JavaScript Calendars out there, but actually only a few can be very customizable to fit anyone's need. That's why we have created a JavaScript Calendar Component that is very customizable and extendable. You can see our calendar at work right in this page. There are tons of features in this calendar package, such as the list below:
Complete Download (including the NoGray Framework)
Download

Donate:
Twitter

Latest News

Partners

Home Page JavaScript Tools JavaScript Calendar

Download:

Features:

Table of content:

Recent Updates:

Follow us on twitter for the latest updates: Twitter
  • Oct 31st, 2011: A new update is released to fix a bug when changing the months for multi months calendar and the start date value (e.g. 31) is smaller than the last month end date (e.g. 30). Only replace the calendar.js to fix this error.
  • March 18th, 2011: A new update is released to fix a bug with a conflict between the multi_selection and selected_date options when declaring a new calendar.
  • March 12th, 2011: The NoGray framework is updated to be compatible with jQuery. Your calendar implementation should be the same, only replace the JavaScript files in the zip file. If you find any bugs, please contact us with the details.
  • Feb 23rd, 2011: The calendar input field style is changed to inline to match native input field.
  • Feb 21st, 2011: set_start_date() and set_end_date() fixed to update the year drop down select menu.
  • Feb 18th, 2011: server_date_format option was added to allow the customization of the date format sent to the server when a form is submitted. Default value is Y-n-j (e.g. 2011-2-18).

Requirements:

  • The NoGray JavaScript Library
  • Document Type Declaration (DOCTYPE) such as <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Create It

To create a calendar, you'll need to declare a new calendar object in the ng.ready function or when the page is loaded. The calendar can be declared using an input field or stand alone.
Example: Simple calendar example (new window)
HTML:
<input type="text" id="date1" name="date1">
...
<div id="cal_holder_div"></div>
...
later
...
<script type="text/javascript" src="js/ng/ng_all.js"></script>
<script type="text/javascript" src="js/ng/components/calendar.js"></script>
Script:
// calendar connected to an input field
var my_cal1 = new ng.Calendar({input:'date1'});

// stand alone calendar
var my_cal2 = new ng.Calendar({num_months:4,
                            num_col:2});
my_cal2.make('date2');

Try It:

Simple calendar example (new window)
Simple Calendar:


Four Months Calendar (multi date selection):


Different Languages:
DutchChineseArabic

Skinning:

The Calendar Component use CSS style sheet to skin the different parts of the calendar. The calendar css_prefix option will allow for creating different skins in the same CSS file. Additionally, the general configuration css_prefix option will allow the creation of different skins for all the components in the page in different files.

The following images illustrate the different parts with their class names, ids and text values.
NoGray Calendar CSS Style Sheet Details

Options:

You can pass a JavaScript object when creating the calendar as the following:
Option Type Description Default Value
inputString or HTML objectAn HTML input element or id for the input that will hold the component output.
Special Value: for three drop down select menus, you can pass a JavaScript object with the select menus ids or HTML objects as the following:
input: {year: 'year_id', month: 'month_id', date: 'date_id'}
null
objectString or HTML objectAn HTML holding element or id for the object that will hold the component if it's not connected to an input.null
visibleBooleanSet the component as visible (e.g. always open). Used to implement the component inline instead of floatingfalse
placementStringThe placement of the component in relation to the input, it could be one of the following values:
  • The first two letters are for the input position (t for top, b for bottom, l for left, r for right).
  • The last two letters are for the components position (t for top, b for bottom, l for left, r for right).
  • bltl: bottom left of input will match the top left of the component (default of ltr languages).
  • brtr: bottom right of input will match the top right of the component (default of rtl language).
bltl or brtr
offsetObjectAn X and Y values to offset the placement of the component.{x:0, y:0}
disabledbooleanDisable the component when it's createdfalse
date_formatStringA string that represent the display format for the selected date or when. We have adopted the PHP date specification for printing dates. Click here for more details.D, d M Y
Examples:
var my_cal = new ng.Calendar({date_format:'m/d/Y'});
server_date_formatStringA string that represent the date format sent when the the form is submitted. We have adopted the PHP date specification for printing dates. Click here for more details.Y-n-j
Examples:
var my_cal = new ng.Calendar({date_format:'m/d/Y', server_date_format:'Y-m-d'});
num_monthsIntegerThe number of months displayed in each page.1
Examples:
var my_cal = new ng.Calendar({num_months:4});
num_colIntegerThe number of months displayed in one row.3
Examples:
The following example will show four calendars on each page in two rows.
var my_cal = new ng.Calendar({num_months:4, num_col:2});
css_prefixStringThe CSS prefix for skinning the calendar on the same CSS file.ng_cal_
start_dayIntegerThe starting day for the calendar in an numerical format between 0 to 6 (0-Sunday, 6-Saturday)0
start_dateDate, String or ObjectThe starting date for the calendar.today
end_dateDate, String or ObjectThe ending date for the calendar.year+10
allow_selectionbooleanAllow the user to select a date or just view the calendartrue
multi_selectionbooleanAllow the user to select more than one datefalse
max_selectionintegerIf multi_selection is set to true, the total number of dates the user can select. If set to 0, the user will be able to select any number of dates0
languageStringThe specific language for the calendar.ng_config.language
formatterfunctionFunction that will return the default dates text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
selected_date_formatterfunctionFunction that will return the selected date text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
out_of_range_formatterfunctionFunction that will return the out of range dates text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
other_month_formatterfunctionFunction that will return the previous or next month's dates text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
dates_offarrayAn array of dates that represent the holidays or dates offnull
Examples:
var my_cal = new ng.Calendar({
	dates_off:[
			'today+5',	// five days from today
			{date:25, month:11}		// for xmas every year
	]
});
allow_dates_off_selectionbooleanAllow the user to select an off datefalse
dates_off_formatterfunctionFunction that will return the dates off text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
days_offarrayAn array of integers for the off days (0 for Sun, 6 for Sat)null
allow_days_off_selectionbooleanAllow the user to select an off dayfalse
days_off_formatterfunctionFunction that will return the days off text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
weekendarrayAn array of integers for the weekend days (0 for Sun, 6 for Sat)null
allow_weekend_selectionbooleanAllow the user to select an weekend datefalse
weekend_formatterfunctionFunction that will return the weekend dates text.See Example
Examples:
function(dt){
	return ng.Language.translate_numbers(dt.getDate(), this.get_language());
}.bind(this)
force_selectionsarrayAn array of dates that will allow the user to select them regardless of their statusnull
date_on_avaliableobjectAn object of functions that will run when the date is rendered. The key of each function must be a date in the following format m_d_y (1 for Jan) e.g. 1_15_2011. this will refer to the calendar and the table cell is will be passed as an argument.null
Examples:
var dates_func = {
	'1_15_2011': function(id){ng.get(id).set_style('background', '#ff0000')}
};

ng.Calendar({date_on_avaliable:dates_func});
days_textStringA string to select the length of the days text on top of the calendar. Can be either 'char', 'short', 'mid', or 'long'mid
months_textStringA string to select the length of the months text on top of the calendar. Can be either 'short' or 'long'long
right_arrow_imgStringThe path to the right arrow imageSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/right_arrow.gif'
right_arrow_img_disabledStringThe path to the right arrow image disabledSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/right_arrow_dis.gif'
left_arrow_imgStringThe path to the left arrow imageSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/left_arrow.gif'
left_arrow_img_disabledStringThe path to the left arrow image disabledSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/left_arrow_dis.gif'
calendar_imgStringThe path to the calendar imageSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/calendar.gif'
calendar_img_disabledStringThe path to the calendar image disabledSee Example
Examples:
ng_config.assests_dir+'components/calendar/images/calendar_dis.gif'
header_formatStringThe calendar header date display (default is Month Year). This will only take effect in a single calendar implementation. Multiple calendars will have the Year on the top header and the Month on each month table.F Y
close_on_selectbooleanChoose to close the calendar when the user select a date. Defaults to true for a single date selection or false when multi_selection is truetrue unless multi_selection is true
selected_datedate or arrayA date or an array of dates to select when the calendar is creatednull
display_datedateThe date on which the calendar will first load when createdstart_date
buttons_colorstringThe color of the buttons (defaults to the general configuration color: transparent)ng_config.button_color
buttons_over_colorstringThe color of the buttons when the mouse is over them (defaults to the general configuration color: #ffd06e)ng_config.button_over_color
buttons_down_colorstringThe color of the buttons when the user click on them (null for automatic color based on button_over_color)null
buttons_disable_colorstringThe color of the buttons when the calendar is disabled (null for automatic color based on button_color)null
buttons_glossbooleanTo show a gloss reflection on the button or not (defaults to the general configuration: true)ng_config.button_gloss
hide_clear_buttonbooleanWhen multi_selection is true, a clear selection button is visible in the bottom of the calendar. This option will hide the clear button if set to truefalse
hide_view_all_dates_buttonbooleanWhen multi_selection is true, a view selected dates button is visible in the bottom of the calendar. This option will hide the view selected date button if set to truefalse


Events The events are passed to the calendar in the options object when declaring the calendar. For example:
var my_cal = new ng.Calendar({input:'date1',
	events: {
		onSelect: function(dt) { alert(dt); }
	}
});
The this object will represent the calendar in the event function. Review the table below for a complete list of events.
Event Arguments Description
onOpenN/AFires when the component is opened. If the component visible option is set to true, this event won't fire
onCloseN/AFires when the component is closed. If the component visible option is set to true, this event won't fire
onDisableN/AFires when the component is disabled.
onEnableN/AFires when the component is enabled.
onInputPreStartDateN/AFires when a user enters a date before the start_date option.
onInputPostEndDateN/AFires when a user enters a date after the end_date option.
onSelectdate (DATE)Fires when a user select a date. The function receives the selected date as a variable.
onUnSelectdate (DATE)Fires when a user unselect a date. The function receives the unselected date as a variable.
onClearN/AFires when a user clear all selected dates (when the multi_selection option is set to true).
onDateClickdate (DATE)Fires when a user click on any date in the calendar range (regardless if the date is selecable or not). The function will receive the clicked date as an argument and the event object will refer to the click event.
onPreMonthClickN/AFires when a user click the previous month button.
onShowYearN/AFires when a user click the month/year button to show the drop down menus.
onHideYearN/AFires when a user click the month/year button to hide the drop down menus.
onYearClickN/AFires when a user click the month/year button to hide or show the drop down menus.
onNextMonthClickN/AFires when a user click the next month button.
onLoadN/AFires when the calendar is loaded and ready to use.
onMonthChangeN/AFires when visible month is changed.
onRemoveN/AFires when the calendar is removed.