Yahoo! UI Library

Calendar 

Yahoo! UI Library > calendar > YAHOO.widget.Calendar

Class YAHOO.widget.Calendar

Known Subclasses:
YAHOO.widget.Calendar_Core
Calendar is the base class for the Calendar widget. In its most basic implementation, it has the ability to render a calendar widget on the page that can be manipulated to select a single date, move back and forth between months and years.

To construct the placeholder for the calendar widget, the code is as follows:

<div id="cal1Container"></div> Note that the table can be replaced with any kind of element.

Constructor

YAHOO.widget.Calendar ( id , containerId , config )
Parameters:
id <String> The id of the table element that will represent the calendar widget
containerId <String> The id of the container div element that will wrap the calendar table
config <Object> The configuration object containing the Calendar's arguments

Properties

_pageDate - private Date

A Date object representing the month/year that the calendar is initially set to

_renderStack - private Array

A copy of the initial render functions created before rendering.

_selectedDates - private Array

The private list of initially selected dates.

browser - String

Returns a string representing the current browser.

cellDates - Array[](Number[])

The collection of calendar cell dates that is parallel to the cells collection. The array contains dates field arrays in the format of [YYYY, M, D].

cells - HTMLTableCellElement[]

The collection of calendar table cells

cfg - YAHOO.util.Config

The Config object used to hold the configuration variables for the Calendar

Config - private Object

The configuration object used to set up the calendars various locale and style options.
Deprecated: Configuration properties should be set by calling Calendar.cfg.setProperty.

domEventMap - Object

A map of DOM event handlers to attach to cells associated with specific CSS class names

id - String

The id that uniquely identifies this calendar. This id should match the id of the placeholder element on the page.

index - Number

The index of this item in the parent group

Locale - Object

The local object which contains the Calendar's locale settings

oDomContainer - HTMLElement

The DOM element reference that points to this calendar's container element. The calendar will be inserted into this element when the shell is rendered.

Options - Object

The local object which contains the Calendar's options

parent - CalendarGroup

The parent CalendarGroup, only to be set explicitly by the parent group

renderStack - Array[]

The list of render functions, along with required parameters, used to render cells.

Style - object

Collection of Style constants for the Calendar

Style.CSS_CALENDAR - object


Style.CSS_CELL - object


Style.CSS_CELL_BOTTOM - object


Style.CSS_CELL_HIGHLIGHT1 - object


Style.CSS_CELL_HIGHLIGHT2 - object


Style.CSS_CELL_HIGHLIGHT3 - object


Style.CSS_CELL_HIGHLIGHT4 - object


Style.CSS_CELL_HOVER - object


Style.CSS_CELL_LEFT - object


Style.CSS_CELL_OOB - object


Style.CSS_CELL_OOM - object


Style.CSS_CELL_RESTRICTED - object


Style.CSS_CELL_RIGHT - object


Style.CSS_CELL_SELECTABLE - object


Style.CSS_CELL_SELECTED - object


Style.CSS_CELL_TODAY - object


Style.CSS_CELL_TOP - object


Style.CSS_CONTAINER - object


Style.CSS_FOOTER - object


Style.CSS_HEADER - object


Style.CSS_HEADER_TEXT - object


Style.CSS_NAV_LEFT - object


Style.CSS_NAV_RIGHT - object


Style.CSS_ROW_FOOTER - object


Style.CSS_ROW_HEADER - object


Style.CSS_SINGLE - object


Style.CSS_WEEKDAY_CELL - object


Style.CSS_WEEKDAY_ROW - object


today - Date

A Date object representing today's date.

YAHOO.widget.Calendar.DATE - static final String

Type constant used for renderers to represent an individual date (M/D/Y)

YAHOO.widget.Calendar.DISPLAY_DAYS - static final Number

Constant that represents the total number of date cells that are displayed in a given month

YAHOO.widget.Calendar.IMG_ROOT - static String

The path to be used for images loaded for the Calendar

YAHOO.widget.Calendar.MONTH - static final String

Type constant used for renderers to represent a month across any year

YAHOO.widget.Calendar.MONTH_DAY - static final String

Type constant used for renderers to represent an individual date across any year (M/D)

YAHOO.widget.Calendar.RANGE - static final String

Type constant used for renderers to represent a range of individual dates (M/D/Y-M/D/Y)

YAHOO.widget.Calendar.STOP_RENDER - static final String

Constant used for halting the execution of the remainder of the render stack

YAHOO.widget.Calendar.WEEKDAY - static final String

Type constant used for renderers to represent a weekday

Methods

_addRenderer

