calendarnavigator-debug.js revision 71bbbe94567d63ab107a7eab263595bcc6e47833
150N/AYUI.add('calendarnavigator', function(Y) {
150N/A
150N/A/**
257N/A * Provides a plugin which adds navigation controls to Calendar.
257N/A *
257N/A * @module calendarnavigator
953N/A */
257N/Avar CONTENT_BOX = "contentBox",
257N/A HOST = "host",
257N/A RENDERED = "rendered",
257N/A getCN = Y.ClassNameManager.getClassName,
150N/A substitute = Y.substitute,
257N/A node = Y.Node,
450N/A create = node.create,
670N/A CALENDAR = 'calendar',
257N/A CALENDARNAV = 'calendarnav',
257N/A CAL_HD = getCN(CALENDAR, 'header'),
200N/A CAL_PREV_M = getCN(CALENDARNAV, 'prevmonth'),
150N/A CAL_NEXT_M = getCN(CALENDARNAV, 'nextmonth'),
210N/A CAL_DIS_M = getCN(CALENDARNAV, 'month-disabled'),
150N/A ydate = Y.DataType.Date;
150N/A/**
150N/A * A plugin class which adds navigation controls to Calendar.
150N/A *
150N/A * @class CalendarNavigator
150N/A * @extends Plugin.Base
150N/A * @namespace Plugin
150N/A */
150N/Afunction CalendarNavigator(config) {
150N/A CalendarNavigator.superclass.constructor.apply(this, arguments);
150N/A}
150N/A
150N/A/**
150N/A * The namespace for the plugin. This will be the property on the widget, which will
150N/A * reference the plugin instance, when it's plugged in.
150N/A *
200N/A * @property NS
200N/A * @static
200N/A * @type String
200N/A * @default "navigator"
200N/A */
200N/ACalendarNavigator.NS = "navigator";
200N/A
200N/A/**
200N/A * The NAME of the CalendarNavigator class. Used to prefix events generated
200N/A * by the plugin class.
200N/A *
200N/A * @property NAME
150N/A * @static
210N/A * @type String
210N/A * @default "pluginCalendarNavigator"
953N/A */
953N/ACalendarNavigator.NAME = "pluginCalendarNavigator";
953N/A
953N/A
953N/A/**
953N/A * Static property used to define the default attribute
953N/A * configuration for the plugin.
953N/A *
953N/A * @property ATTRS
953N/A * @type Object
953N/A * @static
953N/A */
953N/ACalendarNavigator.ATTRS = {
210N/A
210N/A /**
210N/A * The number of months to shift by when the control arrows are clicked.
210N/A *
210N/A * @attribute shiftByMonths
210N/A * @type Number
210N/A * @default 1 (months)
210N/A */
210N/A shiftByMonths : {
210N/A value: 1
210N/A }
210N/A};
210N/A
210N/A /**
210N/A * The CSS classnames for the calendar navigator controls.
210N/A * @property CALENDARNAV_STRINGS
210N/A * @type Object
210N/A * @readOnly
257N/A * @protected
257N/A * @static
257N/A */
257N/ACalendarNavigator.CALENDARNAV_STRINGS = {
257N/A prev_month_class: CAL_PREV_M,
257N/A next_month_class: CAL_NEXT_M
257N/A};
257N/A
257N/A /**
257N/A * The template for the calendar navigator previous month control.
257N/A * @property PREV_MONTH_CONTROL_TEMPLATE
257N/A * @type String
257N/A * @protected
257N/A * @static
257N/A */
257N/ACalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {prev_month_class}" role="button" aria-label="{prev_month_arialabel}" tabindex="{control_tabindex}">' +
257N/A "<span>&lt;</span>" +
257N/A '</a>';
257N/A /**
257N/A * The template for the calendar navigator next month control.
257N/A * @property NEXT_MONTH_CONTROL_TEMPLATE
257N/A * @type String
257N/A * @readOnly
257N/A * @protected
257N/A * @static
257N/A */
257N/ACalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {next_month_class}" role="button" aria-label="{next_month_arialabel}" tabindex="{control_tabindex}">' +
257N/A "<span>&gt;</span>" +
257N/A '</a>';
257N/A
257N/A
257N/AY.extend(CalendarNavigator, Y.Plugin.Base, {
450N/A
450N/A _eventAttachments : {},
450N/A _controls: {},
450N/A
450N/A /**
670N/A * The initializer lifecycle implementation. Modifies the host widget's
670N/A * render to add navigation controls.
670N/A *
670N/A * @method initializer
670N/A * @param {Object} config The user configuration for the plugin
670N/A */
670N/A initializer : function(config) {
670N/A
670N/A // After the host has rendered its UI, place the navigation cotnrols
670N/A this._controls = {};
670N/A this._eventAttachments = {};
450N/A
483N/A this.afterHostMethod("renderUI", this._initNavigationControls);
483N/A },
483N/A
483N/A /**
483N/A * The initializer destructor implementation. Responsible for destroying the initialized
483N/A * control mechanisms.
483N/A *
483N/A * @method destructor
483N/A */
483N/A destructor : function() {
483N/A
150N/A },
/**
* 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) {
if ( (ev.type === "click") || (ev.type === "keydown" && (ev.keyCode == 13 || ev.keyCode == 32)) ) {
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) {
if ( (ev.type === "click") || (ev.type === "keydown" && (ev.keyCode == 13 || ev.keyCode == 32)) ) {
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).setAttribute("aria-disabled", "true");
}
}
else {
if (!this._eventAttachments.prevMonth) {
this._eventAttachments.prevMonth = this._controls.prevMonth.on(["click", "keydown"], this._subtractMonths, this);
}
if (this._controls.prevMonth.hasClass(CAL_DIS_M)) {
this._controls.prevMonth.removeClass(CAL_DIS_M).setAttribute("aria-disabled", "false");
}
}
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).setAttribute("aria-disabled", "true");
}
}
else {
if (!this._eventAttachments.nextMonth) {
this._eventAttachments.nextMonth = this._controls.nextMonth.on(["click", "keydown"], this._addMonths, this);
}
if (this._controls.nextMonth.hasClass(CAL_DIS_M)) {
this._controls.nextMonth.removeClass(CAL_DIS_M).setAttribute("aria-disabled", "false");
}
}
},
/**
* 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']});