calendarnavigator-debug.js revision 71bbbe94567d63ab107a7eab263595bcc6e47833
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Provides a plugin which adds navigation controls to Calendar.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @module calendarnavigator
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich CAL_PREV_M = getCN(CALENDARNAV, 'prevmonth'),
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich CAL_NEXT_M = getCN(CALENDARNAV, 'nextmonth'),
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich CAL_DIS_M = getCN(CALENDARNAV, 'month-disabled'),
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * A plugin class which adds navigation controls to Calendar.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @class CalendarNavigator
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @extends Plugin.Base
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @namespace Plugin
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich CalendarNavigator.superclass.constructor.apply(this, arguments);
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The namespace for the plugin. This will be the property on the widget, which will
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * reference the plugin instance, when it's plugged in.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property NS
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type String
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @default "navigator"
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The NAME of the CalendarNavigator class. Used to prefix events generated
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * by the plugin class.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property NAME
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type String
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @default "pluginCalendarNavigator"
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen RabinovichCalendarNavigator.NAME = "pluginCalendarNavigator";
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Static property used to define the default attribute
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * configuration for the plugin.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property ATTRS
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type Object
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The number of months to shift by when the control arrows are clicked.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @attribute shiftByMonths
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type Number
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @default 1 (months)
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The CSS classnames for the calendar navigator controls.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property CALENDARNAV_STRINGS
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type Object
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The template for the calendar navigator previous month control.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property PREV_MONTH_CONTROL_TEMPLATE
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type String
829f44d633f4910c12181f3295e5c6b996d7e559Allen RabinovichCalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {prev_month_class}" role="button" aria-label="{prev_month_arialabel}" tabindex="{control_tabindex}">' +
829f44d633f4910c12181f3295e5c6b996d7e559Allen Rabinovich "<span><</span>" +
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The template for the calendar navigator next month control.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * @property NEXT_MONTH_CONTROL_TEMPLATE
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @type String
829f44d633f4910c12181f3295e5c6b996d7e559Allen RabinovichCalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE = '<a class="yui3-u {next_month_class}" role="button" aria-label="{next_month_arialabel}" tabindex="{control_tabindex}">' +
829f44d633f4910c12181f3295e5c6b996d7e559Allen Rabinovich "<span>></span>" +
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen RabinovichY.extend(CalendarNavigator, Y.Plugin.Base, {
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The initializer lifecycle implementation. Modifies the host widget's
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * render to add navigation controls.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method initializer
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @param {Object} config The user configuration for the plugin
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich // After the host has rendered its UI, place the navigation cotnrols
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich this.afterHostMethod("renderUI", this._initNavigationControls);
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * The initializer destructor implementation. Responsible for destroying the initialized
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * control mechanisms.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method destructor
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Private utility method that subtracts months from the host calendar date
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * based on the control click and the shiftByMonths property.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method _subtractMonths
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @param {Event} ev Click event from the controls
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich if ( (ev.type === "click") || (ev.type === "keydown" && (ev.keyCode == 13 || ev.keyCode == 32)) ) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich host.set("date", ydate.addMonths(oldDate, -1*this.get("shiftByMonths")));
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Private utility method that adds months to the host calendar date
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * based on the control click and the shiftByMonths property.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method _addMonths
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @param {Event} ev Click event from the controls
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich if ( (ev.type === "click") || (ev.type === "keydown" && (ev.keyCode == 13 || ev.keyCode == 32)) ) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich host.set("date", ydate.addMonths(oldDate, this.get("shiftByMonths")));
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (ydate.areEqual(host.get("minimumDate"), host.get("date"))) {
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (!this._controls.prevMonth.hasClass(CAL_DIS_M)) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._controls.prevMonth.addClass(CAL_DIS_M).setAttribute("aria-disabled", "true");
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._eventAttachments.prevMonth = this._controls.prevMonth.on(["click", "keydown"], this._subtractMonths, this);
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (this._controls.prevMonth.hasClass(CAL_DIS_M)) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._controls.prevMonth.removeClass(CAL_DIS_M).setAttribute("aria-disabled", "false");
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (ydate.areEqual(host.get("maximumDate"), ydate.addMonths(host.get("date"), host._paneNumber - 1))) {
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (!this._controls.nextMonth.hasClass(CAL_DIS_M)) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._controls.nextMonth.addClass(CAL_DIS_M).setAttribute("aria-disabled", "true");
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._eventAttachments.nextMonth = this._controls.nextMonth.on(["click", "keydown"], this._addMonths, this);
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich if (this._controls.nextMonth.hasClass(CAL_DIS_M)) {
71bbbe94567d63ab107a7eab263595bcc6e47833Allen Rabinovich this._controls.nextMonth.removeClass(CAL_DIS_M).setAttribute("aria-disabled", "false");
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Private render assist method that renders the previous month control
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method _renderPrevControls
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich var prevControlNode = create(substitute (CalendarNavigator.PREV_MONTH_CONTROL_TEMPLATE,
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich prevControlNode.on("selectstart", function (ev) {ev.preventDefault();});
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Private render assist method that renders the next month control
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method _renderNextControls
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich var nextControlNode = create(substitute (CalendarNavigator.NEXT_MONTH_CONTROL_TEMPLATE,
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich nextControlNode.on("selectstart", function (ev) {ev.preventDefault();});
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * Protected render assist method that initialized and renders the navigation controls.
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich * @method _initNavigationControls
829f44d633f4910c12181f3295e5c6b996d7e559Allen Rabinovich CalendarNavigator.CALENDARNAV_STRINGS["control_tabindex"] = host.get("tabIndex");
829f44d633f4910c12181f3295e5c6b996d7e559Allen Rabinovich CalendarNavigator.CALENDARNAV_STRINGS["prev_month_arialabel"] = "Go to previous month";
829f44d633f4910c12181f3295e5c6b996d7e559Allen Rabinovich CalendarNavigator.CALENDARNAV_STRINGS["next_month_arialabel"] = "Go to next month";
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen Rabinovich var headerCell = host.get(CONTENT_BOX).one("." + CAL_HD);
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich this._controls.prevMonth = this._renderPrevControls();
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich this._controls.nextMonth = this._renderNextControls();
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich host.after("dateChange", this._updateControlState, this);
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich headerCell.prepend(this._controls.prevMonth);
e66eba403ebf8a09e090b3785e8ea63aa1de7f3dAllen Rabinovich headerCell.append(this._controls.nextMonth);
2f17bc2f9d34cb9377a0c15ea9519471bb83e4ecAllen RabinovichY.namespace("Plugin").CalendarNavigator = CalendarNavigator;
9724a6e829470b07523eddcd9df488b799e57a6aDav Glass}, '@VERSION@' ,{requires:['plugin', 'classnamemanager', 'datatype-date', 'node', 'substitute']});