Calendar.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit.Calendar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit.Calendar"] = true;
  8. dojo.provide("dijit.Calendar");
  9. dojo.require("dojo.cldr.supplemental");
  10. dojo.require("dojo.date");
  11. dojo.require("dojo.date.locale");
  12. dojo.require("dijit._Widget");
  13. dojo.require("dijit._Templated");
  14. dojo.require("dijit._CssStateMixin");
  15. dojo.require("dijit.form.DropDownButton");
  16. dojo.declare(
  17. "dijit.Calendar",
  18. [dijit._Widget, dijit._Templated, dijit._CssStateMixin],
  19. {
  20. // summary:
  21. // A simple GUI for choosing a date in the context of a monthly calendar.
  22. //
  23. // description:
  24. // A simple GUI for choosing a date in the context of a monthly calendar.
  25. // This widget can't be used in a form because it doesn't serialize the date to an
  26. // `<input>` field. For a form element, use dijit.form.DateTextBox instead.
  27. //
  28. // Note that the parser takes all dates attributes passed in the
  29. // [RFC 3339 format](http://www.faqs.org/rfcs/rfc3339.html), e.g. `2005-06-30T08:05:00-07:00`
  30. // so that they are serializable and locale-independent.
  31. //
  32. // example:
  33. // | var calendar = new dijit.Calendar({}, dojo.byId("calendarNode"));
  34. //
  35. // example:
  36. // | <div dojoType="dijit.Calendar"></div>
  37. templateString: dojo.cache("dijit", "templates/Calendar.html", "<table cellspacing=\"0\" cellpadding=\"0\" class=\"dijitCalendarContainer\" role=\"grid\" dojoAttachEvent=\"onkeypress: _onKeyPress\" aria-labelledby=\"${id}_year\">\n\t<thead>\n\t\t<tr class=\"dijitReset dijitCalendarMonthContainer\" valign=\"top\">\n\t\t\t<th class='dijitReset dijitCalendarArrow' dojoAttachPoint=\"decrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarDecrease\" role=\"presentation\"/>\n\t\t\t\t<span dojoAttachPoint=\"decreaseArrowNode\" class=\"dijitA11ySideArrow\">-</span>\n\t\t\t</th>\n\t\t\t<th class='dijitReset' colspan=\"5\">\n\t\t\t\t<div dojoType=\"dijit.form.DropDownButton\" dojoAttachPoint=\"monthDropDownButton\"\n\t\t\t\t\tid=\"${id}_mddb\" tabIndex=\"-1\">\n\t\t\t\t</div>\n\t\t\t</th>\n\t\t\t<th class='dijitReset dijitCalendarArrow' dojoAttachPoint=\"incrementMonth\">\n\t\t\t\t<img src=\"${_blankGif}\" alt=\"\" class=\"dijitCalendarIncrementControl dijitCalendarIncrease\" role=\"presentation\"/>\n\t\t\t\t<span dojoAttachPoint=\"increaseArrowNode\" class=\"dijitA11ySideArrow\">+</span>\n\t\t\t</th>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<th class=\"dijitReset dijitCalendarDayLabelTemplate\" role=\"columnheader\"><span class=\"dijitCalendarDayLabel\"></span></th>\n\t\t</tr>\n\t</thead>\n\t<tbody dojoAttachEvent=\"onclick: _onDayClick, onmouseover: _onDayMouseOver, onmouseout: _onDayMouseOut, onmousedown: _onDayMouseDown, onmouseup: _onDayMouseUp\" class=\"dijitReset dijitCalendarBodyContainer\">\n\t\t<tr class=\"dijitReset dijitCalendarWeekTemplate\" role=\"row\">\n\t\t\t<td class=\"dijitReset dijitCalendarDateTemplate\" role=\"gridcell\"><span class=\"dijitCalendarDateLabel\"></span></td>\n\t\t</tr>\n\t</tbody>\n\t<tfoot class=\"dijitReset dijitCalendarYearContainer\">\n\t\t<tr>\n\t\t\t<td class='dijitReset' valign=\"top\" colspan=\"7\">\n\t\t\t\t<h3 class=\"dijitCalendarYearLabel\">\n\t\t\t\t\t<span dojoAttachPoint=\"previousYearLabelNode\" class=\"dijitInline dijitCalendarPreviousYear\"></span>\n\t\t\t\t\t<span dojoAttachPoint=\"currentYearLabelNode\" class=\"dijitInline dijitCalendarSelectedYear\" id=\"${id}_year\"></span>\n\t\t\t\t\t<span dojoAttachPoint=\"nextYearLabelNode\" class=\"dijitInline dijitCalendarNextYear\"></span>\n\t\t\t\t</h3>\n\t\t\t</td>\n\t\t</tr>\n\t</tfoot>\n</table>\n"),
  38. widgetsInTemplate: true,
  39. // value: Date
  40. // The currently selected Date, initially set to invalid date to indicate no selection.
  41. value: new Date(""),
  42. // TODO: for 2.0 make this a string (ISO format) rather than a Date
  43. // datePackage: String
  44. // JavaScript namespace to find Calendar routines. Uses Gregorian Calendar routines
  45. // at dojo.date by default.
  46. datePackage: "dojo.date",
  47. // dayWidth: String
  48. // How to represent the days of the week in the calendar header. See dojo.date.locale
  49. dayWidth: "narrow",
  50. // tabIndex: Integer
  51. // Order fields are traversed when user hits the tab key
  52. tabIndex: "0",
  53. // currentFocus: Date
  54. // Date object containing the currently focused date, or the date which would be focused
  55. // if the calendar itself was focused. Also indicates which year and month to display,
  56. // i.e. the current "page" the calendar is on.
  57. currentFocus: new Date(),
  58. baseClass:"dijitCalendar",
  59. // Set node classes for various mouse events, see dijit._CssStateMixin for more details
  60. cssStateNodes: {
  61. "decrementMonth": "dijitCalendarArrow",
  62. "incrementMonth": "dijitCalendarArrow",
  63. "previousYearLabelNode": "dijitCalendarPreviousYear",
  64. "nextYearLabelNode": "dijitCalendarNextYear"
  65. },
  66. _isValidDate: function(/*Date*/ value){
  67. // summary:
  68. // Runs various tests on the value, checking that it's a valid date, rather
  69. // than blank or NaN.
  70. // tags:
  71. // private
  72. return value && !isNaN(value) && typeof value == "object" &&
  73. value.toString() != this.constructor.prototype.value.toString();
  74. },
  75. setValue: function(/*Date*/ value){
  76. // summary:
  77. // Deprecated. Use set('value', ...) instead.
  78. // tags:
  79. // deprecated
  80. dojo.deprecated("dijit.Calendar:setValue() is deprecated. Use set('value', ...) instead.", "", "2.0");
  81. this.set('value', value);
  82. },
  83. _getValueAttr: function(){
  84. // summary:
  85. // Support get('value')
  86. // this.value is set to 1AM, but return midnight, local time for back-compat
  87. var value = new this.dateClassObj(this.value);
  88. value.setHours(0, 0, 0, 0);
  89. // If daylight savings pushes midnight to the previous date, fix the Date
  90. // object to point at 1am so it will represent the correct day. See #9366
  91. if(value.getDate() < this.value.getDate()){
  92. value = this.dateFuncObj.add(value, "hour", 1);
  93. }
  94. return value;
  95. },
  96. _setValueAttr: function(/*Date|Number*/ value, /*Boolean*/ priorityChange){
  97. // summary:
  98. // Support set("value", ...)
  99. // description:
  100. // Set the current date and update the UI. If the date is disabled, the value will
  101. // not change, but the display will change to the corresponding month.
  102. // value:
  103. // Either a Date or the number of seconds since 1970.
  104. // tags:
  105. // protected
  106. if(value){
  107. // convert from Number to Date, or make copy of Date object so that setHours() call below
  108. // doesn't affect original value
  109. value = new this.dateClassObj(value);
  110. }
  111. if(this._isValidDate(value)){
  112. if(!this._isValidDate(this.value) || this.dateFuncObj.compare(value, this.value)){
  113. value.setHours(1, 0, 0, 0); // round to nearest day (1am to avoid issues when DST shift occurs at midnight, see #8521, #9366)
  114. if(!this.isDisabledDate(value, this.lang)){
  115. this._set("value", value);
  116. // Set focus cell to the new value. Arguably this should only happen when there isn't a current
  117. // focus point. This will also repopulate the grid, showing the new selected value (and possibly
  118. // new month/year).
  119. this.set("currentFocus", value);
  120. if(priorityChange || typeof priorityChange == "undefined"){
  121. this.onChange(this.get('value'));
  122. this.onValueSelected(this.get('value')); // remove in 2.0
  123. }
  124. }
  125. }
  126. }else{
  127. // clear value, and repopulate grid (to deselect the previously selected day) without changing currentFocus
  128. this._set("value", null);
  129. this.set("currentFocus", this.currentFocus);
  130. }
  131. },
  132. _setText: function(node, text){
  133. // summary:
  134. // This just sets the content of node to the specified text.
  135. // Can't do "node.innerHTML=text" because of an IE bug w/tables, see #3434.
  136. // tags:
  137. // private
  138. while(node.firstChild){
  139. node.removeChild(node.firstChild);
  140. }
  141. node.appendChild(dojo.doc.createTextNode(text));
  142. },
  143. _populateGrid: function(){
  144. // summary:
  145. // Fills in the calendar grid with each day (1-31)
  146. // tags:
  147. // private
  148. var month = new this.dateClassObj(this.currentFocus);
  149. month.setDate(1);
  150. var firstDay = month.getDay(),
  151. daysInMonth = this.dateFuncObj.getDaysInMonth(month),
  152. daysInPreviousMonth = this.dateFuncObj.getDaysInMonth(this.dateFuncObj.add(month, "month", -1)),
  153. today = new this.dateClassObj(),
  154. dayOffset = dojo.cldr.supplemental.getFirstDayOfWeek(this.lang);
  155. if(dayOffset > firstDay){ dayOffset -= 7; }
  156. // Iterate through dates in the calendar and fill in date numbers and style info
  157. dojo.query(".dijitCalendarDateTemplate", this.domNode).forEach(function(template, i){
  158. i += dayOffset;
  159. var date = new this.dateClassObj(month),
  160. number, clazz = "dijitCalendar", adj = 0;
  161. if(i < firstDay){
  162. number = daysInPreviousMonth - firstDay + i + 1;
  163. adj = -1;
  164. clazz += "Previous";
  165. }else if(i >= (firstDay + daysInMonth)){
  166. number = i - firstDay - daysInMonth + 1;
  167. adj = 1;
  168. clazz += "Next";
  169. }else{
  170. number = i - firstDay + 1;
  171. clazz += "Current";
  172. }
  173. if(adj){
  174. date = this.dateFuncObj.add(date, "month", adj);
  175. }
  176. date.setDate(number);
  177. if(!this.dateFuncObj.compare(date, today, "date")){
  178. clazz = "dijitCalendarCurrentDate " + clazz;
  179. }
  180. if(this._isSelectedDate(date, this.lang)){
  181. clazz = "dijitCalendarSelectedDate " + clazz;
  182. }
  183. if(this.isDisabledDate(date, this.lang)){
  184. clazz = "dijitCalendarDisabledDate " + clazz;
  185. }
  186. var clazz2 = this.getClassForDate(date, this.lang);
  187. if(clazz2){
  188. clazz = clazz2 + " " + clazz;
  189. }
  190. template.className = clazz + "Month dijitCalendarDateTemplate";
  191. template.dijitDateValue = date.valueOf(); // original code
  192. dojo.attr(template, "dijitDateValue", date.valueOf()); // so I can dojo.query() it
  193. var label = dojo.query(".dijitCalendarDateLabel", template)[0],
  194. text = date.getDateLocalized ? date.getDateLocalized(this.lang) : date.getDate();
  195. this._setText(label, text);
  196. }, this);
  197. // Repopulate month drop down list based on current year.
  198. // Need to do this to hide leap months in Hebrew calendar.
  199. var monthNames = this.dateLocaleModule.getNames('months', 'wide', 'standAlone', this.lang, month);
  200. this.monthDropDownButton.dropDown.set("months", monthNames);
  201. // Set name of current month and also fill in spacer element with all the month names
  202. // (invisible) so that the maximum width will affect layout. But not on IE6 because then
  203. // the center <TH> overlaps the right <TH> (due to a browser bug).
  204. this.monthDropDownButton.containerNode.innerHTML =
  205. (dojo.isIE == 6 ? "" : "<div class='dijitSpacer'>" + this.monthDropDownButton.dropDown.domNode.innerHTML + "</div>") +
  206. "<div class='dijitCalendarMonthLabel dijitCalendarCurrentMonthLabel'>" + monthNames[month.getMonth()] + "</div>";
  207. // Fill in localized prev/current/next years
  208. var y = month.getFullYear() - 1;
  209. var d = new this.dateClassObj();
  210. dojo.forEach(["previous", "current", "next"], function(name){
  211. d.setFullYear(y++);
  212. this._setText(this[name+"YearLabelNode"],
  213. this.dateLocaleModule.format(d, {selector:'year', locale:this.lang}));
  214. }, this);
  215. },
  216. goToToday: function(){
  217. // summary:
  218. // Sets calendar's value to today's date
  219. this.set('value', new this.dateClassObj());
  220. },
  221. constructor: function(/*Object*/args){
  222. var dateClass = (args.datePackage && (args.datePackage != "dojo.date"))? args.datePackage + ".Date" : "Date";
  223. this.dateClassObj = dojo.getObject(dateClass, false);
  224. this.datePackage = args.datePackage || this.datePackage;
  225. this.dateFuncObj = dojo.getObject(this.datePackage, false);
  226. this.dateLocaleModule = dojo.getObject(this.datePackage + ".locale", false);
  227. },
  228. postMixInProperties: function(){
  229. // Parser.instantiate sometimes passes in NaN for IE. Use default value in prototype instead.
  230. // TODO: remove this for 2.0 (thanks to #11511)
  231. if(isNaN(this.value)){ delete this.value; }
  232. this.inherited(arguments);
  233. },
  234. buildRendering: function(){
  235. this.inherited(arguments);
  236. dojo.setSelectable(this.domNode, false);
  237. var cloneClass = dojo.hitch(this, function(clazz, n){
  238. var template = dojo.query(clazz, this.domNode)[0];
  239. for(var i=0; i<n; i++){
  240. template.parentNode.appendChild(template.cloneNode(true));
  241. }
  242. });
  243. // clone the day label and calendar day templates 6 times to make 7 columns
  244. cloneClass(".dijitCalendarDayLabelTemplate", 6);
  245. cloneClass(".dijitCalendarDateTemplate", 6);
  246. // now make 6 week rows
  247. cloneClass(".dijitCalendarWeekTemplate", 5);
  248. // insert localized day names in the header
  249. var dayNames = this.dateLocaleModule.getNames('days', this.dayWidth, 'standAlone', this.lang);
  250. var dayOffset = dojo.cldr.supplemental.getFirstDayOfWeek(this.lang);
  251. dojo.query(".dijitCalendarDayLabel", this.domNode).forEach(function(label, i){
  252. this._setText(label, dayNames[(i + dayOffset) % 7]);
  253. }, this);
  254. var dateObj = new this.dateClassObj(this.currentFocus);
  255. this.monthDropDownButton.dropDown = new dijit.Calendar._MonthDropDown({
  256. id: this.id + "_mdd",
  257. onChange: dojo.hitch(this, "_onMonthSelect")
  258. });
  259. this.set('currentFocus', dateObj, false); // draw the grid to the month specified by currentFocus
  260. // Set up repeating mouse behavior for increment/decrement of months/years
  261. var _this = this;
  262. var typematic = function(nodeProp, dateProp, adj){
  263. _this._connects.push(
  264. dijit.typematic.addMouseListener(_this[nodeProp], _this, function(count){
  265. if(count >= 0){ _this._adjustDisplay(dateProp, adj); }
  266. }, 0.8, 500)
  267. );
  268. };
  269. typematic("incrementMonth", "month", 1);
  270. typematic("decrementMonth", "month", -1);
  271. typematic("nextYearLabelNode", "year", 1);
  272. typematic("previousYearLabelNode", "year", -1);
  273. },
  274. _adjustDisplay: function(/*String*/ part, /*int*/ amount){
  275. // summary:
  276. // Moves calendar forwards or backwards by months or years
  277. // part:
  278. // "month" or "year"
  279. // amount:
  280. // Number of months or years
  281. // tags:
  282. // private
  283. this._setCurrentFocusAttr(this.dateFuncObj.add(this.currentFocus, part, amount));
  284. },
  285. _setCurrentFocusAttr: function(/*Date*/ date, /*Boolean*/ forceFocus){
  286. // summary:
  287. // If the calendar currently has focus, then focuses specified date,
  288. // changing the currently displayed month/year if necessary.
  289. // If the calendar doesn't have focus, updates currently
  290. // displayed month/year, and sets the cell that will get focus.
  291. // forceFocus:
  292. // If true, will focus() the cell even if calendar itself doesn't have focus
  293. var oldFocus = this.currentFocus,
  294. oldCell = oldFocus ? dojo.query("[dijitDateValue=" + oldFocus.valueOf() + "]", this.domNode)[0] : null;
  295. // round specified value to nearest day (1am to avoid issues when DST shift occurs at midnight, see #8521, #9366)
  296. date = new this.dateClassObj(date);
  297. date.setHours(1, 0, 0, 0);
  298. this._set("currentFocus", date);
  299. // TODO: only re-populate grid when month/year has changed
  300. this._populateGrid();
  301. // set tabIndex=0 on new cell, and focus it (but only if Calendar itself is focused)
  302. var newCell = dojo.query("[dijitDateValue=" + date.valueOf() + "]", this.domNode)[0];
  303. newCell.setAttribute("tabIndex", this.tabIndex);
  304. if(this._focused || forceFocus){
  305. newCell.focus();
  306. }
  307. // set tabIndex=-1 on old focusable cell
  308. if(oldCell && oldCell != newCell){
  309. if(dojo.isWebKit){ // see #11064 about webkit bug
  310. oldCell.setAttribute("tabIndex", "-1");
  311. }else{
  312. oldCell.removeAttribute("tabIndex");
  313. }
  314. }
  315. },
  316. focus: function(){
  317. // summary:
  318. // Focus the calendar by focusing one of the calendar cells
  319. this._setCurrentFocusAttr(this.currentFocus, true);
  320. },
  321. _onMonthSelect: function(/*Number*/ newMonth){
  322. // summary:
  323. // Handler for when user selects a month from the drop down list
  324. // tags:
  325. // protected
  326. // move to selected month, bounding by the number of days in the month
  327. // (ex: dec 31 --> jan 28, not jan 31)
  328. this.currentFocus = this.dateFuncObj.add(this.currentFocus, "month",
  329. newMonth - this.currentFocus.getMonth());
  330. this._populateGrid();
  331. },
  332. _onDayClick: function(/*Event*/ evt){
  333. // summary:
  334. // Handler for day clicks, selects the date if appropriate
  335. // tags:
  336. // protected
  337. dojo.stopEvent(evt);
  338. for(var node = evt.target; node && !node.dijitDateValue; node = node.parentNode);
  339. if(node && !dojo.hasClass(node, "dijitCalendarDisabledDate")){
  340. this.set('value', node.dijitDateValue);
  341. }
  342. },
  343. _onDayMouseOver: function(/*Event*/ evt){
  344. // summary:
  345. // Handler for mouse over events on days, sets hovered style
  346. // tags:
  347. // protected
  348. // event can occur on <td> or the <span> inside the td,
  349. // set node to the <td>.
  350. var node =
  351. dojo.hasClass(evt.target, "dijitCalendarDateLabel") ?
  352. evt.target.parentNode :
  353. evt.target;
  354. if(node && (node.dijitDateValue || node == this.previousYearLabelNode || node == this.nextYearLabelNode) ){
  355. dojo.addClass(node, "dijitCalendarHoveredDate");
  356. this._currentNode = node;
  357. }
  358. },
  359. _onDayMouseOut: function(/*Event*/ evt){
  360. // summary:
  361. // Handler for mouse out events on days, clears hovered style
  362. // tags:
  363. // protected
  364. if(!this._currentNode){ return; }
  365. // if mouse out occurs moving from <td> to <span> inside <td>, ignore it
  366. if(evt.relatedTarget && evt.relatedTarget.parentNode == this._currentNode){ return; }
  367. var cls = "dijitCalendarHoveredDate";
  368. if(dojo.hasClass(this._currentNode, "dijitCalendarActiveDate")) {
  369. cls += " dijitCalendarActiveDate";
  370. }
  371. dojo.removeClass(this._currentNode, cls);
  372. this._currentNode = null;
  373. },
  374. _onDayMouseDown: function(/*Event*/ evt){
  375. var node = evt.target.parentNode;
  376. if(node && node.dijitDateValue){
  377. dojo.addClass(node, "dijitCalendarActiveDate");
  378. this._currentNode = node;
  379. }
  380. },
  381. _onDayMouseUp: function(/*Event*/ evt){
  382. var node = evt.target.parentNode;
  383. if(node && node.dijitDateValue){
  384. dojo.removeClass(node, "dijitCalendarActiveDate");
  385. }
  386. },
  387. //TODO: use typematic
  388. handleKey: function(/*Event*/ evt){
  389. // summary:
  390. // Provides keyboard navigation of calendar.
  391. // description:
  392. // Called from _onKeyPress() to handle keypress on a stand alone Calendar,
  393. // and also from `dijit.form._DateTimeTextBox` to pass a keypress event
  394. // from the `dijit.form.DateTextBox` to be handled in this widget
  395. // returns:
  396. // False if the key was recognized as a navigation key,
  397. // to indicate that the event was handled by Calendar and shouldn't be propogated
  398. // tags:
  399. // protected
  400. var dk = dojo.keys,
  401. increment = -1,
  402. interval,
  403. newValue = this.currentFocus;
  404. switch(evt.keyCode){
  405. case dk.RIGHT_ARROW:
  406. increment = 1;
  407. //fallthrough...
  408. case dk.LEFT_ARROW:
  409. interval = "day";
  410. if(!this.isLeftToRight()){ increment *= -1; }
  411. break;
  412. case dk.DOWN_ARROW:
  413. increment = 1;
  414. //fallthrough...
  415. case dk.UP_ARROW:
  416. interval = "week";
  417. break;
  418. case dk.PAGE_DOWN:
  419. increment = 1;
  420. //fallthrough...
  421. case dk.PAGE_UP:
  422. interval = evt.ctrlKey || evt.altKey ? "year" : "month";
  423. break;
  424. case dk.END:
  425. // go to the next month
  426. newValue = this.dateFuncObj.add(newValue, "month", 1);
  427. // subtract a day from the result when we're done
  428. interval = "day";
  429. //fallthrough...
  430. case dk.HOME:
  431. newValue = new this.dateClassObj(newValue);
  432. newValue.setDate(1);
  433. break;
  434. case dk.ENTER:
  435. case dk.SPACE:
  436. this.set("value", this.currentFocus);
  437. break;
  438. default:
  439. return true;
  440. }
  441. if(interval){
  442. newValue = this.dateFuncObj.add(newValue, interval, increment);
  443. }
  444. this._setCurrentFocusAttr(newValue);
  445. return false;
  446. },
  447. _onKeyPress: function(/*Event*/ evt){
  448. // summary:
  449. // For handling keypress events on a stand alone calendar
  450. if(!this.handleKey(evt)){
  451. dojo.stopEvent(evt);
  452. }
  453. },
  454. onValueSelected: function(/*Date*/ date){
  455. // summary:
  456. // Notification that a date cell was selected. It may be the same as the previous value.
  457. // description:
  458. // Formerly used by `dijit.form._DateTimeTextBox` (and thus `dijit.form.DateTextBox`)
  459. // to get notification when the user has clicked a date. Now onExecute() (above) is used.
  460. // tags:
  461. // protected
  462. },
  463. onChange: function(/*Date*/ date){
  464. // summary:
  465. // Called only when the selected date has changed
  466. },
  467. _isSelectedDate: function(/*Date*/ dateObject, /*String?*/ locale){
  468. // summary:
  469. // Extension point so developers can subclass Calendar to
  470. // support multiple (concurrently) selected dates
  471. // tags:
  472. // protected extension
  473. return this._isValidDate(this.value) && !this.dateFuncObj.compare(dateObject, this.value, "date")
  474. },
  475. isDisabledDate: function(/*Date*/ dateObject, /*String?*/ locale){
  476. // summary:
  477. // May be overridden to disable certain dates in the calendar e.g. `isDisabledDate=dojo.date.locale.isWeekend`
  478. // tags:
  479. // extension
  480. /*=====
  481. return false; // Boolean
  482. =====*/
  483. },
  484. getClassForDate: function(/*Date*/ dateObject, /*String?*/ locale){
  485. // summary:
  486. // May be overridden to return CSS classes to associate with the date entry for the given dateObject,
  487. // for example to indicate a holiday in specified locale.
  488. // tags:
  489. // extension
  490. /*=====
  491. return ""; // String
  492. =====*/
  493. }
  494. }
  495. );
  496. dojo.declare("dijit.Calendar._MonthDropDown", [dijit._Widget, dijit._Templated], {
  497. // summary:
  498. // The month drop down
  499. // months: String[]
  500. // List of names of months, possibly w/some undefined entries for Hebrew leap months
  501. // (ex: ["January", "February", undefined, "April", ...])
  502. months: [],
  503. templateString: "<div class='dijitCalendarMonthMenu dijitMenu' " +
  504. "dojoAttachEvent='onclick:_onClick,onmouseover:_onMenuHover,onmouseout:_onMenuHover'></div>",
  505. _setMonthsAttr: function(/*String[]*/ months){
  506. this.domNode.innerHTML = dojo.map(months, function(month, idx){
  507. return month ? "<div class='dijitCalendarMonthLabel' month='" + idx +"'>" + month + "</div>" : "";
  508. }).join("");
  509. },
  510. _onClick: function(/*Event*/ evt){
  511. this.onChange(dojo.attr(evt.target, "month"));
  512. },
  513. onChange: function(/*Number*/ month){
  514. // summary:
  515. // Callback when month is selected from drop down
  516. },
  517. _onMenuHover: function(evt){
  518. dojo.toggleClass(evt.target, "dijitCalendarMonthLabelHover", evt.type == "mouseover");
  519. }
  520. });
  521. }