calendarnavigator-debug.js revision e66eba403ebf8a09e090b3785e8ea63aa1de7f3d
1127N/AYUI.add('calendarnavigator', function(Y) {
1127N/A
1127N/A/**
1127N/A * Provides a plugin which adds navigation controls to Calendar.
1127N/A *
1127N/A * @module calendarnavigator
1127N/A */
1127N/Avar CONTENT_BOX = "contentBox",
1127N/A HOST = "host",
1127N/A RENDERED = "rendered",
1127N/A getCN = Y.ClassNameManager.getClassName,
1127N/A substitute = Y.substitute,
1127N/A node = Y.Node,
1127N/A create = node.create,
1127N/A CALENDAR = 'calendar',
1127N/A CALENDARNAV = 'calendarnav',
1127N/A CAL_HD = getCN(CALENDAR, 'header'),
1127N/A CAL_PREV_M = getCN(CALENDARNAV, 'prevmonth'),
1127N/A CAL_NEXT_M = getCN(CALENDARNAV, 'nextmonth'),
1127N/A CAL_DIS_M = getCN(CALENDARNAV, 'month-disabled'),
1127N/A ydate = Y.DataType.Date;
1127N/A/**
1127N/A * A plugin class which adds navigation controls to Calendar.
1127N/A *
1127N/A * @class CalendarNavigator
1214N/A * @extends Plugin.Base
1127N/A * @namespace Plugin
1127N/A */
1127N/Afunction CalendarNavigator(config) {
1127N/A CalendarNavigator.superclass.constructor.apply(this, arguments);
1127N/A}
1127N/A
1127N/A/**
1129N/A * The namespace for the plugin. This will be the property on the widget, which will
1127N/A * reference the plugin instance, when it's plugged in.
1127N/A *
1127N/A * @property NS
1127N/A * @static
1127N/A * @type String
1127N/A * @default "navigator"
1127N/A */
1127N/ACalendarNavigator.NS = "navigator";
1127N/A
1127N/A/**
1127N/A * The NAME of the CalendarNavigator class. Used to prefix events generated
1127N/A * by the plugin class.
1127N/A *
1127N/A * @property NAME
1127N/A * @static
1127N/A * @type String
1127N/A * @default "pluginCalendarNavigator"
1127N/A */
1127N/ACalendarNavigator.NAME = "pluginCalendarNavigator";
1127N/A
1127N/A
1127N/A/**
1127N/A * Static property used to define the default attribute
1127N/A * configuration for the plugin.
1127N/A *
1214N/A * @property ATTRS
1127N/A * @type Object
1127N/A * @static
1127N/A */
1127N/ACalendarNavigator.ATTRS = {
1127N/A
1127N/A /**
1127N/A * The number of months to shift by when the control arrows are clicked.
1127N/A *
1127N/A * @attribute shiftByMonths
1127N/A * @type Number
1127N/A * @default 1 (months)
1127N/A */
1127N/A shiftByMonths : {
1127N/A value: 1
1127N/A }
1127N/A};
1127N/A
1127N/A /**
1127N/A * The CSS classnames for the calendar navigator controls.
1127N/A * @property CALENDARNAV_STRINGS
1127N/A * @type Object
1127N/A * @readOnly
1127N/A * @protected
1127N/A * @static
1127N/A */
1127N/ACalendarNavigator.CALENDARNAV_STRINGS = {
1127N/A prev_month_class: CAL_PREV_M,
1127N/A next_month_class: CAL_NEXT_M
};
/**
* The template for the calendar navigator previous month control.
* @property PREV_MONTH_CONTROL_TEMPLATE
* @type String
* @protected
* @static
*/
CalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {prev_month_class}" role="button" aria-label="{prev_month_arialabel}" tabindex="{control_tabindex}">' +
"<span>&lt;</span>" +
'</a>';
/**
* The template for the calendar navigator next month control.
* @property NEXT_MONTH_CONTROL_TEMPLATE
* @type String
* @readOnly
* @protected
* @static
*/
CalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {next_month_class}" role="button" aria-label="{next_month_arialabel}" tabindex="{control_tabindex}">' +
"<span>&gt;</span>" +
'</a>';
Y.extend(CalendarNavigator, Y.Plugin.Base, {
_eventAttachments : {},
_controls: {},
/**
* The initializer lifecycle implementation. Modifies the host widget's
* render to add navigation controls.
*
* @method initializer
* @param {Object} config The user configuration for the plugin
*/
initializer : function(config) {
// After the host has rendered its UI, place the navigation cotnrols
this._controls = {};
this._eventAttachments = {};
this.afterHostMethod("renderUI", this._initNavigationControls);
},
/**
* The initializer destructor implementation. Responsible for destroying the initialized
* control mechanisms.
*
* @method destructor
*/
destructor : function() {
},
/**
* Private utility method that subtracts months from the host calendar date
* based on the control click and the shiftByMonths property.
*
* @method _subtractMonths
* @param {Event} ev Click event from the controls
* @protected
*/
_subtractMonths : function (ev) {
var host = this.get(HOST);
var oldDate = host.get("date");
host.set("date", ydate.addMonths(oldDate, -1*this.get("shiftByMonths")));
ev.preventDefault();
},
/**
* Private utility method that adds months to the host calendar date
* based on the control click and the shiftByMonths property.
*
* @method _addMonths
* @param {Event} ev Click event from the controls
* @protected
*/
_addMonths : function (ev) {
var host = this.get(HOST);
var oldDate = host.get("date");
host.set("date", ydate.addMonths(oldDate, this.get("shiftByMonths")));
ev.preventDefault();
},
_updateControlState : function () {
var host = this.get(HOST);
if (ydate.areEqual(host.get("minimumDate"), host.get("date"))) {
if (this._eventAttachments.prevMonth) {
this._eventAttachments.prevMonth.detach();
this._eventAttachments.prevMonth = false;
}
if (!this._controls.prevMonth.hasClass(CAL_DIS_M)) {
this._controls.prevMonth.addClass(CAL_DIS_M);
}
}
else {
if (!this._eventAttachments.prevMonth) {
this._eventAttachments.prevMonth = this._controls.prevMonth.on("click", this._subtractMonths, this);
}
if (this._controls.prevMonth.hasClass(CAL_DIS_M)) {
this._controls.prevMonth.removeClass(CAL_DIS_M);
}
}
if (ydate.areEqual(host.get("maximumDate"), ydate.addMonths(host.get("date"), host._paneNumber - 1))) {
if (this._eventAttachments.nextMonth) {
this._eventAttachments.nextMonth.detach();
this._eventAttachments.nextMonth = false;
}
if (!this._controls.nextMonth.hasClass(CAL_DIS_M)) {
this._controls.nextMonth.addClass(CAL_DIS_M);
}
}
else {
if (!this._eventAttachments.nextMonth) {
this._eventAttachments.nextMonth = this._controls.nextMonth.on("click", this._addMonths, this);
}
if (this._controls.nextMonth.hasClass(CAL_DIS_M)) {
this._controls.nextMonth.removeClass(CAL_DIS_M);
}
}
},
/**
* Private render assist method that renders the previous month control
*
* @method _renderPrevControls
* @private
*/
_renderPrevControls : function () {
var prevControlNode = create(substitute (CalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE,
CalendarNavigator.CALENDARNAV_STRINGS));
prevControlNode.on("selectstart", function (ev) {ev.preventDefault();});
return prevControlNode;
},
/**
* Private render assist method that renders the next month control
*
* @method _renderNextControls
* @private
*/
_renderNextControls : function () {
var nextControlNode = create(substitute (CalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE,
CalendarNavigator.CALENDARNAV_STRINGS));
nextControlNode.on("selectstart", function (ev) {ev.preventDefault();});
return nextControlNode;
},
/**
* Protected render assist method that initialized and renders the navigation controls.
* @method _initNavigationControls
* @protected
*/
_initNavigationControls : function() {
var host = this.get(HOST);
CalendarNavigator.CALENDARNAV_STRINGS["control_tabindex"] = host.get("tabIndex");
CalendarNavigator.CALENDARNAV_STRINGS["prev_month_arialabel"] = "Go to previous month";
CalendarNavigator.CALENDARNAV_STRINGS["next_month_arialabel"] = "Go to next month";
var headerCell = host.get(CONTENT_BOX).one("." + CAL_HD);
this._controls.prevMonth = this._renderPrevControls();
this._controls.nextMonth = this._renderNextControls();
this._updateControlState();
host.after("dateChange", this._updateControlState, this);
headerCell.prepend(this._controls.prevMonth);
headerCell.append(this._controls.nextMonth);
}
});
Y.namespace("Plugin").CalendarNavigator = CalendarNavigator;
}, '@VERSION@' ,{requires:['plugin', 'classnamemanager', 'datatype-date', 'node', 'substitute']});