2 'url:dijit/templates/Calendar.html':"<table cellspacing=\"0\" cellpadding=\"0\" class=\"dijitCalendarContainer\" role=\"grid\" aria-labelledby=\"${id}_mddb ${id}_year\">\n\t<thead>\n\t\t<tr class=\"dijitReset dijitCalendarMonthContainer\" valign=\"top\">\n\t\t\t<th class='dijitReset dijitCalendarArrow' data-dojo-attach-point=\"decrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarDecrease\" role=\"presentation\"/>\n\t\t\t\t<span data-dojo-attach-point=\"decreaseArrowNode\" class=\"dijitA11ySideArrow\">-</span>\n\t\t\t</th>\n\t\t\t<th class='dijitReset' colspan=\"5\">\n\t\t\t\t<div data-dojo-attach-point=\"monthNode\">\n\t\t\t\t</div>\n\t\t\t</th>\n\t\t\t<th class='dijitReset dijitCalendarArrow' data-dojo-attach-point=\"incrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarIncrease\" role=\"presentation\"/>\n\t\t\t\t<span data-dojo-attach-point=\"increaseArrowNode\" class=\"dijitA11ySideArrow\">+</span>\n\t\t\t</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t${!dayCellsHtml}\n\t\t</tr>\n\t</thead>\n\t<tbody data-dojo-attach-point=\"dateRowsNode\" data-dojo-attach-event=\"onclick: _onDayClick\" class=\"dijitReset dijitCalendarBodyContainer\">\n\t\t\t${!dateRowsHtml}\n\t</tbody>\n\t<tfoot class=\"dijitReset dijitCalendarYearContainer\">\n\t\t<tr>\n\t\t\t<td class='dijitReset' valign=\"top\" colspan=\"7\" role=\"presentation\">\n\t\t\t\t<div class=\"dijitCalendarYearLabel\">\n\t\t\t\t\t<span data-dojo-attach-point=\"previousYearLabelNode\" class=\"dijitInline dijitCalendarPreviousYear\" role=\"button\"></span>\n\t\t\t\t\t<span data-dojo-attach-point=\"currentYearLabelNode\" class=\"dijitInline dijitCalendarSelectedYear\" role=\"button\" id=\"${id}_year\"></span>\n\t\t\t\t\t<span data-dojo-attach-point=\"nextYearLabelNode\" class=\"dijitInline dijitCalendarNextYear\" role=\"button\"></span>\n\t\t\t\t</div>\n\t\t\t</td>\n\t\t</tr>\n\t</tfoot>\n</table>\n"}});
3 define("dijit/CalendarLite", [
4 "dojo/_base/array", // array.forEach array.map
5 "dojo/_base/declare", // declare
6 "dojo/cldr/supplemental", // cldrSupplemental.getFirstDayOfWeek
9 "dojo/dom", // dom.setSelectable
10 "dojo/dom-class", // domClass.contains
11 "dojo/_base/event", // event.stop
12 "dojo/_base/lang", // lang.getObject, lang.hitch
13 "dojo/_base/sniff", // has("ie") has("webkit")
14 "dojo/string", // string.substitute
15 "dojo/_base/window", // win.doc.createTextNode
18 "dojo/text!./templates/Calendar.html"
19 ], function(array, declare, cldrSupplemental, date, local, dom, domClass, event, lang, has, string, win,
20 _WidgetBase, _TemplatedMixin, template){
23 var _WidgetBase = dijit._WidgetBase;
24 var _TemplatedMixin = dijit._TemplatedMixin;
30 // Lightweight version of Calendar widget aimed towards mobile use
32 var CalendarLite = declare("dijit.CalendarLite", [_WidgetBase, _TemplatedMixin], {
34 // Lightweight version of Calendar widget aimed towards mobile use
37 // A simple GUI for choosing a date in the context of a monthly calendar.
38 // This widget can't be used in a form because it doesn't serialize the date to an
39 // `<input>` field. For a form element, use dijit.form.DateTextBox instead.
41 // Note that the parser takes all dates attributes passed in the
42 // [RFC 3339 format](http://www.faqs.org/rfcs/rfc3339.html), e.g. `2005-06-30T08:05:00-07:00`
43 // so that they are serializable and locale-independent.
45 // Also note that this widget isn't keyboard accessible; use dijit.Calendar for that
47 // | var calendar = new dijit.CalendarLite({}, dojo.byId("calendarNode"));
50 // | <div data-dojo-type="dijit.CalendarLite"></div>
52 // Template for main calendar
53 templateString: template,
55 // Template for cell for a day of the week (ex: M)
56 dowTemplateString: '<th class="dijitReset dijitCalendarDayLabelTemplate" role="columnheader"><span class="dijitCalendarDayLabel">${d}</span></th>',
58 // Templates for a single date (ex: 13), and for a row for a week (ex: 20 21 22 23 24 25 26)
59 dateTemplateString: '<td class="dijitReset" role="gridcell" data-dojo-attach-point="dateCells"><span class="dijitCalendarDateLabel" data-dojo-attach-point="dateLabels"></span></td>',
60 weekTemplateString: '<tr class="dijitReset dijitCalendarWeekTemplate" role="row">${d}${d}${d}${d}${d}${d}${d}</tr>',
63 // The currently selected Date, initially set to invalid date to indicate no selection.
65 // TODO: for 2.0 make this a string (ISO format) rather than a Date
67 // datePackage: String
68 // JavaScript object containing Calendar functions. Uses Gregorian Calendar routines
69 // from dojo.date by default.
73 // How to represent the days of the week in the calendar header. See locale
77 // Order fields are traversed when user hits the tab key
81 // Date object containing the currently focused date, or the date which would be focused
82 // if the calendar itself was focused. Also indicates which year and month to display,
83 // i.e. the current "page" the calendar is on.
84 currentFocus: new Date(),
86 baseClass:"dijitCalendar",
88 _isValidDate: function(/*Date*/ value){
90 // Runs various tests on the value, checking that it's a valid date, rather
94 return value && !isNaN(value) && typeof value == "object" &&
95 value.toString() != this.constructor.prototype.value.toString();
98 _getValueAttr: function(){
100 // Support get('value')
102 // this.value is set to 1AM, but return midnight, local time for back-compat
103 if(this.value && !isNaN(this.value)){
104 var value = new this.dateClassObj(this.value);
105 value.setHours(0, 0, 0, 0);
107 // If daylight savings pushes midnight to the previous date, fix the Date
108 // object to point at 1am so it will represent the correct day. See #9366
109 if(value.getDate() < this.value.getDate()){
110 value = this.dateFuncObj.add(value, "hour", 1);
118 _setValueAttr: function(/*Date|Number*/ value, /*Boolean*/ priorityChange){
120 // Support set("value", ...)
122 // Set the current date and update the UI. If the date is disabled, the value will
123 // not change, but the display will change to the corresponding month.
125 // Either a Date or the number of seconds since 1970.
129 // convert from Number to Date, or make copy of Date object so that setHours() call below
130 // doesn't affect original value
131 value = new this.dateClassObj(value);
133 if(this._isValidDate(value)){
134 if(!this._isValidDate(this.value) || this.dateFuncObj.compare(value, this.value)){
135 value.setHours(1, 0, 0, 0); // round to nearest day (1am to avoid issues when DST shift occurs at midnight, see #8521, #9366)
137 if(!this.isDisabledDate(value, this.lang)){
138 this._set("value", value);
140 // Set focus cell to the new value. Arguably this should only happen when there isn't a current
141 // focus point. This will also repopulate the grid, showing the new selected value (and possibly
143 this.set("currentFocus", value);
145 if(priorityChange || typeof priorityChange == "undefined"){
146 this.onChange(this.get('value'));
151 // clear value, and repopulate grid (to deselect the previously selected day) without changing currentFocus
152 this._set("value", null);
153 this.set("currentFocus", this.currentFocus);
157 _setText: function(node, text){
159 // This just sets the content of node to the specified text.
160 // Can't do "node.innerHTML=text" because of an IE bug w/tables, see #3434.
163 while(node.firstChild){
164 node.removeChild(node.firstChild);
166 node.appendChild(win.doc.createTextNode(text));
169 _populateGrid: function(){
171 // Fills in the calendar grid with each day (1-31)
175 var month = new this.dateClassObj(this.currentFocus);
178 var firstDay = month.getDay(),
179 daysInMonth = this.dateFuncObj.getDaysInMonth(month),
180 daysInPreviousMonth = this.dateFuncObj.getDaysInMonth(this.dateFuncObj.add(month, "month", -1)),
181 today = new this.dateClassObj(),
182 dayOffset = cldrSupplemental.getFirstDayOfWeek(this.lang);
183 if(dayOffset > firstDay){ dayOffset -= 7; }
185 // Mapping from date (as specified by number returned from Date.valueOf()) to corresponding <td>
186 this._date2cell = {};
188 // Iterate through dates in the calendar and fill in date numbers and style info
189 array.forEach(this.dateCells, function(template, idx){
190 var i = idx + dayOffset;
191 var date = new this.dateClassObj(month),
192 number, clazz = "dijitCalendar", adj = 0;
195 number = daysInPreviousMonth - firstDay + i + 1;
198 }else if(i >= (firstDay + daysInMonth)){
199 number = i - firstDay - daysInMonth + 1;
203 number = i - firstDay + 1;
208 date = this.dateFuncObj.add(date, "month", adj);
210 date.setDate(number);
212 if(!this.dateFuncObj.compare(date, today, "date")){
213 clazz = "dijitCalendarCurrentDate " + clazz;
216 if(this._isSelectedDate(date, this.lang)){
217 clazz = "dijitCalendarSelectedDate " + clazz;
218 template.setAttribute("aria-selected", true);
220 template.setAttribute("aria-selected", false);
223 if(this.isDisabledDate(date, this.lang)){
224 clazz = "dijitCalendarDisabledDate " + clazz;
225 template.setAttribute("aria-disabled", true);
227 clazz = "dijitCalendarEnabledDate " + clazz;
228 template.removeAttribute("aria-disabled");
231 var clazz2 = this.getClassForDate(date, this.lang);
233 clazz = clazz2 + " " + clazz;
236 template.className = clazz + "Month dijitCalendarDateTemplate";
238 // Each cell has an associated integer value representing it's date
239 var dateVal = date.valueOf();
240 this._date2cell[dateVal] = template;
241 template.dijitDateValue = dateVal;
243 // Set Date string (ex: "13").
244 this._setText(this.dateLabels[idx], date.getDateLocalized ? date.getDateLocalized(this.lang) : date.getDate());
247 // set name of this month
248 this.monthWidget.set("month", month);
250 // Fill in localized prev/current/next years
251 var y = month.getFullYear() - 1;
252 var d = new this.dateClassObj();
253 array.forEach(["previous", "current", "next"], function(name){
255 this._setText(this[name+"YearLabelNode"],
256 this.dateLocaleModule.format(d, {selector:'year', locale:this.lang}));
260 goToToday: function(){
262 // Sets calendar's value to today's date
263 this.set('value', new this.dateClassObj());
266 constructor: function(/*Object*/args){
267 this.datePackage = args.datePackage || this.datePackage;
268 this.dateFuncObj = typeof this.datePackage == "string" ?
269 lang.getObject(this.datePackage, false) :// "string" part for back-compat, remove for 2.0
271 this.dateClassObj = this.dateFuncObj.Date || Date;
272 this.dateLocaleModule = lang.getObject("locale", false, this.dateFuncObj);
275 _createMonthWidget: function(){
277 // Creates the drop down button that displays the current month and lets user pick a new one
279 return CalendarLite._MonthWidget({
282 dateLocaleModule: this.dateLocaleModule
286 buildRendering: function(){
287 // Markup for days of the week (referenced from template)
288 var d = this.dowTemplateString,
289 dayNames = this.dateLocaleModule.getNames('days', this.dayWidth, 'standAlone', this.lang),
290 dayOffset = cldrSupplemental.getFirstDayOfWeek(this.lang);
291 this.dayCellsHtml = string.substitute([d,d,d,d,d,d,d].join(""), {d: ""}, function(){
292 return dayNames[dayOffset++ % 7]
295 // Markup for dates of the month (referenced from template), but without numbers filled in
296 var r = string.substitute(this.weekTemplateString, {d: this.dateTemplateString});
297 this.dateRowsHtml = [r,r,r,r,r,r].join("");
299 // Instantiate from template.
300 // dateCells and dateLabels arrays filled when _Templated parses my template.
302 this.dateLabels = [];
303 this.inherited(arguments);
305 dom.setSelectable(this.domNode, false);
307 var dateObj = new this.dateClassObj(this.currentFocus);
309 this._supportingWidgets.push(this.monthWidget = this._createMonthWidget());
311 this.set('currentFocus', dateObj, false); // draw the grid to the month specified by currentFocus
313 // Set up connects for increment/decrement of months/years
314 var connect = lang.hitch(this, function(nodeProp, part, amount){
315 this.connect(this[nodeProp], "onclick", function(){
316 this._setCurrentFocusAttr(this.dateFuncObj.add(this.currentFocus, part, amount));
319 connect("incrementMonth", "month", 1);
320 connect("decrementMonth", "month", -1);
321 connect("nextYearLabelNode", "year", 1);
322 connect("previousYearLabelNode", "year", -1);
325 _setCurrentFocusAttr: function(/*Date*/ date, /*Boolean*/ forceFocus){
327 // If the calendar currently has focus, then focuses specified date,
328 // changing the currently displayed month/year if necessary.
329 // If the calendar doesn't have focus, updates currently
330 // displayed month/year, and sets the cell that will get focus.
332 // If true, will focus() the cell even if calendar itself doesn't have focus
334 var oldFocus = this.currentFocus,
335 oldCell = oldFocus && this._date2cell ? this._date2cell[oldFocus.valueOf()] : null;
337 // round specified value to nearest day (1am to avoid issues when DST shift occurs at midnight, see #8521, #9366)
338 date = new this.dateClassObj(date);
339 date.setHours(1, 0, 0, 0);
341 this._set("currentFocus", date);
343 // TODO: only re-populate grid when month/year has changed
344 this._populateGrid();
346 // set tabIndex=0 on new cell, and focus it (but only if Calendar itself is focused)
347 var newCell = this._date2cell[date.valueOf()];
348 newCell.setAttribute("tabIndex", this.tabIndex);
349 if(this.focused || forceFocus){
353 // set tabIndex=-1 on old focusable cell
354 if(oldCell && oldCell != newCell){
355 if(has("webkit")){ // see #11064 about webkit bug
356 oldCell.setAttribute("tabIndex", "-1");
358 oldCell.removeAttribute("tabIndex");
365 // Focus the calendar by focusing one of the calendar cells
366 this._setCurrentFocusAttr(this.currentFocus, true);
369 _onDayClick: function(/*Event*/ evt){
371 // Handler for day clicks, selects the date if appropriate
375 for(var node = evt.target; node && !node.dijitDateValue; node = node.parentNode);
376 if(node && !domClass.contains(node, "dijitCalendarDisabledDate")){
377 this.set('value', node.dijitDateValue);
381 onChange: function(/*Date*/ /*===== date =====*/){
383 // Called only when the selected date has changed
386 _isSelectedDate: function(dateObject /*===== , locale =====*/){
388 // Extension point so developers can subclass Calendar to
389 // support multiple (concurrently) selected dates
393 // protected extension
394 return this._isValidDate(this.value) && !this.dateFuncObj.compare(dateObject, this.value, "date")
397 isDisabledDate: function(/*===== dateObject, locale =====*/){
399 // May be overridden to disable certain dates in the calendar e.g. `isDisabledDate=dojo.date.locale.isWeekend`
405 return false; // Boolean
409 getClassForDate: function(/*===== dateObject, locale =====*/){
411 // May be overridden to return CSS classes to associate with the date entry for the given dateObject,
412 // for example to indicate a holiday in specified locale.
424 CalendarLite._MonthWidget = declare("dijit.CalendarLite._MonthWidget", _WidgetBase, {
426 // Displays name of current month padded to the width of the month
427 // w/the longest name, so that changing months doesn't change width.
429 // Create as new dijit.Calendar._MonthWidget({
431 // dateLocaleModule: ...
434 _setMonthAttr: function(month){
436 // Set the current month to display as a label
437 var monthNames = this.dateLocaleModule.getNames('months', 'wide', 'standAlone', this.lang, month),
439 (has("ie") == 6 ? "" : "<div class='dijitSpacer'>" +
440 array.map(monthNames, function(s){ return "<div>" + s + "</div>"; }).join("") + "</div>");
442 // Set name of current month and also fill in spacer element with all the month names
443 // (invisible) so that the maximum width will affect layout. But not on IE6 because then
444 // the center <TH> overlaps the right <TH> (due to a browser bug).
445 this.domNode.innerHTML =
447 "<div class='dijitCalendarMonthLabel dijitCalendarCurrentMonthLabel'>" +
448 monthNames[month.getMonth()] + "</div>";