calendar.js revision cab1f4f3841b7834ff91a5aebffd50dba6ecb297
/**
* The Calendar component is a UI widget that allows users
* to view dates in a two-dimensional month grid, as well as
* to select one or more dates, or ranges of dates. Calendar
* is generated dynamically and relies on the developer to
* provide for a progressive enhancement alternative.
*
*
* @module calendar
*/
CALENDAR = 'calendar',
KEY_DOWN = 40,
KEY_UP = 38,
KEY_LEFT = 37,
KEY_RIGHT = 39,
KEY_ENTER = 13,
KEY_SPACE = 32,
/** Create a calendar view to represent a single or multiple
* month range of dates, rendered as a grid with date and
* weekday labels.
*
* @class Calendar
* @extends CalendarBase
* @param config {Object} Configuration object (see Configuration attributes)
* @constructor
*/
}
_keyEvents: [],
_highlightedDateNode: null,
/**
* A property tracking the last selected date on the calendar, for the
* purposes of multiple selection.
*
* @property _lastSelectedDate
* @type Date
* @default null
* @private
*/
_lastSelectedDate: null,
/**
* Designated initializer. Activates the navigation plugin for the calendar.
*
* @method initializer
*/
initializer : function () {
this._keyEvents = [];
this._highlightedDateNode = null;
this._lastSelectedDate = null;
},
/**
* syncUI implementation
*
* Update the scroll position, based on the current value of scrollY
* @method syncUI
*/
syncUI : function () {
},
/**
* Overrides the _bindCalendarEvents placeholder in CalendarBase
* and binds calendar events during bindUI stage.
* @method _bindCalendarEvents
* @protected
*/
_bindCalendarEvents : function () {
},
/**
* Highlights a specific date node with keyboard highlight class
* @method _highlightDateNode
* @param oDate {Date} Date corresponding the node to be highlighted
* @protected
*/
_highlightDateNode : function (oDate) {
this._unhighlightCurrentDateNode();
},
/**
* Unhighlights a specific date node currently highlighted with keyboard highlight class
* @method _unhighlightCurrentDateNode
* @protected
*/
_unhighlightCurrentDateNode : function () {
if (allHilitedNodes) {
}
},
/**
* Returns the grid number for a specific calendar grid (for multi-grid templates)
* @method _getGridNumber
* @param gridNode {Node} Node corresponding to a specific grid
* @protected
*/
_getGridNumber : function (gridNode) {
},
/**
* Handler for loss of focus of calendar grid
* @method _blurCalendarGrid
* @protected
*/
_blurCalendarGrid : function (ev) {
this._unhighlightCurrentDateNode();
},
/**
* Handler for gain of focus of calendar cell
* @method _focusCalendarCell
* @protected
*/
_focusCalendarCell : function (ev) {
},
/**
* Handler for gain of focus of calendar grid
* @method _focusCalendarGrid
* @protected
*/
_focusCalendarGrid : function (ev) {
this._unhighlightCurrentDateNode();
this._highlightedDateNode = null;
},
/**
* Handler for keyboard press on a calendar grid
* @method _keydownCalendar
* @protected
*/
_keydownCalendar : function (ev) {
dayNum = 0,
dir = '';
switch(keyCode) {
case KEY_DOWN:
dayNum = 7;
dir = 's';
break;
case KEY_UP:
dayNum = -7;
dir = 'n';
break;
case KEY_LEFT:
dayNum = -1;
dir = 'w';
break;
case KEY_RIGHT:
dayNum = 1;
dir = 'e';
break;
ev.preventDefault();
if (this._highlightedDateNode) {
this._clearSelection(true);
this._addDateToSelection(curDate);
}
this._removeDateFromSelection(curDate);
}
else {
this._addDateToSelection(curDate);
}
}
}
break;
}
if (!curDate) {
dayNum = 0;
}
ev.preventDefault();
lastPaneDate = new Date(endDate);
/*
var paneShift = (newDate.getMonth() - curDate.getMonth()) % 10;
if (paneShift != 0) {
var newGridNum = gridNum + paneShift,
contentBox = this.get('contentBox'),
newPane = contentBox.one("#" + this._calendarId + "_pane_" + newGridNum);
newPane.focus();
}
*/
this._highlightDateNode(newDate);
}
this._highlightDateNode(newDate);
}
}
this._highlightDateNode(newDate);
}
}
}
},
/**
* Handles the calendar clicks based on selection mode.
* @method _clickCalendar
* @param {Event} ev A click event
* @private
*/
_clickCalendar : function (ev) {
switch (this.get("selectionMode")) {
case("single"):
if (clickedCellIsDay) {
if (!clickedCellIsSelected) {
this._clearSelection(true);
}
}
break;
case("multiple-sticky"):
if (clickedCellIsDay) {
if (clickedCellIsSelected) {
}
else {
}
}
break;
case("multiple"):
this._clearSelection(true);
this._addDateToSelection(this._lastSelectedDate);
}
else if (((os == 'macintosh' && ev.metaKey) || (os != 'macintosh' && ev.ctrlKey)) && !ev.shiftKey) {
if (clickedCellIsSelected) {
this._lastSelectedDate = null;
}
else {
this._addDateToSelection(this._lastSelectedDate);
}
}
if (this._lastSelectedDate) {
this._lastSelectedDate = selectedDate;
}
else {
this._addDateToSelection(this._lastSelectedDate);
}
}
if (this._lastSelectedDate) {
this._clearSelection(true);
this._lastSelectedDate = selectedDate;
}
else {
this._clearSelection(true);
this._addDateToSelection(this._lastSelectedDate);
}
}
break;
}
if (clickedCellIsDay) {
/**
* Fired when a specific date cell in the calendar is clicked. The event carries a
* payload which includes a `cell` property corresponding to the node of the actual
* date cell, and a `date` property, with the `Date` that was clicked.
*
* @event dateClick
*/
}
/**
* Fired when any of the previous month's days displayed before the calendar grid
* are clicked.
*
* @event prevMonthClick
*/
this.fire("prevMonthClick");
}
/**
* Fired when any of the next month's days displayed after the calendar grid
* are clicked.
*
* @event nextMonthClick
*/
this.fire("nextMonthClick");
}
},
/**
* Subtracts one month from the current calendar view.
* @method subtractMonth
*/
subtractMonth : function (e) {
e.halt();
},
/**
* Subtracts one year from the current calendar view.
* @method subtractYear
*/
subtractYear : function (e) {
e.halt();
},
/**
* Adds one month to the current calendar view.
* @method addMonth
*/
addMonth : function (e) {
e.halt();
},
/**
* Adds one year to the current calendar view.
* @method addYear
*/
addYear : function (e) {
e.halt();
}
},
{
/**
* The identity of the widget.
*
* @property NAME
* @type String
* @default 'calendar'
* @readOnly
* @protected
* @static
*/
NAME: "calendar",
/**
* Static property used to define the default attribute configuration of
* the Widget.
*
* @property ATTRS
* @type {Object}
* @protected
* @static
*/
ATTRS: {
/**
* A setting specifying the type of selection the calendar allows.
* Possible values include:
* <ul>
* <li>`single` - One date at a time</li>
* <li>`multiple-sticky` - Multiple dates, selected one at a time (the dates "stick"). This option
* is appropriate for mobile devices, where function keys from the keyboard are not available.</li>
* dates, and Shift key for date ranges.</li>
*
* @attribute selectionMode
* @type String
* @default single
*/
value: "single"
},
/**
* The date corresponding to the current calendar view. Always
* normalized to the first of the month that contains the date
* at assignment time. Used as the first date visible in the
* calendar.
*
* @attribute date
* @type Date
* @default Today's date as set on the user's computer.
*/
date: {
value: new Date(),
lazyAdd: false,
return newDate;
}
return minDate;
}
return actualMaxDate;
}
}
},
/**
* The minimum date that can be displayed by the calendar. The calendar will not
* allow dates earlier than this one to be set, and will reset any earlier date to
* this date. Should be `null` if no minimum date is needed.
*
* @attribute minimumDate
* @type Date
* @default null
*/
minimumDate: {
value: null,
if (val) {
}
return newMinDate;
}
else {
return this._normalizeDate(val);
}
}
},
/**
* The maximum date that can be displayed by the calendar. The calendar will not
* allow dates later than this one to be set, and will reset any later date to
* this date. Should be `null` if no maximum date is needed.
*
* @attribute maximumDate
* @type Date
* @default null
*/
maximumDate: {
value: null,
if (val) {
}
return newMaxDate;
}
else {
return val;
}
}
}
}
});
}, '@VERSION@' ,{requires:['calendar-base', 'calendarnavigator'], lang:['de', 'en', 'fr', 'ja', 'nb-NO', 'pt-BR', 'ru', 'zh-HANT-TW']});