3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('calendar-base', function(Y) {
10 * The Calendar component is a UI widget that allows users
11 * to view dates in a two-dimensional month grid, as well as
12 * to select one or more dates, or ranges of dates. Calendar
13 * is generated dynamically.
16 * @submodule calendar-base
19 /** Create a calendar view to represent a single or multiple
20 * month range of dates, rendered as a grid with date and
25 * @param config {Object} Configuration object (see Configuration attributes)
30 var getCN = Y.ClassNameManager.getClassName,
31 CALENDAR = 'calendar',
32 CAL_GRID = getCN(CALENDAR, 'grid'),
33 CAL_BODY = getCN(CALENDAR, 'body'),
34 CAL_HD = getCN(CALENDAR, 'header'),
35 CAL_HD_WRAP = getCN(CALENDAR, 'header-wrap'),
36 CAL_WDAYROW = getCN(CALENDAR, 'weekdayrow'),
37 CAL_WDAY = getCN(CALENDAR, 'weekday'),
38 CAL_ROW = getCN(CALENDAR, 'row'),
39 CAL_DAY = getCN(CALENDAR, 'day'),
40 CAL_ANCHOR = getCN(CALENDAR, 'anchor'),
43 create = Y.Node.create,
44 substitute = Y.substitute,
48 function CalendarBase() {
49 CalendarBase.superclass.constructor.apply ( this, arguments );
52 Y.CalendarBase = Y.extend( CalendarBase, Y.Widget, {
54 initializer : function () {
57 renderUI : function () {
58 var contentBox = this.get('contentBox');
59 contentBox.appendChild(this._initCalendarHTML(new Date("5/21/1947")));
62 bindUI : function () {
66 _getCutoffColumn : function (date) {
68 var normalizedDate = new Date(date.getFullYear(), date.getMonth(), 1);
69 return (1-normalizedDate.getDay());
73 _initCalendarHTML : function (baseDate) {
75 var startDate = baseDate || new Date(),
76 cutoffCol = this._getCutoffColumn(startDate),
77 headerData = {calheader: (startDate.getMonth()+1) + "/" +
78 startDate.getFullYear()},
80 weekdays = {wday1: 'Su',
89 partials["header_template"] = substitute(CalendarBase.HEADER_TEMPLATE,
92 partials["weekday_row"] = '';
94 each (weekdays, function (v) {
95 partials["weekday_row"] +=
96 substitute(CalendarBase.WEEKDAY_TEMPLATE,
101 partials["wdayrow_template"] = substitute(CalendarBase.WEEKDAY_ROW_TEMPLATE, partials);
107 for (var i = 0; i <= 5; i++) {
109 for (var j = -5; j <=7; j++) {
110 calday_row += substitute (CalendarBase.CALDAY_TEMPLATE, {day_content: '' + (j+7*i),
111 day_display_status: (j >= cutoffCol && j <= (cutoffCol + 6)) ? '' : 'style="display:none;"'});
113 row_array.push(substitute(CalendarBase.CALDAY_ROW_TEMPLATE, {calday_row: calday_row} ));
116 partials["body_template"] = row_array.join('\n');
118 var header = substitute(substitute (CalendarBase.CONTENT_TEMPLATE, partials),
119 CalendarBase.CALENDAR_CLASSES);
125 // Y.CalendarBase static properties
128 calendar_grid_class : CAL_GRID,
129 calendar_body_class : CAL_BODY,
130 calendar_hd_class : CAL_HD,
131 calendar_hd_wrapper_class: CAL_HD_WRAP,
132 calendar_weekdayrow_class: CAL_WDAYROW,
133 calendar_weekday_class: CAL_WDAY,
134 calendar_row_class: CAL_ROW,
135 calendar_day_class: CAL_DAY,
136 calendar_dayanchor_class: CAL_ANCHOR
139 CONTENT_TEMPLATE: '<table class="{calendar_grid_class}">' +
141 '{header_template}' +
142 '{wdayrow_template}' +
144 '<tbody class="{calendar_body_class}">' +
149 HEADER_TEMPLATE: '<tr>' +
150 '<th colspan="7" class="{calendar_hd_class}">' +
151 '<div id="calheader" class="{calendar_hd_wrapper_class}">' +
157 WEEKDAY_ROW_TEMPLATE: '<tr class="{calendar_weekdayrow_class}">' +
161 CALDAY_ROW_TEMPLATE: '<tr class="{calendar_row_class}">' +
165 WEEKDAY_TEMPLATE: '<th class="{calendar_weekday_class}">{weekdayname}</th>',
167 CALDAY_TEMPLATE: '<td class="{calendar_day_class}" {day_display_status}>' +
168 '<a href="#" class="{calendar_dayanchor_class}">' +
173 NAME: 'calendarBase',
182 }, '3.5.0' ,{requires:['widget', 'datatype-date']});