private void _addRenderer ( type , aDates , fnRender )
The private method used for adding cell renderers to the local render stack. This method is called by other methods that set the renderer type prior to the method call.
Parameters:
type <String> The type string that indicates the type of date renderer being added. Values are YAHOO.widget.Calendar.DATE, YAHOO.widget.Calendar.MONTH_DAY, YAHOO.widget.Calendar.WEEKDAY, YAHOO.widget.Calendar.RANGE, YAHOO.widget.Calendar.MONTH
aDates <Array> An array of dates used to construct the renderer. The format varies based on the renderer type
fnRender <Function> The function executed to render cells that match the render rules for this renderer.
Returns: void

_fieldArraysAreEqual

private Boolean _fieldArraysAreEqual ( array1 , array2 )
Converts a date field array [yyyy,mm,dd] to a JavaScript Date object.
Parameters:
array1 <Number[]> The first date field array to compare
array2 <Number[]> The first date field array to compare
Returns: Boolean
The boolean that represents the equality of the two arrays

_indexOfSelectedFieldArray

private Number _indexOfSelectedFieldArray ( find )
Gets the index of a date field array [yyyy,mm,dd] in the current list of selected dates.
Parameters:
find <Number[]> The date field array to search for
Returns: Number
The index of the date field array within the collection of selected dates. -1 will be returned if the date is not found.

_parseDate

private void _parseDate ( sDate )
Converts a date string to a date field array
Parameters:
sDate <String> Date string. Valid formats are mm/dd and mm/dd/yyyy.
Returns: void
A date field array representing the string passed to the method

_parseDates

private void _parseDates ( sDates )
Converts a multi or single-date string to an array of date field arrays
Parameters:
sDates <String> Date string with one or more comma-delimited dates. Valid formats are mm/dd, mm/dd/yyyy, mm/dd/yyyy-mm/dd/yyyy
Returns: void
An array of date field arrays

_parseRange

private void _parseRange ( startDate , endDate )
Converts a date range to the full list of included dates
Parameters:
startDate <Number[]> Date field array representing the first date in the range
endDate <Number[]> Date field array representing the last date in the range
Returns: void
An array of date field arrays

_toDate

private Date _toDate ( dateFieldArray )
Converts a date field array [yyyy,mm,dd] to a JavaScript Date object.
Parameters:
dateFieldArray <Number[]> The date field array to convert to a JavaScript Date.
Returns: Date
JavaScript Date object representing the date field array

_toFieldArray

private Array[](Number[]) _toFieldArray ( date )
Converts a date (either a JavaScript Date object, or a date string) to the internal data structure used to represent dates: [[yyyy,mm,dd],[yyyy,mm,dd]].
Parameters:
date <String/Date/Date[]> The date string of dates to deselect in the current calendar. Valid formats are individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). This method can also take a JavaScript Date object or an array of Date objects.
Returns: Array[](Number[])
Array of date field arrays

addMonthRenderer

void addMonthRenderer ( month , fnRender )
Adds a month to the render stack. The function reference passed to this method will be executed when a date cell matches the month passed to this method.
Parameters:
month <Number> The month (1-12) to associate with this renderer
fnRender <Function> The function executed to render cells that match the render rules for this renderer.
Returns: void

addMonths

void addMonths ( count )
Adds the designated number of months to the current calendar month, and sets the current calendar page date to the new month.
Parameters:
count <Number> The number of months to add to the current calendar
Returns: void

addRenderer

void addRenderer ( sDates , fnRender )
Adds a renderer to the render stack. The function reference passed to this method will be executed when a date cell matches the conditions specified in the date string for this renderer.
Parameters:
sDates <String> A date string to associate with the specified renderer. Valid formats include date (12/24/2005), month/day (12/24), and range (12/1/2004-1/1/2005)
fnRender <Function> The function executed to render cells that match the render rules for this renderer.
Returns: void

addWeekdayRenderer

void addWeekdayRenderer ( weekday , fnRender )
Adds a weekday to the render stack. The function reference passed to this method will be executed when a date cell matches the weekday passed to this method.
Parameters:
weekday <Number> The weekday (0-6) to associate with this renderer
fnRender <Function> The function executed to render cells that match the render rules for this renderer.
Returns: void

addYears

void addYears ( count )
Adds the designated number of years to the current calendar, and sets the current calendar page date to the new month.
Parameters:
count <Number> The number of years to add to the current calendar
Returns: void

applyListeners

void applyListeners ( )
Applies the Calendar's DOM listeners to applicable elements.
Returns: void

buildDayLabel

String buildDayLabel ( workingDate )
Builds the date digit that will be displayed in calendar cells
Parameters:
workingDate <Date> The current working date
Returns: String
The formatted day label

buildMonthLabel

String buildMonthLabel ( )
Builds the date label that will be displayed in the calendar header or footer, depending on configuration.
Returns: String
The formatted calendar month label

buildWeekdays

