Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

1728 wiersze
71 KiB

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