PageRenderTime 61ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/www/ui/ui.datepicker.js

http://cupsfilter.googlecode.com/
JavaScript | 1490 lines | 1252 code | 61 blank | 177 comment | 402 complexity | 0e1ca3081e893ad40b86d100bb24d64e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-3.0
  1. /*
  2. * jQuery UI Datepicker 1.7.1
  3. *
  4. * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
  5. * Dual licensed under the MIT (MIT-LICENSE.txt)
  6. * and GPL (GPL-LICENSE.txt) licenses.
  7. *
  8. * http://docs.jquery.com/UI/Datepicker
  9. *
  10. * Depends:
  11. * ui.core.js
  12. */
  13. (function($) { // hide the namespace
  14. $.extend($.ui, { datepicker: { version: "1.7.1" } });
  15. var PROP_NAME = 'datepicker';
  16. /* Date picker manager.
  17. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  18. Settings for (groups of) date pickers are maintained in an instance object,
  19. allowing multiple different settings on the same page. */
  20. function Datepicker() {
  21. this.debug = false; // Change this to true to start debugging
  22. this._curInst = null; // The current instance in use
  23. this._keyEvent = false; // If the last event was a key event
  24. this._disabledInputs = []; // List of date picker inputs that have been disabled
  25. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  26. this._inDialog = false; // True if showing within a "dialog", false if not
  27. this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
  28. this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
  29. this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
  30. this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
  31. this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
  32. this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
  33. this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
  34. this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
  35. this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
  36. this.regional = []; // Available regional settings, indexed by language code
  37. this.regional[''] = { // Default regional settings
  38. closeText: 'Done', // Display text for close link
  39. prevText: 'Prev', // Display text for previous month link
  40. nextText: 'Next', // Display text for next month link
  41. currentText: 'Today', // Display text for current month link
  42. monthNames: ['January','February','March','April','May','June',
  43. 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
  44. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
  45. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
  46. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
  47. dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
  48. dateFormat: 'mm/dd/yy', // See format options on parseDate
  49. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  50. isRTL: false // True if right-to-left language, false if left-to-right
  51. };
  52. this._defaults = { // Global defaults for all the date picker instances
  53. showOn: 'focus', // 'focus' for popup on focus,
  54. // 'button' for trigger button, or 'both' for either
  55. showAnim: 'show', // Name of jQuery animation for popup
  56. showOptions: {}, // Options for enhanced animations
  57. defaultDate: null, // Used when field is blank: actual date,
  58. // +/-number for offset from today, null for today
  59. appendText: '', // Display text following the input box, e.g. showing the format
  60. buttonText: '...', // Text for trigger button
  61. buttonImage: '', // URL for trigger button image
  62. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  63. hideIfNoPrevNext: false, // True to hide next/previous month links
  64. // if not applicable, false to just disable them
  65. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  66. gotoCurrent: false, // True if today link goes back to current selection instead
  67. changeMonth: false, // True if month can be selected directly, false if only prev/next
  68. changeYear: false, // True if year can be selected directly, false if only prev/next
  69. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  70. yearRange: '-10:+10', // Range of years to display in drop-down,
  71. // either relative to current year (-nn:+nn) or absolute (nnnn:nnnn)
  72. showOtherMonths: false, // True to show dates in other months, false to leave blank
  73. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  74. // takes a Date and returns the number of the week for it
  75. shortYearCutoff: '+10', // Short year values < this are in the current century,
  76. // > this are in the previous century,
  77. // string value starting with '+' for current year + value
  78. minDate: null, // The earliest selectable date, or null for no limit
  79. maxDate: null, // The latest selectable date, or null for no limit
  80. duration: 'normal', // Duration of display/closure
  81. beforeShowDay: null, // Function that takes a date and returns an array with
  82. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
  83. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  84. beforeShow: null, // Function that takes an input field and
  85. // returns a set of custom settings for the date picker
  86. onSelect: null, // Define a callback function when a date is selected
  87. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  88. onClose: null, // Define a callback function when the datepicker is closed
  89. numberOfMonths: 1, // Number of months to show at a time
  90. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  91. stepMonths: 1, // Number of months to step back/forward
  92. stepBigMonths: 12, // Number of months to step back/forward for the big links
  93. altField: '', // Selector for an alternate field to store selected dates into
  94. altFormat: '', // The date format to use for the alternate field
  95. constrainInput: true, // The input is constrained by the current date format
  96. showButtonPanel: false // True to show button panel, false to not show it
  97. };
  98. $.extend(this._defaults, this.regional['']);
  99. this.dpDiv = $('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all ui-helper-hidden-accessible"></div>');
  100. }
  101. $.extend(Datepicker.prototype, {
  102. /* Class name added to elements to indicate already configured with a date picker. */
  103. markerClassName: 'hasDatepicker',
  104. /* Debug logging (if enabled). */
  105. log: function () {
  106. if (this.debug)
  107. console.log.apply('', arguments);
  108. },
  109. /* Override the default settings for all instances of the date picker.
  110. @param settings object - the new settings to use as defaults (anonymous object)
  111. @return the manager object */
  112. setDefaults: function(settings) {
  113. extendRemove(this._defaults, settings || {});
  114. return this;
  115. },
  116. /* Attach the date picker to a jQuery selection.
  117. @param target element - the target input field or division or span
  118. @param settings object - the new settings to use for this date picker instance (anonymous) */
  119. _attachDatepicker: function(target, settings) {
  120. // check for settings on the control itself - in namespace 'date:'
  121. var inlineSettings = null;
  122. for (var attrName in this._defaults) {
  123. var attrValue = target.getAttribute('date:' + attrName);
  124. if (attrValue) {
  125. inlineSettings = inlineSettings || {};
  126. try {
  127. inlineSettings[attrName] = eval(attrValue);
  128. } catch (err) {
  129. inlineSettings[attrName] = attrValue;
  130. }
  131. }
  132. }
  133. var nodeName = target.nodeName.toLowerCase();
  134. var inline = (nodeName == 'div' || nodeName == 'span');
  135. if (!target.id)
  136. target.id = 'dp' + (++this.uuid);
  137. var inst = this._newInst($(target), inline);
  138. inst.settings = $.extend({}, settings || {}, inlineSettings || {});
  139. if (nodeName == 'input') {
  140. this._connectDatepicker(target, inst);
  141. } else if (inline) {
  142. this._inlineDatepicker(target, inst);
  143. }
  144. },
  145. /* Create a new instance object. */
  146. _newInst: function(target, inline) {
  147. var id = target[0].id.replace(/([:\[\]\.])/g, '\\\\$1'); // escape jQuery meta chars
  148. return {id: id, input: target, // associated target
  149. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  150. drawMonth: 0, drawYear: 0, // month being drawn
  151. inline: inline, // is datepicker inline or not
  152. dpDiv: (!inline ? this.dpDiv : // presentation div
  153. $('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))};
  154. },
  155. /* Attach the date picker to an input field. */
  156. _connectDatepicker: function(target, inst) {
  157. var input = $(target);
  158. inst.trigger = $([]);
  159. if (input.hasClass(this.markerClassName))
  160. return;
  161. var appendText = this._get(inst, 'appendText');
  162. var isRTL = this._get(inst, 'isRTL');
  163. if (appendText)
  164. input[isRTL ? 'before' : 'after']('<span class="' + this._appendClass + '">' + appendText + '</span>');
  165. var showOn = this._get(inst, 'showOn');
  166. if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
  167. input.focus(this._showDatepicker);
  168. if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
  169. var buttonText = this._get(inst, 'buttonText');
  170. var buttonImage = this._get(inst, 'buttonImage');
  171. inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
  172. $('<img/>').addClass(this._triggerClass).
  173. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  174. $('<button type="button"></button>').addClass(this._triggerClass).
  175. html(buttonImage == '' ? buttonText : $('<img/>').attr(
  176. { src:buttonImage, alt:buttonText, title:buttonText })));
  177. input[isRTL ? 'before' : 'after'](inst.trigger);
  178. inst.trigger.click(function() {
  179. if ($.datepicker._datepickerShowing && $.datepicker._lastInput == target)
  180. $.datepicker._hideDatepicker();
  181. else
  182. $.datepicker._showDatepicker(target);
  183. return false;
  184. });
  185. }
  186. input.addClass(this.markerClassName).keydown(this._doKeyDown).keypress(this._doKeyPress).
  187. bind("setData.datepicker", function(event, key, value) {
  188. inst.settings[key] = value;
  189. }).bind("getData.datepicker", function(event, key) {
  190. return this._get(inst, key);
  191. });
  192. $.data(target, PROP_NAME, inst);
  193. },
  194. /* Attach an inline date picker to a div. */
  195. _inlineDatepicker: function(target, inst) {
  196. var divSpan = $(target);
  197. if (divSpan.hasClass(this.markerClassName))
  198. return;
  199. divSpan.addClass(this.markerClassName).append(inst.dpDiv).
  200. bind("setData.datepicker", function(event, key, value){
  201. inst.settings[key] = value;
  202. }).bind("getData.datepicker", function(event, key){
  203. return this._get(inst, key);
  204. });
  205. $.data(target, PROP_NAME, inst);
  206. this._setDate(inst, this._getDefaultDate(inst));
  207. this._updateDatepicker(inst);
  208. this._updateAlternate(inst);
  209. },
  210. /* Pop-up the date picker in a "dialog" box.
  211. @param input element - ignored
  212. @param dateText string - the initial date to display (in the current format)
  213. @param onSelect function - the function(dateText) to call when a date is selected
  214. @param settings object - update the dialog date picker instance's settings (anonymous object)
  215. @param pos int[2] - coordinates for the dialog's position within the screen or
  216. event - with x/y coordinates or
  217. leave empty for default (screen centre)
  218. @return the manager object */
  219. _dialogDatepicker: function(input, dateText, onSelect, settings, pos) {
  220. var inst = this._dialogInst; // internal instance
  221. if (!inst) {
  222. var id = 'dp' + (++this.uuid);
  223. this._dialogInput = $('<input type="text" id="' + id +
  224. '" size="1" style="position: absolute; top: -100px;"/>');
  225. this._dialogInput.keydown(this._doKeyDown);
  226. $('body').append(this._dialogInput);
  227. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  228. inst.settings = {};
  229. $.data(this._dialogInput[0], PROP_NAME, inst);
  230. }
  231. extendRemove(inst.settings, settings || {});
  232. this._dialogInput.val(dateText);
  233. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  234. if (!this._pos) {
  235. var browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  236. var browserHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
  237. var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  238. var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  239. this._pos = // should use actual width/height below
  240. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  241. }
  242. // move input on screen for focus, but hidden behind dialog
  243. this._dialogInput.css('left', this._pos[0] + 'px').css('top', this._pos[1] + 'px');
  244. inst.settings.onSelect = onSelect;
  245. this._inDialog = true;
  246. this.dpDiv.addClass(this._dialogClass);
  247. this._showDatepicker(this._dialogInput[0]);
  248. if ($.blockUI)
  249. $.blockUI(this.dpDiv);
  250. $.data(this._dialogInput[0], PROP_NAME, inst);
  251. return this;
  252. },
  253. /* Detach a datepicker from its control.
  254. @param target element - the target input field or division or span */
  255. _destroyDatepicker: function(target) {
  256. var $target = $(target);
  257. var inst = $.data(target, PROP_NAME);
  258. if (!$target.hasClass(this.markerClassName)) {
  259. return;
  260. }
  261. var nodeName = target.nodeName.toLowerCase();
  262. $.removeData(target, PROP_NAME);
  263. if (nodeName == 'input') {
  264. inst.trigger.remove();
  265. $target.siblings('.' + this._appendClass).remove().end().
  266. removeClass(this.markerClassName).
  267. unbind('focus', this._showDatepicker).
  268. unbind('keydown', this._doKeyDown).
  269. unbind('keypress', this._doKeyPress);
  270. } else if (nodeName == 'div' || nodeName == 'span')
  271. $target.removeClass(this.markerClassName).empty();
  272. },
  273. /* Enable the date picker to a jQuery selection.
  274. @param target element - the target input field or division or span */
  275. _enableDatepicker: function(target) {
  276. var $target = $(target);
  277. var inst = $.data(target, PROP_NAME);
  278. if (!$target.hasClass(this.markerClassName)) {
  279. return;
  280. }
  281. var nodeName = target.nodeName.toLowerCase();
  282. if (nodeName == 'input') {
  283. target.disabled = false;
  284. inst.trigger.filter("button").
  285. each(function() { this.disabled = false; }).end().
  286. filter("img").
  287. css({opacity: '1.0', cursor: ''});
  288. }
  289. else if (nodeName == 'div' || nodeName == 'span') {
  290. var inline = $target.children('.' + this._inlineClass);
  291. inline.children().removeClass('ui-state-disabled');
  292. }
  293. this._disabledInputs = $.map(this._disabledInputs,
  294. function(value) { return (value == target ? null : value); }); // delete entry
  295. },
  296. /* Disable the date picker to a jQuery selection.
  297. @param target element - the target input field or division or span */
  298. _disableDatepicker: function(target) {
  299. var $target = $(target);
  300. var inst = $.data(target, PROP_NAME);
  301. if (!$target.hasClass(this.markerClassName)) {
  302. return;
  303. }
  304. var nodeName = target.nodeName.toLowerCase();
  305. if (nodeName == 'input') {
  306. target.disabled = true;
  307. inst.trigger.filter("button").
  308. each(function() { this.disabled = true; }).end().
  309. filter("img").
  310. css({opacity: '0.5', cursor: 'default'});
  311. }
  312. else if (nodeName == 'div' || nodeName == 'span') {
  313. var inline = $target.children('.' + this._inlineClass);
  314. inline.children().addClass('ui-state-disabled');
  315. }
  316. this._disabledInputs = $.map(this._disabledInputs,
  317. function(value) { return (value == target ? null : value); }); // delete entry
  318. this._disabledInputs[this._disabledInputs.length] = target;
  319. },
  320. /* Is the first field in a jQuery collection disabled as a datepicker?
  321. @param target element - the target input field or division or span
  322. @return boolean - true if disabled, false if enabled */
  323. _isDisabledDatepicker: function(target) {
  324. if (!target) {
  325. return false;
  326. }
  327. for (var i = 0; i < this._disabledInputs.length; i++) {
  328. if (this._disabledInputs[i] == target)
  329. return true;
  330. }
  331. return false;
  332. },
  333. /* Retrieve the instance data for the target control.
  334. @param target element - the target input field or division or span
  335. @return object - the associated instance data
  336. @throws error if a jQuery problem getting data */
  337. _getInst: function(target) {
  338. try {
  339. return $.data(target, PROP_NAME);
  340. }
  341. catch (err) {
  342. throw 'Missing instance data for this datepicker';
  343. }
  344. },
  345. /* Update the settings for a date picker attached to an input field or division.
  346. @param target element - the target input field or division or span
  347. @param name object - the new settings to update or
  348. string - the name of the setting to change or
  349. @param value any - the new value for the setting (omit if above is an object) */
  350. _optionDatepicker: function(target, name, value) {
  351. var settings = name || {};
  352. if (typeof name == 'string') {
  353. settings = {};
  354. settings[name] = value;
  355. }
  356. var inst = this._getInst(target);
  357. if (inst) {
  358. if (this._curInst == inst) {
  359. this._hideDatepicker(null);
  360. }
  361. extendRemove(inst.settings, settings);
  362. var date = new Date();
  363. extendRemove(inst, {rangeStart: null, // start of range
  364. endDay: null, endMonth: null, endYear: null, // end of range
  365. selectedDay: date.getDate(), selectedMonth: date.getMonth(),
  366. selectedYear: date.getFullYear(), // starting point
  367. currentDay: date.getDate(), currentMonth: date.getMonth(),
  368. currentYear: date.getFullYear(), // current selection
  369. drawMonth: date.getMonth(), drawYear: date.getFullYear()}); // month being drawn
  370. this._updateDatepicker(inst);
  371. }
  372. },
  373. // change method deprecated
  374. _changeDatepicker: function(target, name, value) {
  375. this._optionDatepicker(target, name, value);
  376. },
  377. /* Redraw the date picker attached to an input field or division.
  378. @param target element - the target input field or division or span */
  379. _refreshDatepicker: function(target) {
  380. var inst = this._getInst(target);
  381. if (inst) {
  382. this._updateDatepicker(inst);
  383. }
  384. },
  385. /* Set the dates for a jQuery selection.
  386. @param target element - the target input field or division or span
  387. @param date Date - the new date
  388. @param endDate Date - the new end date for a range (optional) */
  389. _setDateDatepicker: function(target, date, endDate) {
  390. var inst = this._getInst(target);
  391. if (inst) {
  392. this._setDate(inst, date, endDate);
  393. this._updateDatepicker(inst);
  394. this._updateAlternate(inst);
  395. }
  396. },
  397. /* Get the date(s) for the first entry in a jQuery selection.
  398. @param target element - the target input field or division or span
  399. @return Date - the current date or
  400. Date[2] - the current dates for a range */
  401. _getDateDatepicker: function(target) {
  402. var inst = this._getInst(target);
  403. if (inst && !inst.inline)
  404. this._setDateFromField(inst);
  405. return (inst ? this._getDate(inst) : null);
  406. },
  407. /* Handle keystrokes. */
  408. _doKeyDown: function(event) {
  409. var inst = $.datepicker._getInst(event.target);
  410. var handled = true;
  411. var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
  412. inst._keyEvent = true;
  413. if ($.datepicker._datepickerShowing)
  414. switch (event.keyCode) {
  415. case 9: $.datepicker._hideDatepicker(null, '');
  416. break; // hide on tab out
  417. case 13: var sel = $('td.' + $.datepicker._dayOverClass +
  418. ', td.' + $.datepicker._currentClass, inst.dpDiv);
  419. if (sel[0])
  420. $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
  421. else
  422. $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
  423. return false; // don't submit the form
  424. break; // select the value on enter
  425. case 27: $.datepicker._hideDatepicker(null, $.datepicker._get(inst, 'duration'));
  426. break; // hide on escape
  427. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  428. -$.datepicker._get(inst, 'stepBigMonths') :
  429. -$.datepicker._get(inst, 'stepMonths')), 'M');
  430. break; // previous month/year on page up/+ ctrl
  431. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  432. +$.datepicker._get(inst, 'stepBigMonths') :
  433. +$.datepicker._get(inst, 'stepMonths')), 'M');
  434. break; // next month/year on page down/+ ctrl
  435. case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
  436. handled = event.ctrlKey || event.metaKey;
  437. break; // clear on ctrl or command +end
  438. case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
  439. handled = event.ctrlKey || event.metaKey;
  440. break; // current on ctrl or command +home
  441. case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
  442. handled = event.ctrlKey || event.metaKey;
  443. // -1 day on ctrl or command +left
  444. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  445. -$.datepicker._get(inst, 'stepBigMonths') :
  446. -$.datepicker._get(inst, 'stepMonths')), 'M');
  447. // next month/year on alt +left on Mac
  448. break;
  449. case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
  450. handled = event.ctrlKey || event.metaKey;
  451. break; // -1 week on ctrl or command +up
  452. case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
  453. handled = event.ctrlKey || event.metaKey;
  454. // +1 day on ctrl or command +right
  455. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  456. +$.datepicker._get(inst, 'stepBigMonths') :
  457. +$.datepicker._get(inst, 'stepMonths')), 'M');
  458. // next month/year on alt +right
  459. break;
  460. case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
  461. handled = event.ctrlKey || event.metaKey;
  462. break; // +1 week on ctrl or command +down
  463. default: handled = false;
  464. }
  465. else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
  466. $.datepicker._showDatepicker(this);
  467. else {
  468. handled = false;
  469. }
  470. if (handled) {
  471. event.preventDefault();
  472. event.stopPropagation();
  473. }
  474. },
  475. /* Filter entered characters - based on date format. */
  476. _doKeyPress: function(event) {
  477. var inst = $.datepicker._getInst(event.target);
  478. if ($.datepicker._get(inst, 'constrainInput')) {
  479. var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
  480. var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
  481. return event.ctrlKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
  482. }
  483. },
  484. /* Pop-up the date picker for a given input field.
  485. @param input element - the input field attached to the date picker or
  486. event - if triggered by focus */
  487. _showDatepicker: function(input) {
  488. input = input.target || input;
  489. if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
  490. input = $('input', input.parentNode)[0];
  491. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
  492. return;
  493. var inst = $.datepicker._getInst(input);
  494. var beforeShow = $.datepicker._get(inst, 'beforeShow');
  495. extendRemove(inst.settings, (beforeShow ? beforeShow.apply(input, [input, inst]) : {}));
  496. $.datepicker._hideDatepicker(null, '');
  497. $.datepicker._lastInput = input;
  498. $.datepicker._setDateFromField(inst);
  499. if ($.datepicker._inDialog) // hide cursor
  500. input.value = '';
  501. if (!$.datepicker._pos) { // position below input
  502. $.datepicker._pos = $.datepicker._findPos(input);
  503. $.datepicker._pos[1] += input.offsetHeight; // add the height
  504. }
  505. var isFixed = false;
  506. $(input).parents().each(function() {
  507. isFixed |= $(this).css('position') == 'fixed';
  508. return !isFixed;
  509. });
  510. if (isFixed && $.browser.opera) { // correction for Opera when fixed and scrolled
  511. $.datepicker._pos[0] -= document.documentElement.scrollLeft;
  512. $.datepicker._pos[1] -= document.documentElement.scrollTop;
  513. }
  514. var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  515. $.datepicker._pos = null;
  516. inst.rangeStart = null;
  517. // determine sizing offscreen
  518. inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
  519. $.datepicker._updateDatepicker(inst);
  520. // fix width for dynamic number of date pickers
  521. // and adjust position before showing
  522. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  523. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  524. 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
  525. left: offset.left + 'px', top: offset.top + 'px'});
  526. if (!inst.inline) {
  527. var showAnim = $.datepicker._get(inst, 'showAnim') || 'show';
  528. var duration = $.datepicker._get(inst, 'duration');
  529. var postProcess = function() {
  530. $.datepicker._datepickerShowing = true;
  531. if ($.browser.msie && parseInt($.browser.version,10) < 7) // fix IE < 7 select problems
  532. $('iframe.ui-datepicker-cover').css({width: inst.dpDiv.width() + 4,
  533. height: inst.dpDiv.height() + 4});
  534. };
  535. if ($.effects && $.effects[showAnim])
  536. inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  537. else
  538. inst.dpDiv[showAnim](duration, postProcess);
  539. if (duration == '')
  540. postProcess();
  541. if (inst.input[0].type != 'hidden')
  542. inst.input[0].focus();
  543. $.datepicker._curInst = inst;
  544. }
  545. },
  546. /* Generate the date picker content. */
  547. _updateDatepicker: function(inst) {
  548. var dims = {width: inst.dpDiv.width() + 4,
  549. height: inst.dpDiv.height() + 4};
  550. var self = this;
  551. inst.dpDiv.empty().append(this._generateHTML(inst))
  552. .find('iframe.ui-datepicker-cover').
  553. css({width: dims.width, height: dims.height})
  554. .end()
  555. .find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a')
  556. .bind('mouseout', function(){
  557. $(this).removeClass('ui-state-hover');
  558. if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
  559. if(this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
  560. })
  561. .bind('mouseover', function(){
  562. if (!self._isDisabledDatepicker( inst.inline ? inst.dpDiv.parent()[0] : inst.input[0])) {
  563. $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
  564. $(this).addClass('ui-state-hover');
  565. if(this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
  566. if(this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
  567. }
  568. })
  569. .end()
  570. .find('.' + this._dayOverClass + ' a')
  571. .trigger('mouseover')
  572. .end();
  573. var numMonths = this._getNumberOfMonths(inst);
  574. var cols = numMonths[1];
  575. var width = 17;
  576. if (cols > 1) {
  577. inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
  578. } else {
  579. inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
  580. }
  581. inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
  582. 'Class']('ui-datepicker-multi');
  583. inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
  584. 'Class']('ui-datepicker-rtl');
  585. if (inst.input && inst.input[0].type != 'hidden' && inst == $.datepicker._curInst)
  586. $(inst.input[0]).focus();
  587. },
  588. /* Check positioning to remain on screen. */
  589. _checkOffset: function(inst, offset, isFixed) {
  590. var dpWidth = inst.dpDiv.outerWidth();
  591. var dpHeight = inst.dpDiv.outerHeight();
  592. var inputWidth = inst.input ? inst.input.outerWidth() : 0;
  593. var inputHeight = inst.input ? inst.input.outerHeight() : 0;
  594. var viewWidth = (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) + $(document).scrollLeft();
  595. var viewHeight = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) + $(document).scrollTop();
  596. offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
  597. offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
  598. offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  599. // now check if datepicker is showing outside window viewport - move to a better place if so.
  600. offset.left -= (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ? Math.abs(offset.left + dpWidth - viewWidth) : 0;
  601. offset.top -= (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ? Math.abs(offset.top + dpHeight + inputHeight*2 - viewHeight) : 0;
  602. return offset;
  603. },
  604. /* Find an object's position on the screen. */
  605. _findPos: function(obj) {
  606. while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
  607. obj = obj.nextSibling;
  608. }
  609. var position = $(obj).offset();
  610. return [position.left, position.top];
  611. },
  612. /* Hide the date picker from view.
  613. @param input element - the input field attached to the date picker
  614. @param duration string - the duration over which to close the date picker */
  615. _hideDatepicker: function(input, duration) {
  616. var inst = this._curInst;
  617. if (!inst || (input && inst != $.data(input, PROP_NAME)))
  618. return;
  619. if (inst.stayOpen)
  620. this._selectDate('#' + inst.id, this._formatDate(inst,
  621. inst.currentDay, inst.currentMonth, inst.currentYear));
  622. inst.stayOpen = false;
  623. if (this._datepickerShowing) {
  624. duration = (duration != null ? duration : this._get(inst, 'duration'));
  625. var showAnim = this._get(inst, 'showAnim');
  626. var postProcess = function() {
  627. $.datepicker._tidyDialog(inst);
  628. };
  629. if (duration != '' && $.effects && $.effects[showAnim])
  630. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'),
  631. duration, postProcess);
  632. else
  633. inst.dpDiv[(duration == '' ? 'hide' : (showAnim == 'slideDown' ? 'slideUp' :
  634. (showAnim == 'fadeIn' ? 'fadeOut' : 'hide')))](duration, postProcess);
  635. if (duration == '')
  636. this._tidyDialog(inst);
  637. var onClose = this._get(inst, 'onClose');
  638. if (onClose)
  639. onClose.apply((inst.input ? inst.input[0] : null),
  640. [(inst.input ? inst.input.val() : ''), inst]); // trigger custom callback
  641. this._datepickerShowing = false;
  642. this._lastInput = null;
  643. if (this._inDialog) {
  644. this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
  645. if ($.blockUI) {
  646. $.unblockUI();
  647. $('body').append(this.dpDiv);
  648. }
  649. }
  650. this._inDialog = false;
  651. }
  652. this._curInst = null;
  653. },
  654. /* Tidy up after a dialog display. */
  655. _tidyDialog: function(inst) {
  656. inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
  657. },
  658. /* Close date picker if clicked elsewhere. */
  659. _checkExternalClick: function(event) {
  660. if (!$.datepicker._curInst)
  661. return;
  662. var $target = $(event.target);
  663. if (($target.parents('#' + $.datepicker._mainDivId).length == 0) &&
  664. !$target.hasClass($.datepicker.markerClassName) &&
  665. !$target.hasClass($.datepicker._triggerClass) &&
  666. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI))
  667. $.datepicker._hideDatepicker(null, '');
  668. },
  669. /* Adjust one of the date sub-fields. */
  670. _adjustDate: function(id, offset, period) {
  671. var target = $(id);
  672. var inst = this._getInst(target[0]);
  673. if (this._isDisabledDatepicker(target[0])) {
  674. return;
  675. }
  676. this._adjustInstDate(inst, offset +
  677. (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
  678. period);
  679. this._updateDatepicker(inst);
  680. },
  681. /* Action for current link. */
  682. _gotoToday: function(id) {
  683. var target = $(id);
  684. var inst = this._getInst(target[0]);
  685. if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
  686. inst.selectedDay = inst.currentDay;
  687. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  688. inst.drawYear = inst.selectedYear = inst.currentYear;
  689. }
  690. else {
  691. var date = new Date();
  692. inst.selectedDay = date.getDate();
  693. inst.drawMonth = inst.selectedMonth = date.getMonth();
  694. inst.drawYear = inst.selectedYear = date.getFullYear();
  695. }
  696. this._notifyChange(inst);
  697. this._adjustDate(target);
  698. },
  699. /* Action for selecting a new month/year. */
  700. _selectMonthYear: function(id, select, period) {
  701. var target = $(id);
  702. var inst = this._getInst(target[0]);
  703. inst._selectingMonthYear = false;
  704. inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
  705. inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
  706. parseInt(select.options[select.selectedIndex].value,10);
  707. this._notifyChange(inst);
  708. this._adjustDate(target);
  709. },
  710. /* Restore input focus after not changing month/year. */
  711. _clickMonthYear: function(id) {
  712. var target = $(id);
  713. var inst = this._getInst(target[0]);
  714. if (inst.input && inst._selectingMonthYear && !$.browser.msie)
  715. inst.input[0].focus();
  716. inst._selectingMonthYear = !inst._selectingMonthYear;
  717. },
  718. /* Action for selecting a day. */
  719. _selectDay: function(id, month, year, td) {
  720. var target = $(id);
  721. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  722. return;
  723. }
  724. var inst = this._getInst(target[0]);
  725. inst.selectedDay = inst.currentDay = $('a', td).html();
  726. inst.selectedMonth = inst.currentMonth = month;
  727. inst.selectedYear = inst.currentYear = year;
  728. if (inst.stayOpen) {
  729. inst.endDay = inst.endMonth = inst.endYear = null;
  730. }
  731. this._selectDate(id, this._formatDate(inst,
  732. inst.currentDay, inst.currentMonth, inst.currentYear));
  733. if (inst.stayOpen) {
  734. inst.rangeStart = this._daylightSavingAdjust(
  735. new Date(inst.currentYear, inst.currentMonth, inst.currentDay));
  736. this._updateDatepicker(inst);
  737. }
  738. },
  739. /* Erase the input field and hide the date picker. */
  740. _clearDate: function(id) {
  741. var target = $(id);
  742. var inst = this._getInst(target[0]);
  743. inst.stayOpen = false;
  744. inst.endDay = inst.endMonth = inst.endYear = inst.rangeStart = null;
  745. this._selectDate(target, '');
  746. },
  747. /* Update the input field with the selected date. */
  748. _selectDate: function(id, dateStr) {
  749. var target = $(id);
  750. var inst = this._getInst(target[0]);
  751. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  752. if (inst.input)
  753. inst.input.val(dateStr);
  754. this._updateAlternate(inst);
  755. var onSelect = this._get(inst, 'onSelect');
  756. if (onSelect)
  757. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  758. else if (inst.input)
  759. inst.input.trigger('change'); // fire the change event
  760. if (inst.inline)
  761. this._updateDatepicker(inst);
  762. else if (!inst.stayOpen) {
  763. this._hideDatepicker(null, this._get(inst, 'duration'));
  764. this._lastInput = inst.input[0];
  765. if (typeof(inst.input[0]) != 'object')
  766. inst.input[0].focus(); // restore focus
  767. this._lastInput = null;
  768. }
  769. },
  770. /* Update any alternate field to synchronise with the main field. */
  771. _updateAlternate: function(inst) {
  772. var altField = this._get(inst, 'altField');
  773. if (altField) { // update alternate field too
  774. var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
  775. var date = this._getDate(inst);
  776. dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  777. $(altField).each(function() { $(this).val(dateStr); });
  778. }
  779. },
  780. /* Set as beforeShowDay function to prevent selection of weekends.
  781. @param date Date - the date to customise
  782. @return [boolean, string] - is this date selectable?, what is its CSS class? */
  783. noWeekends: function(date) {
  784. var day = date.getDay();
  785. return [(day > 0 && day < 6), ''];
  786. },
  787. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  788. @param date Date - the date to get the week for
  789. @return number - the number of the week within the year that contains this date */
  790. iso8601Week: function(date) {
  791. var checkDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
  792. var firstMon = new Date(checkDate.getFullYear(), 1 - 1, 4); // First week always contains 4 Jan
  793. var firstDay = firstMon.getDay() || 7; // Day of week: Mon = 1, ..., Sun = 7
  794. firstMon.setDate(firstMon.getDate() + 1 - firstDay); // Preceding Monday
  795. if (firstDay < 4 && checkDate < firstMon) { // Adjust first three days in year if necessary
  796. checkDate.setDate(checkDate.getDate() - 3); // Generate for previous year
  797. return $.datepicker.iso8601Week(checkDate);
  798. } else if (checkDate > new Date(checkDate.getFullYear(), 12 - 1, 28)) { // Check last three days in year
  799. firstDay = new Date(checkDate.getFullYear() + 1, 1 - 1, 4).getDay() || 7;
  800. if (firstDay > 4 && (checkDate.getDay() || 7) < firstDay - 3) { // Adjust if necessary
  801. return 1;
  802. }
  803. }
  804. return Math.floor(((checkDate - firstMon) / 86400000) / 7) + 1; // Weeks to given date
  805. },
  806. /* Parse a string value into a date object.
  807. See formatDate below for the possible formats.
  808. @param format string - the expected format of the date
  809. @param value string - the date in the above format
  810. @param settings Object - attributes include:
  811. shortYearCutoff number - the cutoff year for determining the century (optional)
  812. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  813. dayNames string[7] - names of the days from Sunday (optional)
  814. monthNamesShort string[12] - abbreviated names of the months (optional)
  815. monthNames string[12] - names of the months (optional)
  816. @return Date - the extracted date value or null if value is blank */
  817. parseDate: function (format, value, settings) {
  818. if (format == null || value == null)
  819. throw 'Invalid arguments';
  820. value = (typeof value == 'object' ? value.toString() : value + '');
  821. if (value == '')
  822. return null;
  823. var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
  824. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  825. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  826. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  827. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  828. var year = -1;
  829. var month = -1;
  830. var day = -1;
  831. var doy = -1;
  832. var literal = false;
  833. // Check whether a format character is doubled
  834. var lookAhead = function(match) {
  835. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  836. if (matches)
  837. iFormat++;
  838. return matches;
  839. };
  840. // Extract a number from the string value
  841. var getNumber = function(match) {
  842. lookAhead(match);
  843. var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2)));
  844. var size = origSize;
  845. var num = 0;
  846. while (size > 0 && iValue < value.length &&
  847. value.charAt(iValue) >= '0' && value.charAt(iValue) <= '9') {
  848. num = num * 10 + parseInt(value.charAt(iValue++),10);
  849. size--;
  850. }
  851. if (size == origSize)
  852. throw 'Missing number at position ' + iValue;
  853. return num;
  854. };
  855. // Extract a name from the string value and convert to an index
  856. var getName = function(match, shortNames, longNames) {
  857. var names = (lookAhead(match) ? longNames : shortNames);
  858. var size = 0;
  859. for (var j = 0; j < names.length; j++)
  860. size = Math.max(size, names[j].length);
  861. var name = '';
  862. var iInit = iValue;
  863. while (size > 0 && iValue < value.length) {
  864. name += value.charAt(iValue++);
  865. for (var i = 0; i < names.length; i++)
  866. if (name == names[i])
  867. return i + 1;
  868. size--;
  869. }
  870. throw 'Unknown name at position ' + iInit;
  871. };
  872. // Confirm that a literal character matches the string value
  873. var checkLiteral = function() {
  874. if (value.charAt(iValue) != format.charAt(iFormat))
  875. throw 'Unexpected literal at position ' + iValue;
  876. iValue++;
  877. };
  878. var iValue = 0;
  879. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  880. if (literal)
  881. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  882. literal = false;
  883. else
  884. checkLiteral();
  885. else
  886. switch (format.charAt(iFormat)) {
  887. case 'd':
  888. day = getNumber('d');
  889. break;
  890. case 'D':
  891. getName('D', dayNamesShort, dayNames);
  892. break;
  893. case 'o':
  894. doy = getNumber('o');
  895. break;
  896. case 'm':
  897. month = getNumber('m');
  898. break;
  899. case 'M':
  900. month = getName('M', monthNamesShort, monthNames);
  901. break;
  902. case 'y':
  903. year = getNumber('y');
  904. break;
  905. case '@':
  906. var date = new Date(getNumber('@'));
  907. year = date.getFullYear();
  908. month = date.getMonth() + 1;
  909. day = date.getDate();
  910. break;
  911. case "'":
  912. if (lookAhead("'"))
  913. checkLiteral();
  914. else
  915. literal = true;
  916. break;
  917. default:
  918. checkLiteral();
  919. }
  920. }
  921. if (year == -1)
  922. year = new Date().getFullYear();
  923. else if (year < 100)
  924. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  925. (year <= shortYearCutoff ? 0 : -100);
  926. if (doy > -1) {
  927. month = 1;
  928. day = doy;
  929. do {
  930. var dim = this._getDaysInMonth(year, month - 1);
  931. if (day <= dim)
  932. break;
  933. month++;
  934. day -= dim;
  935. } while (true);
  936. }
  937. var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  938. if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
  939. throw 'Invalid date'; // E.g. 31/02/*
  940. return date;
  941. },
  942. /* Standard date formats. */
  943. ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
  944. COOKIE: 'D, dd M yy',
  945. ISO_8601: 'yy-mm-dd',
  946. RFC_822: 'D, d M y',
  947. RFC_850: 'DD, dd-M-y',
  948. RFC_1036: 'D, d M y',
  949. RFC_1123: 'D, d M yy',
  950. RFC_2822: 'D, d M yy',
  951. RSS: 'D, d M y', // RFC 822
  952. TIMESTAMP: '@',
  953. W3C: 'yy-mm-dd', // ISO 8601
  954. /* Format a date object into a string value.
  955. The format can be combinations of the following:
  956. d - day of month (no leading zero)
  957. dd - day of month (two digit)
  958. o - day of year (no leading zeros)
  959. oo - day of year (three digit)
  960. D - day name short
  961. DD - day name long
  962. m - month of year (no leading zero)
  963. mm - month of year (two digit)
  964. M - month name short
  965. MM - month name long
  966. y - year (two digit)
  967. yy - year (four digit)
  968. @ - Unix timestamp (ms since 01/01/1970)
  969. '...' - literal text
  970. '' - single quote
  971. @param format string - the desired format of the date
  972. @param date Date - the date value to format
  973. @param settings Object - attributes include:
  974. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  975. dayNames string[7] - names of the days from Sunday (optional)
  976. monthNamesShort string[12] - abbreviated names of the months (optional)
  977. monthNames string[12] - names of the months (optional)
  978. @return string - the date in the above format */
  979. formatDate: function (format, date, settings) {
  980. if (!date)
  981. return '';
  982. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  983. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  984. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  985. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  986. // Check whether a format character is doubled
  987. var lookAhead = function(match) {
  988. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  989. if (matches)
  990. iFormat++;
  991. return matches;
  992. };
  993. // Format a number, with leading zero if necessary
  994. var formatNumber = function(match, value, len) {
  995. var num = '' + value;
  996. if (lookAhead(match))
  997. while (num.length < len)
  998. num = '0' + num;
  999. return num;
  1000. };
  1001. // Format a name, short or long as requested
  1002. var formatName = function(match, value, shortNames, longNames) {
  1003. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  1004. };
  1005. var output = '';
  1006. var literal = false;
  1007. if (date)
  1008. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  1009. if (literal)
  1010. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  1011. literal = false;
  1012. else
  1013. output += format.charAt(iFormat);
  1014. else
  1015. switch (format.charAt(iFormat)) {
  1016. case 'd':
  1017. output += formatNumber('d', date.getDate(), 2);
  1018. break;
  1019. case 'D':
  1020. output += formatName('D', date.getDay(), dayNamesShort, dayNames);
  1021. break;
  1022. case 'o':
  1023. var doy = date.getDate();
  1024. for (var m = date.getMonth() - 1; m >= 0; m--)
  1025. doy += this._getDaysInMonth(date.getFullYear(), m);
  1026. output += formatNumber('o', doy, 3);
  1027. break;
  1028. case 'm':
  1029. output += formatNumber('m', date.getMonth() + 1, 2);
  1030. break;
  1031. case 'M':
  1032. output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
  1033. break;
  1034. case 'y':
  1035. output += (lookAhead('y') ? date.getFullYear() :
  1036. (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
  1037. break;
  1038. case '@':
  1039. output += date.getTime();
  1040. break;
  1041. case "'":
  1042. if (lookAhead("'"))
  1043. output += "'";
  1044. else
  1045. literal = true;
  1046. break;
  1047. default:
  1048. output += format.charAt(iFormat);
  1049. }
  1050. }
  1051. return output;
  1052. },
  1053. /* Extract all possible characters from the date format. */
  1054. _possibleChars: function (format) {
  1055. var chars = '';
  1056. var literal = false;
  1057. for (var iFormat = 0; iFormat < format.length; iFormat++)
  1058. if (literal)
  1059. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  1060. literal = false;
  1061. else
  1062. chars += format.charAt(iFormat);
  1063. else
  1064. switch (format.charAt(iFormat)) {
  1065. case 'd': case 'm': case 'y': case '@':
  1066. chars += '0123456789';
  1067. break;
  1068. case 'D': case 'M':
  1069. return null; // Accept anything
  1070. case "'":
  1071. if (lookAhead("'"))
  1072. chars += "'";
  1073. else
  1074. literal = true;
  1075. break;
  1076. default:
  1077. chars += format.charAt(iFormat);
  1078. }
  1079. return chars;
  1080. },
  1081. /* Get a setting value, defaulting if necessary. */
  1082. _get: function(inst, name) {
  1083. return inst.settings[name] !== undefined ?
  1084. inst.settings[name] : this._defaults[name];
  1085. },
  1086. /* Parse existing date and initialise date picker. */
  1087. _setDateFromField: function(inst) {
  1088. var dateFormat = this._get(inst, 'dateFormat');
  1089. var dates = inst.input ? inst.input.val() : null;
  1090. inst.endDay = inst.endMonth = inst.endYear = null;
  1091. var date = defaultDate = this._getDefaultDate(inst);
  1092. var settings = this._getFormatConfig(inst);
  1093. try {
  1094. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  1095. } catch (event) {
  1096. this.log(event);
  1097. date = defaultDate;
  1098. }
  1099. inst.selectedDay = date.getDate();
  1100. inst.drawMonth = inst.selectedMonth = date.getMonth();
  1101. inst.drawYear = inst.selectedYear = date.getFullYear();
  1102. inst.currentDay = (dates ? date.getDate() : 0);
  1103. inst.currentMonth = (dates ? date.getMonth() : 0);
  1104. inst.currentYear = (dates ? date.getFullYear() : 0);
  1105. this._adjustInstDate(inst);
  1106. },
  1107. /* Retrieve the default date shown on opening. */
  1108. _getDefaultDate: function(inst) {
  1109. var date = this._determineDate(this._get(inst, 'defaultDate'), new Date());
  1110. var minDate = this._getMinMaxDate(inst, 'min', true);
  1111. var maxDate = this._getMinMaxDate(inst, 'max');
  1112. date = (minDate && date < minDate ? minDate : date);
  1113. date = (maxDate && date > maxDate ? maxDate : date);
  1114. return date;
  1115. },
  1116. /* A date may be specified as an exact value or a relative one. */
  1117. _determineDate: function(date, defaultDate) {
  1118. var offsetNumeric = function(offset) {
  1119. var date = new Date();
  1120. date.setDate(date.getDate() + offset);
  1121. return date;
  1122. };
  1123. var offsetString = function(offset, getDaysInMonth) {
  1124. var date = new Date();
  1125. var year = date.getFullYear();
  1126. var month = date.getMonth();
  1127. var day = date.getDate();
  1128. var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
  1129. var matches = pattern.exec(offset);
  1130. while (matches) {
  1131. switch (matches[2] || 'd') {
  1132. case 'd' : case 'D' :
  1133. day += parseInt(matches[1],10); break;
  1134. case 'w' : case 'W' :
  1135. day += parseInt(matches[1],10) * 7; break;
  1136. case 'm' : case 'M' :
  1137. month += parseInt(matches[1],10);
  1138. day = Math.min(day, getDaysInMonth(year, month));
  1139. break;
  1140. case 'y': case 'Y' :
  1141. year += parseInt(matches[1],10);
  1142. day = Math.min(day, getDaysInMonth(year, month));
  1143. break;
  1144. }
  1145. matches = pattern.exec(offset);
  1146. }
  1147. return new Date(year, month, day);
  1148. };
  1149. date = (date == null ? defaultDate :
  1150. (typeof date == 'string' ? offsetString(date, this._getDaysInMonth) :
  1151. (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : date)));
  1152. date = (date && date.toString() == 'Invalid Date' ? defaultDate : date);
  1153. if (date) {
  1154. date.setHours(0);
  1155. date.setMinutes(0);
  1156. date.setSeconds(0);
  1157. date.setMilliseconds(0);
  1158. }
  1159. return this._daylightSavingAdjust(date);
  1160. },
  1161. /* Handle switch to/from daylight saving.
  1162. Hours may be non-zero on daylight saving cut-over:
  1163. > 12 when midnight changeover, but then cannot generate
  1164. midnight datetime, so jump to 1AM, otherwise reset.
  1165. @param date (Date) the date to check
  1166. @return (Date) the corrected date */
  1167. _daylightSavingAdjust: function(date) {
  1168. if (!date) return null;
  1169. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  1170. return date;
  1171. },
  1172. /* Set the date(s) directly. */
  1173. _setDate: function(inst, date, endDate) {
  1174. var clear = !(date);
  1175. var origMonth = inst.selectedMonth;
  1176. var origYear = inst.selectedYear;
  1177. date = this._determineDate(date, new Date());
  1178. inst.selectedDay = inst.currentDay = date.getDate();
  1179. inst.drawMonth = inst.selectedMonth = inst.currentMonth = date.getMonth();
  1180. inst.drawYear = inst.selectedYear = inst.currentYear = date.getFullYear();
  1181. if (origMonth != inst.selectedMonth || origYear != inst.selectedYear)
  1182. this._notifyChange(inst);
  1183. this._adjustInstDate(inst);
  1184. if (inst.input) {
  1185. inst.input.val(clear ? '' : this._formatDate(inst));
  1186. }
  1187. },
  1188. /* Retrieve the date(s) directly. */
  1189. _getDate: function(inst) {
  1190. var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
  1191. this._daylightSavingAdjust(new Date(
  1192. inst.currentYear, inst.currentMonth, inst.currentDay)));
  1193. return startDate;
  1194. },
  1195. /* Generate the HTML for the current state of the date picker. */
  1196. _generateHTML: function(inst) {
  1197. var today = new Date();
  1198. today = this._daylightSavingAdjust(
  1199. new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
  1200. var isRTL = this._get(inst, 'isRTL');
  1201. var showButtonPanel = this._get(inst, 'showButtonPanel');
  1202. var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
  1203. var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
  1204. var numMonths = this._getNumberOfMonths(inst);
  1205. var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
  1206. var stepMonths = this._get(inst, 'stepMonths');
  1207. var stepBigMonths = this._get(inst, 'stepBigMonths');
  1208. var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
  1209. var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  1210. new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  1211. var minDate = this._getMinMaxDate(inst, 'min', true);
  1212. var maxDate = this._getMinMaxDate(inst, 'max');
  1213. var drawMonth = inst.drawMonth - showCurrentAtPos;
  1214. var drawYear = inst.drawYear;
  1215. if (drawMonth < 0) {
  1216. drawMonth += 12;
  1217. drawYear--;
  1218. }
  1219. if (maxDate) {
  1220. var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  1221. maxDate.getMonth() - numMonths[1] + 1, maxDate.getDate()));
  1222. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  1223. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  1224. drawMonth--;
  1225. if (drawMonth < 0) {
  1226. drawMonth = 11;
  1227. drawYear--;
  1228. }
  1229. }
  1230. }
  1231. inst.drawMonth = drawMonth;
  1232. inst.drawYear = drawYear;
  1233. var prevText = this._get(inst, 'prevText');
  1234. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  1235. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  1236. this._getFormatConfig(inst)));
  1237. var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  1238. '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' +
  1239. ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
  1240. (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-prev ui-corner-all ui-state-disabled" title="'+ prevText +'"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>'));
  1241. var nextText = this._get(inst, 'nextText');
  1242. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  1243. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  1244. this._getFormatConfig(inst)));
  1245. var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  1246. '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' +
  1247. ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
  1248. (hideIfNoPrevNext ? '' : '<a class="ui-datepicker-next ui-corner-all ui-state-disabled" title="'+ nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>'));
  1249. var currentText = this._get(inst, 'currentText');
  1250. var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
  1251. currentText = (!navigationAsDateFormat ? currentText :
  1252. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  1253. var controls = (!inst.inline ? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery.datepicker._hideDatepicker();">' + this._get(inst, 'closeText') + '</button>' : '');
  1254. var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
  1255. (this._isInRange(inst, gotoDate) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' +
  1256. '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
  1257. var firstDay = parseInt(this._get(inst, 'firstDay'),10);
  1258. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  1259. var dayNames = this._get(inst, 'dayNames');
  1260. var dayNamesShort = this._get(inst, 'dayNamesShort');
  1261. var dayNamesMin = this._get(inst, 'dayNamesMin');
  1262. var monthNames = this._get(inst, 'monthNames');
  1263. var monthNamesShort = this._get(inst, 'monthNamesShort');
  1264. var beforeShowDay = this._get(inst, 'beforeShowDay');
  1265. var showOtherMonths = this._get(inst, 'showOtherMonths');
  1266. var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
  1267. var endDate = inst.endDay ? this._daylightSavingAdjust(
  1268. new Date(inst.endYear, inst.endMonth, inst.endDay)) : currentDate;
  1269. var defaultDate = this._getDefaultDate(inst);
  1270. var html = '';
  1271. for (var row = 0; row < numMonths[0]; row++) {
  1272. var group = '';
  1273. for (var col = 0; col < numMonths[1]; col++) {
  1274. var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  1275. var cornerClass = ' ui-corner-all';
  1276. var calender = '';
  1277. if (isMultiMonth) {
  1278. calender += '<div class="ui-datepicker-group ui-datepicker-group-';
  1279. switch (col) {
  1280. case 0: calender += 'first'; cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
  1281. case numMonths[1]-1: calender += 'last'; cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
  1282. default: calender += 'middle'; cornerClass = ''; break;
  1283. }
  1284. calender += '">';
  1285. }
  1286. calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
  1287. (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
  1288. (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
  1289. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  1290. selectedDate, row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  1291. '</div><table class="ui-datepicker-calendar"><thead>' +
  1292. '<tr>';
  1293. var thead = '';
  1294. for (var dow = 0; dow < 7; dow++) { // days of the week
  1295. var day = (dow + firstDay) % 7;
  1296. thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
  1297. '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
  1298. }
  1299. calender += thead + '</tr></thead><tbody>';
  1300. var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  1301. if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
  1302. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  1303. var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  1304. var numRows = (isMultiMonth ? 6 : Math.ceil((leadDays + daysInMonth) / 7)); // calculate the number of rows to generate
  1305. var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  1306. for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  1307. calender += '<tr>';
  1308. var tbody = '';
  1309. for (var dow = 0; dow < 7; dow++) { // create date picker days
  1310. var daySettings = (beforeShowDay ?
  1311. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
  1312. var otherMonth = (printDate.getMonth() != drawMonth);
  1313. var unselectable = otherMonth || !daySettings[0] ||
  1314. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  1315. tbody += '<td class="' +
  1316. ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
  1317. (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
  1318. ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
  1319. (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
  1320. // or defaultDate is current printedDate and defaultDate is selectedDate
  1321. ' ' + this._dayOverClass : '') + // highlight selected day
  1322. (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
  1323. (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
  1324. (printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range
  1325. ' ' + this._currentClass : '') + // highlight selected day
  1326. (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
  1327. ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
  1328. (unselectable ? '' : ' onclick="DP_jQuery.datepicker._selectDay(\'#' +
  1329. inst.id + '\',' + drawMonth + ',' + drawYear + ', this);return false;"') + '>' + // actions
  1330. (otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months
  1331. (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
  1332. (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
  1333. (printDate.getTime() >= currentDate.getTime() && printDate.getTime() <= endDate.getTime() ? // in current range
  1334. ' ui-state-active' : '') + // highlight selected day
  1335. '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display for this month
  1336. printDate.setDate(printDate.getDate() + 1);
  1337. printDate = this._daylightSavingAdjust(printDate);
  1338. }
  1339. calender += tbody + '</tr>';
  1340. }
  1341. drawMonth++;
  1342. if (drawMonth > 11) {
  1343. drawMonth = 0;
  1344. drawYear++;
  1345. }
  1346. calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
  1347. ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
  1348. group += calender;
  1349. }
  1350. html += group;
  1351. }
  1352. html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
  1353. '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
  1354. inst._keyEvent = false;
  1355. return html;
  1356. },
  1357. /* Generate the month and year header. */
  1358. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  1359. selectedDate, secondary, monthNames, monthNamesShort) {
  1360. minDate = (inst.rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate);
  1361. var changeMonth = this._get(inst, 'changeMonth');
  1362. var changeYear = this._get(inst, 'changeYear');
  1363. var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
  1364. var html = '<div class="ui-datepicker-title">';
  1365. var monthHtml = '';
  1366. // month selection
  1367. if (secondary || !changeMonth)
  1368. monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span> ';
  1369. else {
  1370. var inMinYear = (minDate && minDate.getFullYear() == drawYear);
  1371. var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
  1372. monthHtml += '<select class="ui-datepicker-month" ' +
  1373. 'onchange="DP_jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +
  1374. 'onclick="DP_jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
  1375. '>';
  1376. for (var month = 0; month < 12; month++) {
  1377. if ((!inMinYear || month >= minDate.getMonth()) &&
  1378. (!inMaxYear || month <= maxDate.getMonth()))
  1379. monthHtml += '<option value="' + month + '"' +
  1380. (month == drawMonth ? ' selected="selected"' : '') +
  1381. '>' + monthNamesShort[month] + '</option>';
  1382. }
  1383. monthHtml += '</select>';
  1384. }
  1385. if (!showMonthAfterYear)
  1386. html += monthHtml + ((secondary || changeMonth || changeYear) && (!(changeMonth && changeYear)) ? '&#xa0;' : '');
  1387. // year selection
  1388. if (secondary || !changeYear)
  1389. html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
  1390. else {
  1391. // determine range of years to display
  1392. var years = this._get(inst, 'yearRange').split(':');
  1393. var year = 0;
  1394. var endYear = 0;
  1395. if (years.length != 2) {
  1396. year = drawYear - 10;
  1397. endYear = drawYear + 10;
  1398. } else if (years[0].charAt(0) == '+' || years[0].charAt(0) == '-') {
  1399. year = drawYear + parseInt(years[0], 10);
  1400. endYear = drawYear + parseInt(years[1], 10);
  1401. } else {
  1402. year = parseInt(years[0], 10);
  1403. endYear = parseInt(years[1], 10);
  1404. }
  1405. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  1406. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  1407. html += '<select class="ui-datepicker-year" ' +
  1408. 'onchange="DP_jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +
  1409. 'onclick="DP_jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' +
  1410. '>';
  1411. for (; year <= endYear; year++) {
  1412. html += '<option value="' + year + '"' +
  1413. (year == drawYear ? ' selected="selected"' : '') +
  1414. '>' + year + '</option>';
  1415. }
  1416. html += '</select>';
  1417. }
  1418. if (showMonthAfterYear)
  1419. html += (secondary || changeMonth || changeYear ? '&#xa0;' : '') + monthHtml;
  1420. html += '</div>'; // Close datepicker_header
  1421. return html;
  1422. },
  1423. /* Adjust one of the date sub-fields. */
  1424. _adjustInstDate: function(inst, offset, period) {
  1425. var year = inst.drawYear + (period == 'Y' ? offset : 0);
  1426. var month = inst.drawMonth + (period == 'M' ? offset : 0);
  1427. var day = Math.min(inst.selectedDay, this._getDaysInMonth(ye