calendar.js revision 0b1399c88929d68d588a14c154b525ff876e3d53
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * The Calendar component is a UI widget that allows users
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * to view dates in a two-dimensional month grid, as well as
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * to select one or more dates, or ranges of dates. Calendar
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * is generated dynamically and relies on the developer to
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * provide for a progressive enhancement alternative.
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @module calendar
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly CAL_DAY_SELECTED = getCN(CALENDAR, 'day-selected'),
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly CAL_DAY_HILITED = getCN(CALENDAR, 'day-highlighted'),
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly CAL_PREVMONTH_DAY = getCN(CALENDAR, 'prevmonth-day'),
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly CAL_NEXTMONTH_DAY = getCN(CALENDAR, 'nextmonth-day'),
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly/** Create a calendar view to represent a single or multiple
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * month range of dates, rendered as a grid with date and
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * weekday labels.
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @class Calendar
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @extends CalendarBase
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @param config {Object} Configuration object (see Configuration attributes)
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @constructor
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly Calendar.superclass.constructor.apply ( this, arguments );
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny DonnellyY.Calendar = Y.extend(Calendar, Y.CalendarBase, {
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * A property tracking the last selected date on the calendar, for the
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * purposes of multiple selection.
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @property _lastSelectedDate
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @default null
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * Designated initializer. Activates the navigation plugin for the calendar.
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @method initializer
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly initializer : function () {
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * syncUI implementation
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * Update the scroll position, based on the current value of scrollY
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @method syncUI
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly syncUI : function () {
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * Overrides the _bindCalendarEvents placeholder in CalendarBase
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * and binds calendar events during bindUI stage.
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @method _bindCalendarEvents
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.on("selectstart", function (ev) { ev.preventDefault();});
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.delegate("click", this._clickCalendar, "." + CAL_DAY, this);
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.delegate("keydown", this._keydownCalendar, "." + CAL_GRID, this);
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.delegate("focus", this._focusCalendarGrid, "." + CAL_GRID, this);
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.delegate("focus", this._focusCalendarCell, "." + CAL_DAY, this);
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly pane.delegate("blur", this._blurCalendarGrid, "." + CAL_GRID + ",." + CAL_DAY, this);
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * Highlights a specific date node with keyboard highlight class
8f9d94fb7812612dff92ce14a37dbcad4ff02c1cJenny Donnelly * @method _highlightDateNode
this._unhighlightCurrentDateNode();
_unhighlightCurrentDateNode : function () {
if (allHilitedNodes) {
this._unhighlightCurrentDateNode();
this._unhighlightCurrentDateNode();
this._highlightedDateNode = null;
switch(keyCode) {
case KEY_DOWN:
case KEY_UP:
case KEY_LEFT:
case KEY_RIGHT:
if (this._highlightedDateNode) {
this._clearSelection(true);
if (!curDate) {
if (clickedCellIsDay) {
if (!clickedCellIsSelected) {
this._clearSelection(true);
if (clickedCellIsDay) {
if (clickedCellIsSelected) {
this._clearSelection(true);
else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
if (clickedCellIsSelected) {
this._lastSelectedDate = null;
if (this._lastSelectedDate) {
if (this._lastSelectedDate) {
this._clearSelection(true);
this._clearSelection(true);
if (clickedCellIsDay) {
subtractMonth : function (e) {
e.halt();
subtractYear : function (e) {
e.halt();
addMonth : function (e) {
e.halt();
addYear : function (e) {
e.halt();
ATTRS: {
date: {
value: new Date(),
lazyAdd: false,
return newDate;
return minDate;
return actualMaxDate;
minimumDate: {
value: null,
if (val) {
return newMinDate;
maximumDate: {
value: null,
if (val) {
return newMaxDate;
return val;