Calendar.js - Documentation - Public Functions

Below is a list of all the public API functions that can be called from a Calendar.js class instance.

Download Now

v2.10.13 - 27th Feb 2024
Functions

Main controls:

turnOnFullScreen():

Turn on the full-screen mode (if enabled).
Returns: ‘Object’ - The Calendar.js class instance.

turnOffFullScreen():

Turn off the full-screen mode (if enabled).
Returns: ‘Object’ - The Calendar.js class instance.

isFullScreenActivated():

States if full-screen mode is activated.
Returns: ‘boolean’ - States if the full-screen mode is activated.

startTheAutoRefreshTimer():

Starts the auto-refresh timer (if enabled).
Returns: ‘Object’ - The Calendar.js class instance.

stopTheAutoRefreshTimer():

Stops the auto-refresh timer (if enabled).
Returns: ‘Object’ - The Calendar.js class instance.

destroy():

Removes the calendar from the DOM.
Fires: onDestroy
Returns: ‘Object’ - The Calendar.js class instance.


Navigation, Exporting and Refreshing:

moveToPreviousMonth():

Moves to the previous month.
Fires: onPreviousMonth
Returns: ‘Object’ - The Calendar.js class instance.

moveToNextMonth():

Moves to the next month.
Fires: onNextMonth
Returns: ‘Object’ - The Calendar.js class instance.

moveToPreviousYear():

Moves to the previous year.
Fires: onPreviousYear
Returns: ‘Object’ - The Calendar.js class instance.

moveToNextYear():

Moves to the next year.
Fires: onNextYear
Returns: ‘Object’ - The Calendar.js class instance.

moveToToday():

Moves to the current month.
Fires: onToday
Returns: ‘Object’ - The Calendar.js class instance.

getCurrentDisplayDate():

Returns the current date that is being used in the main display.
Returns: ‘Object’ - A Date() object (day is always set to the 1st).

setCurrentDisplayDate( date ):

Sets the current date that is being used in the main display.
Fires: onSetDate
Parameter: date: ‘Object’ - The Date() object to set.
Returns: ‘Object’ - The Calendar.js class instance.

getSelectedDatePickerDate():

Returns the current date that has been selected in DatePicker mode.
Returns: ‘Object’ - A Date() object.

setSelectedDatePickerDate( date ):

Sets the current date that is being used in DatePicker mode.
Fires: onDatePickerDateChanged
Parameter: date: ‘Object’ - The Date() object to set.
Returns: ‘Object’ - The Calendar.js class instance.

exportAllEvents( [type] ):

Exports all the events into a downloadable file.
Fires: onEventsExported
Parameter: type: ‘string’ - The data type to export to (defaults to “csv”, accepts “csv”, “xml”, “json”, “txt”, “ical”, “md”, “html”, and “tsv”).
Returns: ‘Object’ - The Calendar.js class instance.

refresh():

Refreshes all of the views.
Fires: onRefresh
Returns: ‘Object’ - The Calendar.js class instance.


Add/Remove Events:

setEvents( events, [updateEvents], [triggerEvent] ):

