Yahoo! UI Library

Calendar  2.6.0

Yahoo! UI Library > calendar > YAHOO.widget.Calendar
Search:
 
Filters

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="calContainer"></div>

NOTE: As of 2.4.0, the constructor's ID argument is optional. The Calendar can be constructed by simply providing a container ID string, or a reference to a container DIV HTMLElement (the element needs to exist in the document). E.g.:

var c = new YAHOO.widget.Calendar("calContainer", configOptions); or: var containerDiv = YAHOO.util.Dom.get("calContainer"); var c = new YAHOO.widget.Calendar(containerDiv, configOptions);

If not provided, the ID will be generated from the container DIV ID by adding an "_t" suffix. For example if an ID is not provided, and the container's ID is "calContainer", the Calendar's ID will be set to "calContainer_t".

Constructor

YAHOO.widget.Calendar ( id , container , config )
Parameters:
id <String> optional The id of the table element that will represent the Calendar widget. As of 2.4.0, this argument is optional.
container <String | HTMLElement> The id of the container div element that will wrap the Calendar table, or a reference to a DIV element which exists in the document.
config <Object> optional The configuration object containing the initial configuration values for the Calendar.

Properties

_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.
Deprecated: As of 2.3.0, environment information is available in YAHOO.env.ua

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.

containerId - String

The unique id associated with the Calendar's container

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.

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.

oNavigator - CalendarNavigator

A reference to the CalendarNavigator instance created for this Calendar. Will be null if the "navigator" configuration property has not been set

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.CSS_BODY - object


Style.CSS_CELL - object


Style.CSS_CLOSE - object


Style.CSS_FOOTER - object


Style.CSS_HEADER - object


Style.CSS_NAV - object


Style.CSS_SINGLE - object


today - Date

A Date object representing today's date.

YAHOO.widget.Calendar._DEFAULT_CONFIG - private static final Object

The set of default Config property keys and values for the Calendar

YAHOO.widget.Calendar._EVENT_TYPES - private static final Object

The set of Custom Event types supported by the Calendar

YAHOO.widget.Calendar._STYLES - private static final Object

The set of default style constants for the Calendar

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
Deprecated: You can now customize images by overriding the calclose, calnavleft and calnavright default CSS classes for the close icon, left arrow and right arrow respectively

YAHOO.widget.Calendar.LONG - static final String

Constant used to represent long date field string formats (e.g. Monday or February)

YAHOO.widget.Calendar.MEDIUM - static final String

Constant used to represent medium date field string formats (e.g. Mon)

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.ONE_CHAR - static final String

Constant used to represent single character date field string formats (e.g. M, T, W)

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.SHORT - static final String

Constant used to represent short date field string formats (e.g. Tu or Feb)

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

_buildMonthLabel

private String _buildMonthLabel ( date )
Helper method, to format a Month Year string, given a JavaScript Date, based on the Calendar localization settings
Parameters:
date <Date>
Returns: String
Formated month, year string

_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.

_parseArgs

protected Object _parseArgs ( Function )
Protected helper used to parse Calendar constructor/init arguments. As of 2.4.0, Calendar supports a simpler constructor signature. This method reconciles arguments received in the pre 2.4.0 and 2.4.0 formats.
Parameters:
Function <Array> "arguments" array
Returns: Object
Object with id, container, config properties containing the reconciled argument values.

_parseDate

private _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.

_parseDates

private _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

_parsePageDate

private Date _parsePageDate ( date )
Parses a pagedate configuration property value. The value can either be specified as a string of form "mm/yyyy" or a Date object and is parsed into a Date object normalized to the first day of the month. If no value is passed in, the month and year from today's date are used to create the Date object
Parameters:
date <Date|String> Pagedate value which needs to be parsed
Returns: Date
The Date object representing the pagedate

_parseRange

private _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

_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
Deprecated Made public, toDate

_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 (Sunday = 1, Monday = 2 ... Saturday = 7) 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 ( style )
Removes all styles from all body cells in the current calendar table.
Parameters:
style <style> The CSS class name to remove from all calendar body cells
Returns: void

clearElement

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