Add the jsCalendar code on your HTML's <head> section.
<!-- jsCalendar style -->
<link rel="stylesheet" type="text/css" href="jsCalendar.css">
<!-- jsCalendar script -->
<script type="text/javascript" src="jsCalendar.js"></script>
Then, add a jsCalendar element on your page's <body> section
<!-- my calendar -->
<div class="auto-jsCalendar"></div>
*All .auto-jsCalendar elements are initiated as a calendar, when the page's load event fire.
Since jsCalendar has a GitHub and an NPM project, you can use free CDNs that distributes such projects.
Two such well-known CDNs are the Unpkg CDN and the JsDelivr CDN.
jsCalendar using the Unpkg CDN
<!-- jsCalendar v1.4.5 Javascript and CSS from unpkg cdn -->
<script src="https://unpkg.com/simple-jscalendar@1.4.5/source/jsCalendar.min.js" integrity="sha384-F3Wc9EgweCL3C58eDn9902kdEH6bTDL9iW2JgwQxJYUIeudwhm4Wu9JhTkKJUtIJ" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://unpkg.com/simple-jscalendar@1.4.5/source/jsCalendar.min.css" integrity="sha384-CTBW6RKuDwU/TWFl2qLavDqLuZtBzcGxBXY8WvQ0lShXglO/DsUvGkXza+6QTxs0" crossorigin="anonymous">
jsCalendar using the JsDelivr CDN
<!-- jsCalendar v1.4.5 Javascript and CSS from jsdelivr npm cdn -->
<script src="https://cdn.jsdelivr.net/npm/simple-jscalendar@1.4.5/source/jsCalendar.min.js" integrity="sha384-F3Wc9EgweCL3C58eDn9902kdEH6bTDL9iW2JgwQxJYUIeudwhm4Wu9JhTkKJUtIJ" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/simple-jscalendar@1.4.5/source/jsCalendar.min.css" integrity="sha384-CTBW6RKuDwU/TWFl2qLavDqLuZtBzcGxBXY8WvQ0lShXglO/DsUvGkXza+6QTxs0" crossorigin="anonymous">
Full example with all the files and their integrity hashes using unpkg here and using jsdelivr here (the hashes are the same).
Notice: When using CDNs, always include integrity hashes.
The jsCalendar.css includes 3 basic themes. The "Default Theme", the "Material Theme" and "Classic Theme". For additional themes, check the Themes section.
Of course, all these themes are just a few lines of CSS code, thus you can easily create your own theme according to your needs.
The default theme of the jsCalendar is simple and clear.
<!-- Default theme -->
<div class="auto-jsCalendar"></div>
For a minimalistic approach, try the simple Material theme.
<!-- Material theme -->
<div class="auto-jsCalendar material-theme"></div>
For a more old fashion look, try the Classic theme.
<!-- Classic theme -->
<div class="auto-jsCalendar classic-theme"></div>
Each one of the built-in themes has 5 color versions:
blue, yellow, orange, red, green
The blue color is the default.
For example the green version of the default theme is
<!-- Green theme -->
<div class="auto-jsCalendar green"></div>
Or give a try on the red version of the material theme.
<!-- Red material theme -->
<div class="auto-jsCalendar material-theme red"></div>
You can customize each jsCalendar instance by defining data-* parameters on its HTML element or by passing them on the dynamic javascript creation of the calendar.
Set the calendar's active date.
Name | date |
Values | Date string |
Default | "now" |
<!-- Calendar date 01/12/2018 -->
<div class="auto-jsCalendar"
data-date="01/12/2018"></div>
Enable/Disable month's navigation buttons.
Name | navigator |
Values | true | false |
Default | true |
<!-- No navigator calendar -->
<div class="auto-jsCalendar"
data-navigator="false"></div>
Set the month's navigation position.
Name | navigatorPosition |
Values | both | left | right |
Default | both |
<!-- Set navigator on right -->
<div class="auto-jsCalendar"
data-navigator-position="right"></div>
Enable/Disable date's number zero fill.
Name | zeroFill |
Values | true | false |
Default | false |
<!-- Add zero prefix -->
<div class="auto-jsCalendar"
data-zero-fill="true"></div>
Custom month string format.
Name | monthFormat |
Values | <string> |
Default | "month" |
Format string codes
Code | Description | Output |
---|---|---|
MONTH | Month's full name | February |
month | Month's full name | February |
MMM | Month's first 3 letters | Feb |
mmm | Month's first 3 letters | Feb |
## | Month's number (zero-filled) | 02 |
# | Month's number | 2 |
YYYY | Year | 2017 |
yyyy | Year | 2017 |
Codes can be combined. For example, for the February
month of the year 2017, the code "##/YYYY" would
display 02/2017
<!-- Custom month format -->
<div class="auto-jsCalendar"
data-month-format="month YYYY"></div>
Custom day of the week string format.
Name | dayFormat |
Values | <string> |
Default | "D" |
Format string codes
Code | Description | Output |
---|---|---|
DAY | Day's full name | Monday |
day | Day's full name | Monday |
DDD | Day's first 3 letters | Mon |
ddd | Day's first 3 letters | Mon |
DD | Day's first 2 letters | Mo |
dd | Day's first 2 letters | Mo |
D | Day's first letter | M |
<!-- Custom day format -->
<div class="auto-jsCalendar"
data-day-format="DDD"></div>
Select the first day of the week.
Name | firstDayOfTheWeek |
Alias | fdotw (alias bugged on v1.4.4) |
Values | <string> | <number> |
Default | 1 |
Values format
Type | Description | Example |
---|---|---|
String | Day's full name (based on the language) | "Monday" |
String | Day's number 1-7 starting from Sunday | "2" |
Number | Day's number 1-7 starting from Sunday | 2 |
<!-- Select Monday as the first day of the week -->
<div class="auto-jsCalendar"
data-first-day-of-the-week="2"></div>
<!-- Equivalent using alias -->
<div class="auto-jsCalendar"
data-fdotw="2"></div>
Change calendar language.
Name | language |
Values | <string> |
Default | "en" |
Each language, other than English, is loaded from a separate script.
So first you need to load the languages on the HTML's <head>.
<!-- Load Greek language -->
<script type="text/javascript"
src="jsCalendar.lang.gr.js"></script>
<!-- Load German language -->
<script type="text/javascript"
src="jsCalendar.lang.de.js"></script>
and then you can use any loaded language.
<!-- With German language -->
<div class="auto-jsCalendar"
data-language="de"></div>
Supported languages (alphabetical order)
Language | Code | Released on |
---|---|---|
Arabic | ar | v1.4.5 |
Belarusian | be | v1.4.4 |
Catalan | ca | v1.4.4 |
Chinese | zh | |
Dutch | nl | v1.4.4 |
Dutch | nl | |
English | en | |
French | fr | |
German | de | |
Greek | gr | |
Hungarian | hu | v1.4.3 |
Italian | it | |
Japanese | ja | |
Korean | ko | v1.4.5 |
Norwegian | no | v1.4.3 |
Occitan | oc | v1.4.5 |
Polish | pl | v1.4.5 |
Portuguese | pt | v1.4.3 |
Russian | ru | |
Slovak | sk | v1.4.3 |
Spanish | es | |
Swedish | sv | v1.4.4 |
Thai | th | v1.4.5 |
Turkish | tr | v1.4.3 |
Ukrainian | uk | v1.4.3 |
Vietnamese | vi | v1.4.5 |
The supported languages codes are based on the ISO 639-1 codes.
Set a Minimum/Maximum date for the calendar.
Name | min | max |
Values | false | date |
Default | false |
Min-date 01/01/2017 (January 2017 and later)
<!-- Set min date -->
<div class="auto-jsCalendar"
data-date="01/02/2017"
data-min="01/01/2017"></div>
Max-date 01/03/2017 (before March 2017)
<!-- Set max date -->
<div class="auto-jsCalendar"
data-date="01/02/2017"
data-max="01/03/2017"></div>
Min-date 01/02/2017 and Max-date 01/02/2017
(between January 2017 and March 2017)
<!-- Set min-max date -->
<div class="auto-jsCalendar"
data-date="01/02/2017"
data-min="01/01/2017"
data-max="01/03/2017"></div>
For dynamic creation of the calendar, you can use the Javascript API.
Create a calendar on an HTML element. Throws an error if date does not exist.
API syntax
Syntax 1 | jsCalendar.new( target | options ); |
Syntax 2 | jsCalendar.new( target [, date] [, options] ); |
Syntax 3 | new jsCalendar( target | options ); |
Syntax 4 | new jsCalendar( target [, date] [, options] ); |
Parameters
target | HTML element |
date | Date Object | Timestamp Number | String |
options | Object |
So here is the full code
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Dynamic create it -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
jsCalendar.new(element);
</script>
The target element for the calendar
target | HTML element | v1.2 |
target | String | v1.4 |
<!-- My calendar target -->
<div id="my-calendar-target"></div>
<!-- Code to get the target element -->
<script type="text/javascript">
// Get the target element
var target = document.getElementById("my-calendar-target");
</script>
<!-- id calendar target -->
<div id="id-calendar-target"></div>
<!-- Code to get the target element -->
<script type="text/javascript">
// String identifier of the target element
var target = "#id-calendar-target";
</script>
<!-- class calendar target -->
<div class="class-calendar-target"></div>
<!-- Code to get the target element -->
<script type="text/javascript">
// String identifier of the target element
var target = ".class-calendar-target";
</script>
The date for the calendar
date | Date Object | Timestamp Number | String |
Format date
Type | Description | Example |
---|---|---|
Date Object | Using the javascript date | new Date() |
Timestamp Number | Using a timestamp | new Date(2017, 0, 30).getTime() |
Timestamp Number | Using a timestamp | 1485727200000 |
String | Date string | "30/01/2017" |
String | Date string | "30-01-2017" |
String | Date string | "now" |
Full code example
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Dynamic create it -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
jsCalendar.new(element, "30/01/2017");
</script>
The options for the calendar
options | Object |
Options items
Name | Values | |
---|---|---|
target | HTML element | v1.2 |
date | Date | Number | String | v1.2 |
navigator | true | false | v1.2 |
navigatorPosition | "both" | "left" | "right" | v1.2 |
zeroFill | true | false | v1.2 |
monthFormat | String | v1.2 |
dayFormat | String | v1.2 |
firstDayOfTheWeek | String | Number | v1.3 |
fdotw | String | Number | v1.3 |
language | String | v1.2 |
min | false | Date | v1.4 |
max | false | Date | v1.4 |
All the options, except the target, are the same as the HTML element parameters.
Code example 1
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Dynamic create it -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
jsCalendar.new(element, "30/01/2017", {
navigator : true,
navigatorPosition : "left",
zeroFill : false,
monthFormat : "month YYYY",
dayFormat : "DDD",
language : "en"
});
</script>
Code example 2
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Dynamic create it -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
jsCalendar.new({
target : element,
date : "30/01/2017",
navigator : true,
navigatorPosition : "right",
zeroFill : true,
monthFormat : "month",
dayFormat : "DD",
language : "gr"
});
</script>
For dynamic control of the calendar, you can use the Javascript API.
Move to the next month.
API syntax
Syntax 1 | .next() |
Syntax 2 | .next(n) |
Parameters
None | Go to next month |
n | Go to month + n |
Example code
<!-- Next month button -->
<button id="my-button">Next</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Go to the next month
myCalendar.next();
}, false);
</script>
Move to the previous month.
API syntax
Syntax 1 | .previous() |
Syntax 2 | .previous(n) |
Parameters
None | Go to previous month |
n | Go to month - n |
Example code
<!-- Button -->
<button id="my-button">Previous</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Go to the previous month
myCalendar.previous();
}, false);
</script>
Example code
<!-- Button -->
<button id="my-button">Set date</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Set date
myCalendar.set("30/01/2017");
}, false);
</script>
Refreshes the calendar based on the background information of the library, updating the HTML of the calendar (mainly for developers). If a date is provided, the calendar will refresh to that date (exactly like the goto method).
API syntax
Syntax 1 | .refresh() |
Syntax 2 | .refresh(date) |
Please note that the date parameter will change the view date/month and not the active date of the calendar. To change the active date you can use the set method.
Example code
<!-- Button -->
<button id="my-button">Refresh</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Refresh
myCalendar.refresh();
}, false);
</script>
Go to a specific date.
API syntax
Syntax | .goto(date) |
Please note that the date parameter will change the view date/month and not the active date of the calendar. To change the active date you can use the set method.
Example code
<!-- Button -->
<button id="my-button">Goto</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Goto
myCalendar.goto("30/01/2017");
}, false);
</script>
Go to the set date.
API syntax
Syntax | .reset() |
Example code
<!-- Button -->
<button id="my-button">Reset</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Reset
myCalendar.reset();
}, false);
</script>
Example code
<!-- Button -->
<button id="my-button">Change language</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the button
var button = document.getElementById("my-button");
// Add a button event
button.addEventListener("click", function(){
// Change language
myCalendar.setLanguage("de");
}, false);
</script>
*You can find a list of all the available languages here.
Set a Minimum/Maximum date for the calendar.
API syntax
Syntax | .min(false | date) |
Syntax | .max(false | date) |
Example code
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Create the calendar -->
<script type="text/javascript">
// Create the calendar
var myCalendar = jsCalendar.new("#my-calendar");
// Limit to only current month
myCalendar.min("now");
myCalendar.max("now");
</script>
Some more things in the Javascript API.
Get the version of jsCalendar
API syntax
Syntax | jsCalendar.version |
Example code
<!-- Print version -->
You are using<br>jsCalendar <span id="version"></span>
<script type="text/javascript">
document.getElementById("version").textContent = jsCalendar.version;
</script>
Add a click event on the calendar
API syntax
On month change | .onMonthChange(function(event, date){ ... }) |
On day click | .onDateClick(function(event, date){ ... }) |
*The events are called on a user click event on the calendar, so there will be no event, for example, while using .next().
Example code
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Outputs -->
Day click : <br>
<input id="my-input-a"><br>
Month change : <br>
<input id="my-input-b"><br>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element);
// Get the inputs
var inputA = document.getElementById("my-input-a");
var inputB = document.getElementById("my-input-b");
// Add events
myCalendar.onDateClick(function(event, date){
inputA.value = date.toString();
});
myCalendar.onMonthChange(function(event, date){
inputB.value = date.toString();
});
</script>
Add render handlers on the calendar to make advance custom changes
API syntax
On month render | .onMonthRender(function(index, element, info){ ... }) |
On day render | .onDayRender(function(index, element, info){ ... }) |
On date render | .onDateRender(function(date, element, info){ ... }) |
*The render handlers are called after every corresponding render.
Example code
<!-- My auto calendar element -->
<div id="my-calendar"
data-first-day-of-the-week="2"></div>
<!-- Apply render handlers to the second calendar -->
<script type="text/javascript">
// Get the auto-calendar (we have to wait the window load event)
var calendar = jsCalendar.new('#my-calendar');
// Make changes on the month element
calendar.onMonthRender(function(index, element, info) {
// Show month index
var month = index + 1;
element.textContent += ' (' + (month > 9 ? '' : '0') + month + '/' + (info.start.getYear() + 1900) + ')';
});
// Make changes on the day name elements
calendar.onDayRender(function(index, element, info) {
// If weekend, make it red
if (index == 0 || index == 6) {
element.style.color = '#c32525';
}
});
// Make changes on the date elements
calendar.onDateRender(function(date, element, info) {
// Make weekends bold and red
if (!info.isCurrent && (date.getDay() == 0 || date.getDay() == 6)) {
element.style.fontWeight = 'bold';
element.style.color = (info.isCurrentMonth) ? '#c32525' : '#ffb4b4';
}
});
// Refresh layout
calendar.refresh();
</script>
To prevent the calendar from rendering between custom changes, you can use the freeze related functions.
API syntax
Prevent rendering from running | .freeze() | - |
Restore rendering functionality | .unfreeze() | - |
Get freeze state | .isFrozen() | returns: true | false |
Select days on the calendar
API syntax
Select | .select(date | date array) | v1.2 |
Unselect | .unselect(date | date array) | v1.2 |
Clear select | .clearselect() | v1.2 |
Clear select | .clearSelected() | v1.4 |
Get selected | .getSelected(select options | None) | v1.4 |
Check date API syntax
Check if selected | .isSelected(date) | v1.4 |
Check if visible | .isVisible(date) | v1.4 |
Check if in month | .isInMonth(date) | v1.4 |
Select options v1.4
Attribute | Value | Description |
sort | true | Sort in ascending order |
sort | "asc" | "desc" | Sort in ascending/descending order |
type | "timestamp" | Format dates as timestamp integer |
type | "date" | Format dates as javascript Date |
type | String with month format or day format | Format dates as custom string |
*Examples below.
Example code
<!-- Buttons -->
<button id="my-button-a">Select</button>
<button id="my-button-b">Unselect</button>
<button id="my-button-c">Clear</button>
<!-- My calendar element -->
<div id="my-calendar"></div>
<!-- Outputs -->
Day click : <br>
<input id="my-input-a"><br>
Month change : <br>
<input id="my-input-b"><br>
<!-- Create the calendar -->
<script type="text/javascript">
// Get the element
var element = document.getElementById("my-calendar");
// Create the calendar
var myCalendar = jsCalendar.new(element,"1-1-2017");
// Get the buttons
var buttonA = document.getElementById("my-button-a");
var buttonB = document.getElementById("my-button-b");
var buttonC = document.getElementById("my-button-c");
// Add events
buttonA.addEventListener("click", function() {
myCalendar.select([
"01/01/2017",
"02/01/2017",
"03/01/2017",
"05/01/2017"
]);
}, false);
buttonB.addEventListener("click", function() {
myCalendar.unselect([
"05/01/2017"
]);
}, false);
buttonC.addEventListener("click", function() {
myCalendar.clearselect();
}, false);
</script>
Example .getSelected()
myCalendar.getSelected();
// Returns [1483567200000, 1483394400000, 1483308000000, 1483221600000]
myCalendar.getSelected({sort : true});
// Returns [1483221600000, 1483308000000, 1483394400000, 1483567200000]
myCalendar.getSelected({sort : "desc", type : "DD-MM-YYYY"});
// Returns ["05-01-2017", "03-01-2017", "02-01-2017", "01-01-2017"]
myCalendar.getSelected({sort : "asc", type : "date"});
/*
* Returns [
* Sun Jan 01 2017 00:00:00 GMT+0200 (GTB Standard Time),
* Mon Jan 02 2017 00:00:00 GMT+0200 (GTB Standard Time),
* Tue Jan 03 2017 00:00:00 GMT+0200 (GTB Standard Time),
* Thu Jan 05 2017 00:00:00 GMT+0200 (GTB Standard Time)
* ]
*/
The library maintains a list of jsCalendar instances created, based on the id of their target. This is helpful if you want to control an automatically created calendar. Calendars that their target element does not have an id, are not saved but you can manually binding them to a custom id.
API methods syntax
Get instance | jsCalendar.get( id ) |
Set instance | jsCalendar.set( id, calendar ) |
Remove instance from the list | jsCalendar.del( id ) |
Parameters
id | The string id of the target element or a custom id |
calendar | A jsCalendar instance |
Example code
<!-- My calendar element -->
<div class="auto-jsCalendar" id="my-calendar"></div>
Get auto-jsCalendar by target id<br>
<input id="my-input" value="checking"/><br>
<!-- Get the calendar object through javascript -->
<script type="text/javascript">
// You have to wait the load event
window.addEventListener('load', function() {
// Get input
var input = document.getElementById('my-input');
// Get the calendar
var calendar = jsCalendar.get('#my-calendar');
// Show result
input.value = (calendar instanceof jsCalendar) ?
'OK' :
'Failed';
}, false);
// The jsCalendar creates the auto-jsCalendar onload,
// so you have to wait for the event and this code must
// be under the jsCalendar.js script tag
</script>
Calendar tools methods
API methods syntax
String to Date | jsCalendar.tools.parseDate(date) | v1.4.1 |
String to Date | jsCalendar.tools.stringToDate(date) | v1.4.1 |
Date to String | jsCalendar.tools.dateToString(date, string_format, language_code = "en") | v1.4.1 |
*jsCalendar.tools.stringToDate is alias of JsCalendar.tools.parseDate.
*string_format parameter is a string with month format or day format.
Example code
<!-- Inputs to show results -->
Testing stringToDate:
<input id="my-input-a" value="checking"/><br>
Testing dateToString:
<input id="my-input-b" value="checking"/><br>
<!-- Test the methods -->
<script type="text/javascript">
// Get the elements
var inputA = document.getElementById("my-input-a");
var inputB = document.getElementById("my-input-b");
// Express 01-01-2018 in string and date
var str = "01-01-2018";
var date = new Date(2018 , 0, 1);
// Parse/Convert dates
var str2date = jsCalendar.tools.stringToDate(str);
var date2str = jsCalendar.tools.dateToString(date, "DD-MM-yyyy");
// Check results
inputA.value = (str2date.getTime() === date.getTime()) ? "pass" : "failed";
inputB.value = (date2str === str) ? "pass" : "failed";
</script>
Testing stringToDate: Calendar exposes an API that allows the extension of its functionalities by developing extension.
Loading Extension API syntax
Syntax | .ext(extention_name, extention_object) |
Parameters
extention_name | The string name of the extension to load. This should be unique for each extension. |
extention_object | The ExtentionObject of the extension. |
To utilise an extension, it should be loaded before creating a calendar. Thus, it is suggested to load any extension script just after loading the jsCalendar library.
The ExtentionObject is an object that can optionally include handlers that will be called from jsCalendar upon the corresponding event.
ExtentionObject |
{ init: function(instance) { ... }, create: function(instance, elements) { ... }, update: function(instance, month) { ... } } |
Handlers
init | Will be called just after the initialisation of the calendar's parameters. (optional) |
create | Will be called just after the creation of the calendar's HTML elements. The calendar's elements will be passed as a parameter. (optional) |
update | Will be called just after the UI update of the calendar. The information of the active month will be passed as a parameter. (optional) |
More themes related informations are provided in this section. Additionally, you can check the Themes section for more themes.
Add a custom theme colour on the built in themes by editing the example code below
<!-- New purple colour -->
<style type="text/css">
.jsCalendar.custom-purple tbody td.jsCalendar-current {
background-color: #800080;
}
.jsCalendar.custom-purple *::selection {
background: #800080;
}
.jsCalendar.custom-purple *::-moz-selection {
background: #800080;
}
.jsCalendar.material-theme.custom-purple thead {
background-color: #800080;
}
.jsCalendar.material-theme.custom-purple thead .jsCalendar-nav-left:hover,
.jsCalendar.material-theme.custom-purple thead .jsCalendar-nav-right:hover {
background-color: #660066;
}
.jsCalendar.classic-theme.custom-purple thead {
background-color: #800080;
}
.jsCalendar.classic-theme.custom-purple thead .jsCalendar-nav-left:hover,
.jsCalendar.classic-theme.custom-purple thead .jsCalendar-nav-right:hover {
background-color: #660066;
}
</style>
<!-- Custom color on calendar -->
<div class="auto-jsCalendar custom-purple"></div>
<div class="auto-jsCalendar material-theme custom-purple"></div>
<div class="auto-jsCalendar classic-theme custom-purple"></div>
You can add more languages to the calendar easy and fast.
You can edit the jsCalendar.lang.template.js file provided, to support a new language.
Open the template, then find and translate all the green text you see below.
// Language code
code : 'en',
// Months of the year
months : [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
],
// Days of the week
days : [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
]
Save the changes and rename the file from jsCalendar.lang.template.js to jsCalendar.lang.code.js, where code is your language code.
You can find your language code on the ISO 639-1 code list.
Then you can use it like any other language file. Consider sharing it with the community by submitting it to the jsCaldendar Github project.
You can auto generate your calendar code by using the Code Generator tool.
The Code Generator tool let you select a theme and many of the calendar's options on a simple GUI environment.
It can generate both an HTML auto-jsCalendar calendars and dynamic javascript calendars created with jsCalendar.new.