Sets the events and clears any existing ones.
Fires: onEventsSet
Parameter: events: ‘Event[]’ - The array of events (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsSet” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

setEventsFromJson( json, [updateEvents], [triggerEvent] ):

Sets new events from JSON data and clears any existing ones.
Fires: onEventsSetFromJSON
Parameter: json: ‘string’ - The JSON string containing the events (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsSetFromJSON” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

addEvents( events, [updateEvents], [triggerEvent] ):

Adds an array of new events.
Fires: onEventsAdded
Parameter: events: ‘Event[]’ - The array of events (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsAdded” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

addEventsFromJson( json, [updateEvents], [triggerEvent] ):

Adds new events from JSON data.
Fires: onEventsAddedFromJSON
Parameter: json: ‘json’ - The JSON string containing the events (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsAddedFromJSON” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

addEvent( event, [updateEvents], [triggerEvent], [setLastUpdated] ):

Adds a new event.
Fires: onEventAdded
Parameter: event: ‘Event’ - The event (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventAdded” event should be triggered (defaults to true).
Parameter: [setLastUpdated]: ‘boolean’ - States if the “lastUpdated” date should be set (defaults to true).
Returns: ‘boolean’ - States if the event was added.

updateEvents( events, [updateEvents], [triggerEvent] ):

Updates an array of existing events.
Fires: onEventsUpdated
Parameter: events: ‘Event[]’ - The array of events (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsUpdated” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

updateEvent( id, event, [updateEvents], [triggerEvent] ):

Updates an existing event.
Fires: onEventUpdated
Parameter: id: ‘string’ - The ID of the event.
Parameter: event: ‘Event’ - The event (refer to “Event” documentation for properties).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventUpdated” event should be triggered (defaults to true).
Returns: ‘boolean’ - States if the event was updated.

updateEventDateTimes( id, from, to, repeatEnds, [updateEvents], [triggerEvent] ):

Updates an existing events from, to, and repeatEnds dates.
Fires: onEventUpdated
Parameter: id: ‘string’ - The ID of the event.
Parameter: from: ‘Object’ - The new from date.
Parameter: to: ‘Object’ - The new to date.
Parameter: repeatEnds: ‘Object’ - The new repeat ends day.
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventUpdated” event should be triggered (defaults to true).
Returns: ‘boolean’ - States if the event was updated.

removeEvent( id, [updateEvents], [triggerEvent] ):

Removes an event.
Fires: onEventRemoved
Parameter: id: ‘string’ - The ID of the event.
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventRemoved” event should be triggered (defaults to true).
Returns: ‘boolean’ - States if the event was removed.

clearEvents( [updateEvents], [triggerEvent] ):

Clears all the events.
Fires: onEventsCleared
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventsCleared” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

getEvents():

Returns an array of the events available.
Returns: ‘Event[]’ - An array of events.

getEvent( id ):

Returns an event that matches the ID passed.
Parameter: id: ‘string’ - The ID of the event to get.
Returns: ‘object’ - The event details (or null if the ID cannot be found).

removeExpiredEvents( [updateEvents], [triggerEvent] ):

Removes all events (non-repeating) that have expired.
Fires: onEventRemoved
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onEventRemoved” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.


Add/Remove Event Types:

addEventType( id, text ):

Adds a new event type.
Parameter: id: ‘number’ - The ID for the event type.
Parameter: text: ‘string’ - The text for the event type.
Returns: ‘boolean’ - States if the event type was added.

removeEventType( id ):

Removes an event type.
Parameter: id: ‘number’ - The ID for the event type to remove.
Returns: ‘boolean’ - States if the event type was removed.

setVisibleEventTypes( ids, [triggerEvent] ):

Set which event types are visible.
Fires: onVisibleEventTypesChanged
Parameter: ids: ‘number[]’ - The IDs of the event types to make visible.
Parameter: [triggerEvent]: ‘boolean’ - States if the “onVisibleEventTypesChanged” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.


Add/Remove Groups:

getAllGroups():

Returns an array of group names being used.
Returns: ‘string[]’ - An array of the group names.

clearAllGroups( [updateEvents], [triggerEvent] ):

Clears all the event groups.
Fires: onGroupsCleared
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onGroupsCleared” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

removeGroup( groupName, [updateEvents], [triggerEvent] ):

Removes a group by name.
Fires: onGroupRemoved
Parameter: groupName: ‘string’ - The name of the group to remove.
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onGroupRemoved” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

setVisibleGroups( groupNames, [triggerEvent] ):

Set which groups are visible.
Fires: onVisibleGroupsChanged
Parameter: groupNames: ‘string[]’ - The names of the groups to make visible.
Parameter: [triggerEvent]: ‘boolean’ - States if the “onVisibleGroupsChanged” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.


Internal Clipboard:

setClipboardEvent( event ):

Set the clipboard event.
Parameter: event: ‘Event’ - The event to set (refer to “Day Event” documentation for properties).
Returns: ‘Object’ - The Calendar.js class instance.

setClipboardEvents( events ):

Set the clipboard events.
Parameter: events: ‘Event[]’ - The events to set (refer to “Day Event” documentation for properties).
Returns: ‘Object’ - The Calendar.js class instance.

getClipboardEvents():

Returns the events copied in the clipboard.
Returns: ‘Event[]’ - The copied events details.

clearClipboard():

Clears the internal clipboard.
Returns: ‘Object’ - The Calendar.js class instance.


Get/Set Additional Data:

getVersion():

Returns the version of Calendar.js.
Returns: ‘string’ - The version number.

getId():

Returns the ID of this Calendar.js instance.
Returns: ‘string’ - The Calendar ID.

isBusy():

Returns a flag that states if the calendar is busy.
Returns: ‘boolean’ - States if the calendar is busy.


Setting Options:

setOptions( newOptions, [triggerEvent] ):

Sets the specific options that should be used.
Fires: onOptionsUpdated
Parameter: newOptions: ‘Options’ - All the options that should be set (refer to “Options” documentation for properties).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onOptionsUpdated” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

setSearchOptions( newSearchOptions, [triggerEvent] ):

Sets the specific search options that should be used.
Fires: onSearchOptionsUpdated
Parameter: newSearchOptions: ‘Search’ - All the search options that should be set (refer to “Search Options” documentation for properties).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onSearchOptionsUpdated” event should be triggered (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

addHolidays( holidays, [triggerEvent], [updateEvents] ):

Adds new holidays.
Fires: onOptionsUpdated
Parameter: holidays: ‘Holiday[]’ - The holidays to add (refer to “Holiday” documentation for properties).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onOptionsUpdated” event should be triggered (defaults to true).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

removeHolidays( holidayNames, [triggerEvent], [updateEvents] ):

Removes holidays.
Fires: onOptionsUpdated
Parameter: holidayNames: ‘string[]’ - The names of the holidays to remove (case sensitive).
Parameter: [triggerEvent]: ‘boolean’ - States if the “onOptionsUpdated” event should be triggered (defaults to true).
Parameter: [updateEvents]: ‘boolean’ - States if the calendar display should be updated (defaults to true).
Returns: ‘Object’ - The Calendar.js class instance.

getHolidays():

Returns the holidays.
Returns: ‘Holiday[]’ - All the holidays.