Array buildWeekdays ( html )
Renders the Calendar's weekday headers.
Parameters:
html <Array> The current working HTML array
Returns: Array
The current working HTML array

clear

void clear ( )
Clears the selected dates in the current calendar widget and sets the calendar to the current month and year.
Returns: void

clearAllBodyCellStyles

void clearAllBodyCellStyles ( The )
Removes all styles from all body cells in the current calendar table.
Parameters:
The <style> CSS class name to remove from all calendar body cells
Returns: void

clearElement

void clearElement ( The )
Clears the inner HTML, CSS class and style information from the specified cell.
Parameters:
The <HTMLTableCellElement> cell to clear
Returns: void

configClose

void configClose ( )
Default handler for the "close" property
Returns: void

configIframe

void configIframe ( )
Renders the built-in IFRAME shim for the IE6 and below
Returns: void

configLocale

void configLocale ( )
The default handler for all configuration locale properties
Returns: void

configLocaleValues

void configLocaleValues ( )
The default handler for all configuration locale field length properties
Returns: void

configMaxDate

void configMaxDate ( )
The default handler for the "maxdate" property
Returns: void

configMinDate

void configMinDate ( )
The default handler for the "mindate" property
Returns: void

configOptions

void configOptions ( )
The default handler for all configuration options properties
Returns: void

configPageDate

void configPageDate ( )
The default handler for the "pagedate" property
Returns: void

configSelected

void configSelected ( )
The default handler for the "selected" property
Returns: void

configTitle

void configTitle ( )
Default handler for the "title" property
Returns: void

deselect

Date[] deselect ( date )
Deselects a date or a collection of dates on the current calendar. This method, by default, does not call the render method explicitly. Once deselection has completed, render must be called for the changes to be reflected visually.
Parameters:
date <String/Date/Date[]> The date string of dates to deselect in the current calendar. Valid formats are individual date(s) (12/24/2005,12/26/2005) or date range(s) (12/24/2005-1/1/2006). Multiple comma-delimited dates can also be passed to this method (12/24/2005,12/11/2005-12/13/2005). This method can also take a JavaScript Date object or an array of Date objects.
Returns: Date[]
Array of JavaScript Date objects representing all individual dates that are currently selected.

deselectAll

Date[] deselectAll ( )
Deselects all dates on the current calendar.
Returns: Date[]
Array of JavaScript Date objects representing all individual dates that are currently selected. Assuming that this function executes properly, the return value should be an empty array. However, the empty array is returned for the sake of being able to check the selection status of the calendar.

deselectCell

Date[] deselectCell ( cellIndex )
Deselects a date on the current calendar by referencing the index of the cell that should be deselected. This method is used to easily deselect a single cell (usually with a mouse click) without having to do a full render. The selected style is removed from the cell directly.
Parameters:
cellIndex <Number> The index of the cell to deselect in the current calendar.
Returns: Date[]
Array of JavaScript Date objects representing all individual dates that are currently selected.

doCellMouseOut

void doCellMouseOut ( e , cal )
The event that is executed when the user moves the mouse out of a cell
Parameters:
e <DOMEvent> The event
cal <Calendar> A reference to the calendar passed by the Event utility
Returns: void

doCellMouseOver

void doCellMouseOver ( e , cal )
The event that is executed when the user hovers over a cell
Parameters:
e <DOMEvent> The event
cal <Calendar> A reference to the calendar passed by the Event utility
Returns: void

doSelectCell

void doSelectCell ( e , cal )
The default event function that is attached to a date link within a calendar cell when the calendar is rendered.
Parameters:
e <DOMEvent> The event
cal <Calendar> A reference to the calendar passed by the Event utility
Returns: void

getDateByCellId

Date getDateByCellId ( id )
Retrieves the Date object for the specified Calendar cell
Parameters:
id <String> The id of the cell
Returns: Date
The Date object for the specified Calendar cell

getDateFieldsByCellId

Array getDateFieldsByCellId ( id )
Retrieves the Date object for the specified Calendar cell
Parameters:
id <String> The id of the cell
Returns: Array
The array of Date fields for the specified Calendar cell

getSelectedDates

Date[] getSelectedDates ( )
Gets the list of currently selected dates from the calendar.
Returns: Date[]
An array of currently selected JavaScript Date objects.

hide

void hide ( )
Hides the Calendar's outer container from view.
Returns: void

init

void init ( id , containerId , config )
Initializes the Calendar widget.
Parameters:
id <String> The id of the table element that will represent the calendar widget
containerId <String> The id of the container div element that will wrap the calendar table
config <Object> The configuration object containing the Calendar's arguments
Returns: void

initEvents

void initEvents ( )
Initializes Calendar's built-in CustomEvents
Returns: void

initStyles

void initStyles ( )
Defines the style constants for the Calendar
Returns: