3
Copyright 2011 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")));
60
Y.log("Rendered Calendar UI");
63
bindUI : function () {
67
_getCutoffColumn : function (date) {
69
var normalizedDate = new Date(date.getFullYear(), date.getMonth(), 1);
70
return (1-normalizedDate.getDay());
74
_initCalendarHTML : function (baseDate) {
76
var startDate = baseDate || new Date(),
77
cutoffCol = this._getCutoffColumn(startDate),
78
headerData = {calheader: (startDate.getMonth()+1) + "/" +
79
startDate.getFullYear()},
81
weekdays = {wday1: 'Su',
90
partials["header_template"] = substitute(CalendarBase.HEADER_TEMPLATE,
93
partials["weekday_row"] = '';
95
each (weekdays, function (v) {
96
partials["weekday_row"] +=
97
substitute(CalendarBase.WEEKDAY_TEMPLATE,
102
partials["wdayrow_template"] = substitute(CalendarBase.WEEKDAY_ROW_TEMPLATE, partials);
108
for (var i = 0; i <= 5; i++) {
110
for (var j = -5; j <=7; j++) {
111
calday_row += substitute (CalendarBase.CALDAY_TEMPLATE, {day_content: '' + (j+7*i),
112
day_display_status: (j >= cutoffCol && j <= (cutoffCol + 6)) ? '' : 'style="display:none;"'});
114
row_array.push(substitute(CalendarBase.CALDAY_ROW_TEMPLATE, {calday_row: calday_row} ));
117
partials["body_template"] = row_array.join('\n');
119
var header = substitute(substitute (CalendarBase.CONTENT_TEMPLATE, partials),
120
CalendarBase.CALENDAR_CLASSES);
126
// Y.CalendarBase static properties
129
calendar_grid_class : CAL_GRID,
130
calendar_body_class : CAL_BODY,
131
calendar_hd_class : CAL_HD,
132
calendar_hd_wrapper_class: CAL_HD_WRAP,
133
calendar_weekdayrow_class: CAL_WDAYROW,
134
calendar_weekday_class: CAL_WDAY,
135
calendar_row_class: CAL_ROW,
136
calendar_day_class: CAL_DAY,
137
calendar_dayanchor_class: CAL_ANCHOR
140
CONTENT_TEMPLATE: '<table class="{calendar_grid_class}">' +
142
'{header_template}' +
143
'{wdayrow_template}' +
145
'<tbody class="{calendar_body_class}">' +
150
HEADER_TEMPLATE: '<tr>' +
151
'<th colspan="7" class="{calendar_hd_class}">' +
152
'<div id="calheader" class="{calendar_hd_wrapper_class}">' +
158
WEEKDAY_ROW_TEMPLATE: '<tr class="{calendar_weekdayrow_class}">' +
162
CALDAY_ROW_TEMPLATE: '<tr class="{calendar_row_class}">' +
166
WEEKDAY_TEMPLATE: '<th class="{calendar_weekday_class}">{weekdayname}</th>',
168
CALDAY_TEMPLATE: '<td class="{calendar_day_class}" {day_display_status}>' +
169
'<a href="#" class="{calendar_dayanchor_class}">' +
174
NAME: 'calendarBase',
183
}, '3.4.1' ,{requires:['widget', 'datatype-date']});