2 * jQuery UI Datepicker 1.8.7
4 * Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
5 * Dual licensed under the MIT or GPL Version 2 licenses.
6 * http://jquery.org/license
8 * http://docs.jquery.com/UI/Datepicker
13 (function( $, undefined ) {
15 $.extend($.ui
, { datepicker
: { version
: "1.8.7" } });
17 var PROP_NAME
= 'datepicker';
18 var dpuuid
= new Date().getTime();
20 /* Date picker manager.
21 Use the singleton instance of this class, $.datepicker, to interact with the date picker.
22 Settings for (groups of) date pickers are maintained in an instance object,
23 allowing multiple different settings on the same page. */
25 function Datepicker() {
26 this.debug
= false; // Change this to true to start debugging
27 this._curInst
= null; // The current instance in use
28 this._keyEvent
= false; // If the last event was a key event
29 this._disabledInputs
= []; // List of date picker inputs that have been disabled
30 this._datepickerShowing
= false; // True if the popup picker is showing , false if not
31 this._inDialog
= false; // True if showing within a "dialog", false if not
32 this._mainDivId
= 'ui-datepicker-div'; // The ID of the main datepicker division
33 this._inlineClass
= 'ui-datepicker-inline'; // The name of the inline marker class
34 this._appendClass
= 'ui-datepicker-append'; // The name of the append marker class
35 this._triggerClass
= 'ui-datepicker-trigger'; // The name of the trigger marker class
36 this._dialogClass
= 'ui-datepicker-dialog'; // The name of the dialog marker class
37 this._disableClass
= 'ui-datepicker-disabled'; // The name of the disabled covering marker class
38 this._unselectableClass
= 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
39 this._currentClass
= 'ui-datepicker-current-day'; // The name of the current day marker class
40 this._dayOverClass
= 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
41 this.regional
= []; // Available regional settings, indexed by language code
42 this.regional
[''] = { // Default regional settings
43 closeText
: 'Done', // Display text for close link
44 prevText
: 'Prev', // Display text for previous month link
45 nextText
: 'Next', // Display text for next month link
46 currentText
: 'Today', // Display text for current month link
47 monthNames
: ['January','February','March','April','May','June',
48 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
49 monthNamesShort
: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
50 dayNames
: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
51 dayNamesShort
: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
52 dayNamesMin
: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
53 weekHeader
: 'Wk', // Column header for week of the year
54 dateFormat
: 'mm/dd/yy', // See format options on parseDate
55 firstDay
: 0, // The first day of the week, Sun = 0, Mon = 1, ...
56 isRTL
: false, // True if right-to-left language, false if left-to-right
57 showMonthAfterYear
: false, // True if the year select precedes month, false for month then year
58 yearSuffix
: '' // Additional text to append to the year in the month headers
60 this._defaults
= { // Global defaults for all the date picker instances
61 showOn
: 'focus', // 'focus' for popup on focus,
62 // 'button' for trigger button, or 'both' for either
63 showAnim
: 'fadeIn', // Name of jQuery animation for popup
64 showOptions
: {}, // Options for enhanced animations
65 defaultDate
: null, // Used when field is blank: actual date,
66 // +/-number for offset from today, null for today
67 appendText
: '', // Display text following the input box, e.g. showing the format
68 buttonText
: '...', // Text for trigger button
69 buttonImage
: '', // URL for trigger button image
70 buttonImageOnly
: false, // True if the image appears alone, false if it appears on a button
71 hideIfNoPrevNext
: false, // True to hide next/previous month links
72 // if not applicable, false to just disable them
73 navigationAsDateFormat
: false, // True if date formatting applied to prev/today/next links
74 gotoCurrent
: false, // True if today link goes back to current selection instead
75 changeMonth
: false, // True if month can be selected directly, false if only prev/next
76 changeYear
: false, // True if year can be selected directly, false if only prev/next
77 yearRange
: 'c-10:c+10', // Range of years to display in drop-down,
78 // either relative to today's year (-nn:+nn), relative to currently displayed year
79 // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
80 showOtherMonths
: false, // True to show dates in other months, false to leave blank
81 selectOtherMonths
: false, // True to allow selection of dates in other months, false for unselectable
82 showWeek
: false, // True to show week of the year, false to not show it
83 calculateWeek
: this.iso8601Week
, // How to calculate the week of the year,
84 // takes a Date and returns the number of the week for it
85 shortYearCutoff
: '+10', // Short year values < this are in the current century,
86 // > this are in the previous century,
87 // string value starting with '+' for current year + value
88 minDate
: null, // The earliest selectable date, or null for no limit
89 maxDate
: null, // The latest selectable date, or null for no limit
90 duration
: 'fast', // Duration of display/closure
91 beforeShowDay
: null, // Function that takes a date and returns an array with
92 // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
93 // [2] = cell title (optional), e.g. $.datepicker.noWeekends
94 beforeShow
: null, // Function that takes an input field and
95 // returns a set of custom settings for the date picker
96 onSelect
: null, // Define a callback function when a date is selected
97 onChangeMonthYear
: null, // Define a callback function when the month or year is changed
98 onClose
: null, // Define a callback function when the datepicker is closed
99 numberOfMonths
: 1, // Number of months to show at a time
100 showCurrentAtPos
: 0, // The position in multipe months at which to show the current month (starting at 0)
101 stepMonths
: 1, // Number of months to step back/forward
102 stepBigMonths
: 12, // Number of months to step back/forward for the big links
103 altField
: '', // Selector for an alternate field to store selected dates into
104 altFormat
: '', // The date format to use for the alternate field
105 constrainInput
: true, // The input is constrained by the current date format
106 showButtonPanel
: false, // True to show button panel, false to not show it
107 autoSize
: false // True to size the input for the date format, false to leave as is
109 $.extend(this._defaults
, this.regional
['']);
110 this.dpDiv
= $('<div id="' + this._mainDivId
+ '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>');
113 $.extend(Datepicker
.prototype, {
114 /* Class name added to elements to indicate already configured with a date picker. */
115 markerClassName
: 'hasDatepicker',
117 /* Debug logging (if enabled). */
120 console
.log
.apply('', arguments
);
123 // TODO rename to "widget" when switching to widget factory
124 _widgetDatepicker: function() {
128 /* Override the default settings for all instances of the date picker.
129 @param settings object - the new settings to use as defaults (anonymous object)
130 @return the manager object */
131 setDefaults: function(settings
) {
132 extendRemove(this._defaults
, settings
|| {});
136 /* Attach the date picker to a jQuery selection.
137 @param target element - the target input field or division or span
138 @param settings object - the new settings to use for this date picker instance (anonymous) */
139 _attachDatepicker: function(target
, settings
) {
140 // check for settings on the control itself - in namespace 'date:'
141 var inlineSettings
= null;
142 for (var attrName
in this._defaults
) {
143 var attrValue
= target
.getAttribute('date:' + attrName
);
145 inlineSettings
= inlineSettings
|| {};
147 inlineSettings
[attrName
] = eval(attrValue
);
149 inlineSettings
[attrName
] = attrValue
;
153 var nodeName
= target
.nodeName
.toLowerCase();
154 var inline
= (nodeName
== 'div' || nodeName
== 'span');
157 target
.id
= 'dp' + this.uuid
;
159 var inst
= this._newInst($(target
), inline
);
160 inst
.settings
= $.extend({}, settings
|| {}, inlineSettings
|| {});
161 if (nodeName
== 'input') {
162 this._connectDatepicker(target
, inst
);
164 this._inlineDatepicker(target
, inst
);
168 /* Create a new instance object. */
169 _newInst: function(target
, inline
) {
170 var id
= target
[0].id
.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
171 return {id
: id
, input
: target
, // associated target
172 selectedDay
: 0, selectedMonth
: 0, selectedYear
: 0, // current selection
173 drawMonth
: 0, drawYear
: 0, // month being drawn
174 inline
: inline
, // is datepicker inline or not
175 dpDiv
: (!inline
? this.dpDiv
: // presentation div
176 $('<div class="' + this._inlineClass
+ ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'))};
179 /* Attach the date picker to an input field. */
180 _connectDatepicker: function(target
, inst
) {
181 var input
= $(target
);
183 inst
.trigger
= $([]);
184 if (input
.hasClass(this.markerClassName
))
186 this._attachments(input
, inst
);
187 input
.addClass(this.markerClassName
).keydown(this._doKeyDown
).
188 keypress(this._doKeyPress
).keyup(this._doKeyUp
).
189 bind("setData.datepicker", function(event
, key
, value
) {
190 inst
.settings
[key
] = value
;
191 }).bind("getData.datepicker", function(event
, key
) {
192 return this._get(inst
, key
);
194 this._autoSize(inst
);
195 $.data(target
, PROP_NAME
, inst
);
198 /* Make attachments based on settings. */
199 _attachments: function(input
, inst
) {
200 var appendText
= this._get(inst
, 'appendText');
201 var isRTL
= this._get(inst
, 'isRTL');
203 inst
.append
.remove();
205 inst
.append
= $('<span class="' + this._appendClass
+ '">' + appendText
+ '</span>');
206 input
[isRTL
? 'before' : 'after'](inst
.append
);
208 input
.unbind('focus', this._showDatepicker
);
210 inst
.trigger
.remove();
211 var showOn
= this._get(inst
, 'showOn');
212 if (showOn
== 'focus' || showOn
== 'both') // pop-up date picker when in the marked field
213 input
.focus(this._showDatepicker
);
214 if (showOn
== 'button' || showOn
== 'both') { // pop-up date picker when button clicked
215 var buttonText
= this._get(inst
, 'buttonText');
216 var buttonImage
= this._get(inst
, 'buttonImage');
217 inst
.trigger
= $(this._get(inst
, 'buttonImageOnly') ?
218 $('<img/>').addClass(this._triggerClass
).
219 attr({ src
: buttonImage
, alt
: buttonText
, title
: buttonText
}) :
220 $('<button type="button"></button>').addClass(this._triggerClass
).
221 html(buttonImage
== '' ? buttonText
: $('<img/>').attr(
222 { src
:buttonImage
, alt
:buttonText
, title
:buttonText
})));
223 input
[isRTL
? 'before' : 'after'](inst
.trigger
);
224 inst
.trigger
.click(function() {
225 if ($.datepicker
._datepickerShowing
&& $.datepicker
._lastInput
== input
[0])
226 $.datepicker
._hideDatepicker();
228 $.datepicker
._showDatepicker(input
[0]);
234 /* Apply the maximum length for the date format. */
235 _autoSize: function(inst
) {
236 if (this._get(inst
, 'autoSize') && !inst
.inline
) {
237 var date
= new Date(2009, 12 - 1, 20); // Ensure double digits
238 var dateFormat
= this._get(inst
, 'dateFormat');
239 if (dateFormat
.match(/[DM]/)) {
240 var findMax = function(names
) {
243 for (var i
= 0; i
< names
.length
; i
++) {
244 if (names
[i
].length
> max
) {
245 max
= names
[i
].length
;
251 date
.setMonth(findMax(this._get(inst
, (dateFormat
.match(/MM/) ?
252 'monthNames' : 'monthNamesShort'))));
253 date
.setDate(findMax(this._get(inst
, (dateFormat
.match(/DD/) ?
254 'dayNames' : 'dayNamesShort'))) + 20 - date
.getDay());
256 inst
.input
.attr('size', this._formatDate(inst
, date
).length
);
260 /* Attach an inline date picker to a div. */
261 _inlineDatepicker: function(target
, inst
) {
262 var divSpan
= $(target
);
263 if (divSpan
.hasClass(this.markerClassName
))
265 divSpan
.addClass(this.markerClassName
).append(inst
.dpDiv
).
266 bind("setData.datepicker", function(event
, key
, value
){
267 inst
.settings
[key
] = value
;
268 }).bind("getData.datepicker", function(event
, key
){
269 return this._get(inst
, key
);
271 $.data(target
, PROP_NAME
, inst
);
272 this._setDate(inst
, this._getDefaultDate(inst
), true);
273 this._updateDatepicker(inst
);
274 this._updateAlternate(inst
);
278 /* Pop-up the date picker in a "dialog" box.
279 @param input element - ignored
280 @param date string or Date - the initial date to display
281 @param onSelect function - the function to call when a date is selected
282 @param settings object - update the dialog date picker instance's settings (anonymous object)
283 @param pos int[2] - coordinates for the dialog's position within the screen or
284 event - with x/y coordinates or
285 leave empty for default (screen centre)
286 @return the manager object */
287 _dialogDatepicker: function(input
, date
, onSelect
, settings
, pos
) {
288 var inst
= this._dialogInst
; // internal instance
291 var id
= 'dp' + this.uuid
;
292 this._dialogInput
= $('<input type="text" id="' + id
+
293 '" style="position: absolute; top: -100px; width: 0px; z-index: -10;"/>');
294 this._dialogInput
.keydown(this._doKeyDown
);
295 $('body').append(this._dialogInput
);
296 inst
= this._dialogInst
= this._newInst(this._dialogInput
, false);
298 $.data(this._dialogInput
[0], PROP_NAME
, inst
);
300 extendRemove(inst
.settings
, settings
|| {});
301 date
= (date
&& date
.constructor == Date
? this._formatDate(inst
, date
) : date
);
302 this._dialogInput
.val(date
);
304 this._pos
= (pos
? (pos
.length
? pos
: [pos
.pageX
, pos
.pageY
]) : null);
306 var browserWidth
= document
.documentElement
.clientWidth
;
307 var browserHeight
= document
.documentElement
.clientHeight
;
308 var scrollX
= document
.documentElement
.scrollLeft
|| document
.body
.scrollLeft
;
309 var scrollY
= document
.documentElement
.scrollTop
|| document
.body
.scrollTop
;
310 this._pos
= // should use actual width/height below
311 [(browserWidth
/ 2) - 100 + scrollX
, (browserHeight
/ 2) - 150 + scrollY
];
314 // move input on screen for focus, but hidden behind dialog
315 this._dialogInput
.css('left', (this._pos
[0] + 20) + 'px').css('top', this._pos
[1] + 'px');
316 inst
.settings
.onSelect
= onSelect
;
317 this._inDialog
= true;
318 this.dpDiv
.addClass(this._dialogClass
);
319 this._showDatepicker(this._dialogInput
[0]);
321 $.blockUI(this.dpDiv
);
322 $.data(this._dialogInput
[0], PROP_NAME
, inst
);
326 /* Detach a datepicker from its control.
327 @param target element - the target input field or division or span */
328 _destroyDatepicker: function(target
) {
329 var $target
= $(target
);
330 var inst
= $.data(target
, PROP_NAME
);
331 if (!$target
.hasClass(this.markerClassName
)) {
334 var nodeName
= target
.nodeName
.toLowerCase();
335 $.removeData(target
, PROP_NAME
);
336 if (nodeName
== 'input') {
337 inst
.append
.remove();
338 inst
.trigger
.remove();
339 $target
.removeClass(this.markerClassName
).
340 unbind('focus', this._showDatepicker
).
341 unbind('keydown', this._doKeyDown
).
342 unbind('keypress', this._doKeyPress
).
343 unbind('keyup', this._doKeyUp
);
344 } else if (nodeName
== 'div' || nodeName
== 'span')
345 $target
.removeClass(this.markerClassName
).empty();
348 /* Enable the date picker to a jQuery selection.
349 @param target element - the target input field or division or span */
350 _enableDatepicker: function(target
) {
351 var $target
= $(target
);
352 var inst
= $.data(target
, PROP_NAME
);
353 if (!$target
.hasClass(this.markerClassName
)) {
356 var nodeName
= target
.nodeName
.toLowerCase();
357 if (nodeName
== 'input') {
358 target
.disabled
= false;
359 inst
.trigger
.filter('button').
360 each(function() { this.disabled
= false; }).end().
361 filter('img').css({opacity
: '1.0', cursor
: ''});
363 else if (nodeName
== 'div' || nodeName
== 'span') {
364 var inline
= $target
.children('.' + this._inlineClass
);
365 inline
.children().removeClass('ui-state-disabled');
367 this._disabledInputs
= $.map(this._disabledInputs
,
368 function(value
) { return (value
== target
? null : value
); }); // delete entry
371 /* Disable the date picker to a jQuery selection.
372 @param target element - the target input field or division or span */
373 _disableDatepicker: function(target
) {
374 var $target
= $(target
);
375 var inst
= $.data(target
, PROP_NAME
);
376 if (!$target
.hasClass(this.markerClassName
)) {
379 var nodeName
= target
.nodeName
.toLowerCase();
380 if (nodeName
== 'input') {
381 target
.disabled
= true;
382 inst
.trigger
.filter('button').
383 each(function() { this.disabled
= true; }).end().
384 filter('img').css({opacity
: '0.5', cursor
: 'default'});
386 else if (nodeName
== 'div' || nodeName
== 'span') {
387 var inline
= $target
.children('.' + this._inlineClass
);
388 inline
.children().addClass('ui-state-disabled');
390 this._disabledInputs
= $.map(this._disabledInputs
,
391 function(value
) { return (value
== target
? null : value
); }); // delete entry
392 this._disabledInputs
[this._disabledInputs
.length
] = target
;
395 /* Is the first field in a jQuery collection disabled as a datepicker?
396 @param target element - the target input field or division or span
397 @return boolean - true if disabled, false if enabled */
398 _isDisabledDatepicker: function(target
) {
402 for (var i
= 0; i
< this._disabledInputs
.length
; i
++) {
403 if (this._disabledInputs
[i
] == target
)
409 /* Retrieve the instance data for the target control.
410 @param target element - the target input field or division or span
411 @return object - the associated instance data
412 @throws error if a jQuery problem getting data */
413 _getInst: function(target
) {
415 return $.data(target
, PROP_NAME
);
418 throw 'Missing instance data for this datepicker';
422 /* Update or retrieve the settings for a date picker attached to an input field or division.
423 @param target element - the target input field or division or span
424 @param name object - the new settings to update or
425 string - the name of the setting to change or retrieve,
426 when retrieving also 'all' for all instance settings or
427 'defaults' for all global defaults
428 @param value any - the new value for the setting
429 (omit if above is an object or to retrieve a value) */
430 _optionDatepicker: function(target
, name
, value
) {
431 var inst
= this._getInst(target
);
432 if (arguments
.length
== 2 && typeof name
== 'string') {
433 return (name
== 'defaults' ? $.extend({}, $.datepicker
._defaults
) :
434 (inst
? (name
== 'all' ? $.extend({}, inst
.settings
) :
435 this._get(inst
, name
)) : null));
437 var settings
= name
|| {};
438 if (typeof name
== 'string') {
440 settings
[name
] = value
;
443 if (this._curInst
== inst
) {
444 this._hideDatepicker();
446 var date
= this._getDateDatepicker(target
, true);
447 extendRemove(inst
.settings
, settings
);
448 this._attachments($(target
), inst
);
449 this._autoSize(inst
);
450 this._setDateDatepicker(target
, date
);
451 this._updateDatepicker(inst
);
455 // change method deprecated
456 _changeDatepicker: function(target
, name
, value
) {
457 this._optionDatepicker(target
, name
, value
);
460 /* Redraw the date picker attached to an input field or division.
461 @param target element - the target input field or division or span */
462 _refreshDatepicker: function(target
) {
463 var inst
= this._getInst(target
);
465 this._updateDatepicker(inst
);
469 /* Set the dates for a jQuery selection.
470 @param target element - the target input field or division or span
471 @param date Date - the new date */
472 _setDateDatepicker: function(target
, date
) {
473 var inst
= this._getInst(target
);
475 this._setDate(inst
, date
);
476 this._updateDatepicker(inst
);
477 this._updateAlternate(inst
);
481 /* Get the date(s) for the first entry in a jQuery selection.
482 @param target element - the target input field or division or span
483 @param noDefault boolean - true if no default date is to be used
484 @return Date - the current date */
485 _getDateDatepicker: function(target
, noDefault
) {
486 var inst
= this._getInst(target
);
487 if (inst
&& !inst
.inline
)
488 this._setDateFromField(inst
, noDefault
);
489 return (inst
? this._getDate(inst
) : null);
492 /* Handle keystrokes. */
493 _doKeyDown: function(event
) {
494 var inst
= $.datepicker
._getInst(event
.target
);
496 var isRTL
= inst
.dpDiv
.is('.ui-datepicker-rtl');
497 inst
._keyEvent
= true;
498 if ($.datepicker
._datepickerShowing
)
499 switch (event
.keyCode
) {
500 case 9: $.datepicker
._hideDatepicker();
502 break; // hide on tab out
503 case 13: var sel
= $('td.' + $.datepicker
._dayOverClass
+ ':not(.' +
504 $.datepicker
._currentClass
+ ')', inst
.dpDiv
);
506 $.datepicker
._selectDay(event
.target
, inst
.selectedMonth
, inst
.selectedYear
, sel
[0]);
508 $.datepicker
._hideDatepicker();
509 return false; // don't submit the form
510 break; // select the value on enter
511 case 27: $.datepicker
._hideDatepicker();
512 break; // hide on escape
513 case 33: $.datepicker
._adjustDate(event
.target
, (event
.ctrlKey
?
514 -$.datepicker
._get(inst
, 'stepBigMonths') :
515 -$.datepicker
._get(inst
, 'stepMonths')), 'M');
516 break; // previous month/year on page up/+ ctrl
517 case 34: $.datepicker
._adjustDate(event
.target
, (event
.ctrlKey
?
518 +$.datepicker
._get(inst
, 'stepBigMonths') :
519 +$.datepicker
._get(inst
, 'stepMonths')), 'M');
520 break; // next month/year on page down/+ ctrl
521 case 35: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._clearDate(event
.target
);
522 handled
= event
.ctrlKey
|| event
.metaKey
;
523 break; // clear on ctrl or command +end
524 case 36: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._gotoToday(event
.target
);
525 handled
= event
.ctrlKey
|| event
.metaKey
;
526 break; // current on ctrl or command +home
527 case 37: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._adjustDate(event
.target
, (isRTL
? +1 : -1), 'D');
528 handled
= event
.ctrlKey
|| event
.metaKey
;
529 // -1 day on ctrl or command +left
530 if (event
.originalEvent
.altKey
) $.datepicker
._adjustDate(event
.target
, (event
.ctrlKey
?
531 -$.datepicker
._get(inst
, 'stepBigMonths') :
532 -$.datepicker
._get(inst
, 'stepMonths')), 'M');
533 // next month/year on alt +left on Mac
535 case 38: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._adjustDate(event
.target
, -7, 'D');
536 handled
= event
.ctrlKey
|| event
.metaKey
;
537 break; // -1 week on ctrl or command +up
538 case 39: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._adjustDate(event
.target
, (isRTL
? -1 : +1), 'D');
539 handled
= event
.ctrlKey
|| event
.metaKey
;
540 // +1 day on ctrl or command +right
541 if (event
.originalEvent
.altKey
) $.datepicker
._adjustDate(event
.target
, (event
.ctrlKey
?
542 +$.datepicker
._get(inst
, 'stepBigMonths') :
543 +$.datepicker
._get(inst
, 'stepMonths')), 'M');
544 // next month/year on alt +right
546 case 40: if (event
.ctrlKey
|| event
.metaKey
) $.datepicker
._adjustDate(event
.target
, +7, 'D');
547 handled
= event
.ctrlKey
|| event
.metaKey
;
548 break; // +1 week on ctrl or command +down
549 default: handled
= false;
551 else if (event
.keyCode
== 36 && event
.ctrlKey
) // display the date picker on ctrl+home
552 $.datepicker
._showDatepicker(this);
557 event
.preventDefault();
558 event
.stopPropagation();
562 /* Filter entered characters - based on date format. */
563 _doKeyPress: function(event
) {
564 var inst
= $.datepicker
._getInst(event
.target
);
565 if ($.datepicker
._get(inst
, 'constrainInput')) {
566 var chars
= $.datepicker
._possibleChars($.datepicker
._get(inst
, 'dateFormat'));
567 var chr
= String
.fromCharCode(event
.charCode
== undefined ? event
.keyCode
: event
.charCode
);
568 return event
.ctrlKey
|| event
.metaKey
|| (chr
< ' ' || !chars
|| chars
.indexOf(chr
) > -1);
572 /* Synchronise manual entry and field/alternate field. */
573 _doKeyUp: function(event) {
574 var inst = $.datepicker._getInst(event.target);
575 if (inst.input.val() != inst.lastVal) {
577 var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
578 (inst.input ? inst.input.val() : null),
579 $.datepicker._getFormatConfig(inst));
580 if (date) { // only if valid
581 $.datepicker._setDateFromField(inst);
582 $.datepicker._updateAlternate(inst);
583 $.datepicker._updateDatepicker(inst);
587 $.datepicker.log(event);
593 /* Pop-up the date picker for a given input field.
594 @param input element - the input field attached to the date picker or
595 event - if triggered by focus */
596 _showDatepicker: function(input
) {
597 input
= input
.target
|| input
;
598 if (input
.nodeName
.toLowerCase() != 'input') // find from button/image trigger
599 input
= $('input', input
.parentNode
)[0];
600 if ($.datepicker
._isDisabledDatepicker(input
) || $.datepicker
._lastInput
== input
) // already here
602 var inst
= $.datepicker
._getInst(input
);
603 if ($.datepicker
._curInst
&& $.datepicker
._curInst
!= inst
) {
604 $.datepicker
._curInst
.dpDiv
.stop(true, true);
606 var beforeShow
= $.datepicker
._get(inst
, 'beforeShow');
607 extendRemove(inst
.settings
, (beforeShow
? beforeShow
.apply(input
, [input
, inst
]) : {}));
609 $.datepicker
._lastInput
= input
;
610 $.datepicker
._setDateFromField(inst
);
611 if ($.datepicker
._inDialog
) // hide cursor
613 if (!$.datepicker
._pos
) { // position below input
614 $.datepicker
._pos
= $.datepicker
._findPos(input
);
615 $.datepicker
._pos
[1] += input
.offsetHeight
; // add the height
618 $(input
).parents().each(function() {
619 isFixed
|= $(this).css('position') == 'fixed';
622 if (isFixed
&& $.browser
.opera
) { // correction for Opera when fixed and scrolled
623 $.datepicker
._pos
[0] -= document
.documentElement
.scrollLeft
;
624 $.datepicker
._pos
[1] -= document
.documentElement
.scrollTop
;
626 var offset
= {left
: $.datepicker
._pos
[0], top
: $.datepicker
._pos
[1]};
627 $.datepicker
._pos
= null;
628 //to avoid flashes on Firefox
630 // determine sizing offscreen
631 inst
.dpDiv
.css({position
: 'absolute', display
: 'block', top
: '-1000px'});
632 $.datepicker
._updateDatepicker(inst
);
633 // fix width for dynamic number of date pickers
634 // and adjust position before showing
635 offset
= $.datepicker
._checkOffset(inst
, offset
, isFixed
);
636 inst
.dpDiv
.css({position
: ($.datepicker
._inDialog
&& $.blockUI
?
637 'static' : (isFixed
? 'fixed' : 'absolute')), display
: 'none',
638 left
: offset
.left
+ 'px', top
: offset
.top
+ 'px'});
640 var showAnim
= $.datepicker
._get(inst
, 'showAnim');
641 var duration
= $.datepicker
._get(inst
, 'duration');
642 var postProcess = function() {
643 $.datepicker
._datepickerShowing
= true;
644 var cover
= inst
.dpDiv
.find('iframe.ui-datepicker-cover'); // IE6- only
645 if( !! cover
.length
){
646 var borders
= $.datepicker
._getBorders(inst
.dpDiv
);
647 cover
.css({left
: -borders
[0], top
: -borders
[1],
648 width
: inst
.dpDiv
.outerWidth(), height
: inst
.dpDiv
.outerHeight()});
651 inst
.dpDiv
.zIndex($(input
).zIndex()+1);
652 if ($.effects
&& $.effects
[showAnim
])
653 inst
.dpDiv
.show(showAnim
, $.datepicker
._get(inst
, 'showOptions'), duration
, postProcess
);
655 inst
.dpDiv
[showAnim
|| 'show']((showAnim
? duration
: null), postProcess
);
656 if (!showAnim
|| !duration
)
658 if (inst
.input
.is(':visible') && !inst
.input
.is(':disabled'))
660 $.datepicker
._curInst
= inst
;
664 /* Generate the date picker content. */
665 _updateDatepicker: function(inst
) {
667 var borders
= $.datepicker
._getBorders(inst
.dpDiv
);
668 inst
.dpDiv
.empty().append(this._generateHTML(inst
));
669 var cover
= inst
.dpDiv
.find('iframe.ui-datepicker-cover'); // IE6- only
670 if( !!cover
.length
){ //avoid call to outerXXXX() when not in IE6
671 cover
.css({left
: -borders
[0], top
: -borders
[1], width
: inst
.dpDiv
.outerWidth(), height
: inst
.dpDiv
.outerHeight()})
673 inst
.dpDiv
.find('button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a')
674 .bind('mouseout', function(){
675 $(this).removeClass('ui-state-hover');
676 if(this.className
.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
677 if(this.className
.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
679 .bind('mouseover', function(){
680 if (!self
._isDisabledDatepicker( inst
.inline
? inst
.dpDiv
.parent()[0] : inst
.input
[0])) {
681 $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
682 $(this).addClass('ui-state-hover');
683 if(this.className
.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
684 if(this.className
.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
688 .find('.' + this._dayOverClass
+ ' a')
689 .trigger('mouseover')
691 var numMonths
= this._getNumberOfMonths(inst
);
692 var cols
= numMonths
[1];
695 inst
.dpDiv
.addClass('ui-datepicker-multi-' + cols
).css('width', (width
* cols
) + 'em');
697 inst
.dpDiv
.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
698 inst
.dpDiv
[(numMonths
[0] != 1 || numMonths
[1] != 1 ? 'add' : 'remove') +
699 'Class']('ui-datepicker-multi');
700 inst
.dpDiv
[(this._get(inst
, 'isRTL') ? 'add' : 'remove') +
701 'Class']('ui-datepicker-rtl');
702 if (inst
== $.datepicker
._curInst
&& $.datepicker
._datepickerShowing
&& inst
.input
&&
703 inst
.input
.is(':visible') && !inst
.input
.is(':disabled'))
705 // deffered render of the years select (to avoid flashes on Firefox)
706 if( inst
.yearshtml
){
707 var origyearshtml
= inst
.yearshtml
;
708 setTimeout(function(){
709 //assure that inst.yearshtml didn't change.
710 if( origyearshtml
=== inst
.yearshtml
){
711 inst
.dpDiv
.find('select.ui-datepicker-year:first').replaceWith(inst
.yearshtml
);
713 origyearshtml
= inst
.yearshtml
= null;
718 /* Retrieve the size of left and top borders for an element.
719 @param elem (jQuery object) the element of interest
720 @return (number[2]) the left and top borders */
721 _getBorders: function(elem
) {
722 var convert = function(value
) {
723 return {thin
: 1, medium
: 2, thick
: 3}[value
] || value
;
725 return [parseFloat(convert(elem
.css('border-left-width'))),
726 parseFloat(convert(elem
.css('border-top-width')))];
729 /* Check positioning to remain on screen. */
730 _checkOffset: function(inst
, offset
, isFixed
) {
731 var dpWidth
= inst
.dpDiv
.outerWidth();
732 var dpHeight
= inst
.dpDiv
.outerHeight();
733 var inputWidth
= inst
.input
? inst
.input
.outerWidth() : 0;
734 var inputHeight
= inst
.input
? inst
.input
.outerHeight() : 0;
735 var viewWidth
= document
.documentElement
.clientWidth
+ $(document
).scrollLeft();
736 var viewHeight
= document
.documentElement
.clientHeight
+ $(document
).scrollTop();
738 offset
.left
-= (this._get(inst
, 'isRTL') ? (dpWidth
- inputWidth
) : 0);
739 offset
.left
-= (isFixed
&& offset
.left
== inst
.input
.offset().left
) ? $(document
).scrollLeft() : 0;
740 offset
.top
-= (isFixed
&& offset
.top
== (inst
.input
.offset().top
+ inputHeight
)) ? $(document
).scrollTop() : 0;
742 // now check if datepicker is showing outside window viewport - move to a better place if so.
743 offset
.left
-= Math
.min(offset
.left
, (offset
.left
+ dpWidth
> viewWidth
&& viewWidth
> dpWidth
) ?
744 Math
.abs(offset
.left
+ dpWidth
- viewWidth
) : 0);
745 offset
.top
-= Math
.min(offset
.top
, (offset
.top
+ dpHeight
> viewHeight
&& viewHeight
> dpHeight
) ?
746 Math
.abs(dpHeight
+ inputHeight
) : 0);
751 /* Find an object's position on the screen. */
752 _findPos: function(obj
) {
753 var inst
= this._getInst(obj
);
754 var isRTL
= this._get(inst
, 'isRTL');
755 while (obj
&& (obj
.type
== 'hidden' || obj
.nodeType
!= 1)) {
756 obj
= obj
[isRTL
? 'previousSibling' : 'nextSibling'];
758 var position
= $(obj
).offset();
759 return [position
.left
, position
.top
];
762 /* Hide the date picker from view.
763 @param input element - the input field attached to the date picker */
764 _hideDatepicker: function(input
) {
765 var inst
= this._curInst
;
766 if (!inst
|| (input
&& inst
!= $.data(input
, PROP_NAME
)))
768 if (this._datepickerShowing
) {
769 var showAnim
= this._get(inst
, 'showAnim');
770 var duration
= this._get(inst
, 'duration');
771 var postProcess = function() {
772 $.datepicker
._tidyDialog(inst
);
773 this._curInst
= null;
775 if ($.effects
&& $.effects
[showAnim
])
776 inst
.dpDiv
.hide(showAnim
, $.datepicker
._get(inst
, 'showOptions'), duration
, postProcess
);
778 inst
.dpDiv
[(showAnim
== 'slideDown' ? 'slideUp' :
779 (showAnim
== 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim
? duration
: null), postProcess
);
782 var onClose
= this._get(inst
, 'onClose');
784 onClose
.apply((inst
.input
? inst
.input
[0] : null),
785 [(inst
.input
? inst
.input
.val() : ''), inst
]); // trigger custom callback
786 this._datepickerShowing
= false;
787 this._lastInput
= null;
788 if (this._inDialog
) {
789 this._dialogInput
.css({ position
: 'absolute', left
: '0', top
: '-100px' });
792 $('body').append(this.dpDiv
);
795 this._inDialog
= false;
799 /* Tidy up after a dialog display. */
800 _tidyDialog: function(inst
) {
801 inst
.dpDiv
.removeClass(this._dialogClass
).unbind('.ui-datepicker-calendar');
804 /* Close date picker if clicked elsewhere. */
805 _checkExternalClick: function(event
) {
806 if (!$.datepicker
._curInst
)
808 var $target
= $(event
.target
);
809 if ($target
[0].id
!= $.datepicker
._mainDivId
&&
810 $target
.parents('#' + $.datepicker
._mainDivId
).length
== 0 &&
811 !$target
.hasClass($.datepicker
.markerClassName
) &&
812 !$target
.hasClass($.datepicker
._triggerClass
) &&
813 $.datepicker
._datepickerShowing
&& !($.datepicker
._inDialog
&& $.blockUI
))
814 $.datepicker
._hideDatepicker();
817 /* Adjust one of the date sub-fields. */
818 _adjustDate: function(id
, offset
, period
) {
820 var inst
= this._getInst(target
[0]);
821 if (this._isDisabledDatepicker(target
[0])) {
824 this._adjustInstDate(inst
, offset
+
825 (period
== 'M' ? this._get(inst
, 'showCurrentAtPos') : 0), // undo positioning
827 this._updateDatepicker(inst
);
830 /* Action for current link. */
831 _gotoToday: function(id
) {
833 var inst
= this._getInst(target
[0]);
834 if (this._get(inst
, 'gotoCurrent') && inst
.currentDay
) {
835 inst
.selectedDay
= inst
.currentDay
;
836 inst
.drawMonth
= inst
.selectedMonth
= inst
.currentMonth
;
837 inst
.drawYear
= inst
.selectedYear
= inst
.currentYear
;
840 var date
= new Date();
841 inst
.selectedDay
= date
.getDate();
842 inst
.drawMonth
= inst
.selectedMonth
= date
.getMonth();
843 inst
.drawYear
= inst
.selectedYear
= date
.getFullYear();
845 this._notifyChange(inst
);
846 this._adjustDate(target
);
849 /* Action for selecting a new month/year. */
850 _selectMonthYear: function(id, select, period) {
852 var inst = this._getInst(target[0]);
853 inst._selectingMonthYear = false;
854 inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
855 inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
856 parseInt(select.options[select.selectedIndex].value,10);
857 this._notifyChange(inst);
858 this._adjustDate(target);
861 /* Restore input focus after not changing month/year. */
862 _clickMonthYear: function(id) {
864 var inst = this._getInst(target[0]);
865 if (inst.input && inst._selectingMonthYear) {
866 setTimeout(function() {
870 inst._selectingMonthYear = !inst._selectingMonthYear;
873 /* Action for selecting a day. */
874 _selectDay: function(id
, month
, year
, td
) {
876 if ($(td
).hasClass(this._unselectableClass
) || this._isDisabledDatepicker(target
[0])) {
879 var inst
= this._getInst(target
[0]);
880 inst
.selectedDay
= inst
.currentDay
= $('a', td
).html();
881 inst
.selectedMonth
= inst
.currentMonth
= month
;
882 inst
.selectedYear
= inst
.currentYear
= year
;
883 this._selectDate(id
, this._formatDate(inst
,
884 inst
.currentDay
, inst
.currentMonth
, inst
.currentYear
));
887 /* Erase the input field and hide the date picker. */
888 _clearDate: function(id
) {
890 var inst
= this._getInst(target
[0]);
891 this._selectDate(target
, '');
894 /* Update the input field with the selected date. */
895 _selectDate: function(id
, dateStr
) {
897 var inst
= this._getInst(target
[0]);
898 dateStr
= (dateStr
!= null ? dateStr
: this._formatDate(inst
));
900 inst
.input
.val(dateStr
);
901 this._updateAlternate(inst
);
902 var onSelect
= this._get(inst
, 'onSelect');
904 onSelect
.apply((inst
.input
? inst
.input
[0] : null), [dateStr
, inst
]); // trigger custom callback
906 inst
.input
.trigger('change'); // fire the change event
908 this._updateDatepicker(inst
);
910 this._hideDatepicker();
911 this._lastInput
= inst
.input
[0];
912 if (typeof(inst
.input
[0]) != 'object')
913 inst
.input
.focus(); // restore focus
914 this._lastInput
= null;
918 /* Update any alternate field to synchronise with the main field. */
919 _updateAlternate: function(inst
) {
920 var altField
= this._get(inst
, 'altField');
921 if (altField
) { // update alternate field too
922 var altFormat
= this._get(inst
, 'altFormat') || this._get(inst
, 'dateFormat');
923 var date
= this._getDate(inst
);
924 var dateStr
= this.formatDate(altFormat
, date
, this._getFormatConfig(inst
));
925 $(altField
).each(function() { $(this).val(dateStr
); });
929 /* Set as beforeShowDay function to prevent selection of weekends.
930 @param date Date - the date to customise
931 @return [boolean, string] - is this date selectable?, what is its CSS class? */
932 noWeekends: function(date
) {
933 var day
= date
.getDay();
934 return [(day
> 0 && day
< 6), ''];
937 /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
938 @param date Date - the date to get the week for
939 @return number - the number of the week within the year that contains this date */
940 iso8601Week: function(date
) {
941 var checkDate
= new Date(date
.getTime());
942 // Find Thursday of this week starting on Monday
943 checkDate
.setDate(checkDate
.getDate() + 4 - (checkDate
.getDay() || 7));
944 var time
= checkDate
.getTime();
945 checkDate
.setMonth(0); // Compare with Jan 1
946 checkDate
.setDate(1);
947 return Math
.floor(Math
.round((time
- checkDate
) / 86400000) / 7) + 1;
950 /* Parse a string value into a date object.
951 See formatDate below for the possible formats.
953 @param format string - the expected format of the date
954 @param value string - the date in the above format
955 @param settings Object - attributes include:
956 shortYearCutoff number - the cutoff year for determining the century (optional)
957 dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
958 dayNames string[7] - names of the days from Sunday (optional)
959 monthNamesShort string[12] - abbreviated names of the months (optional)
960 monthNames string[12] - names of the months (optional)
961 @return Date - the extracted date value or null if value is blank */
962 parseDate: function (format
, value
, settings
) {
963 if (format
== null || value
== null)
964 throw 'Invalid arguments';
965 value
= (typeof value
== 'object' ? value
.toString() : value
+ '');
968 var shortYearCutoff
= (settings
? settings
.shortYearCutoff
: null) || this._defaults
.shortYearCutoff
;
969 var dayNamesShort
= (settings
? settings
.dayNamesShort
: null) || this._defaults
.dayNamesShort
;
970 var dayNames
= (settings
? settings
.dayNames
: null) || this._defaults
.dayNames
;
971 var monthNamesShort
= (settings
? settings
.monthNamesShort
: null) || this._defaults
.monthNamesShort
;
972 var monthNames
= (settings
? settings
.monthNames
: null) || this._defaults
.monthNames
;
978 // Check whether a format character is doubled
979 var lookAhead = function(match
) {
980 var matches
= (iFormat
+ 1 < format
.length
&& format
.charAt(iFormat
+ 1) == match
);
985 // Extract a number from the string value
986 var getNumber = function(match
) {
987 var isDoubled
= lookAhead(match
);
988 var size
= (match
== '@' ? 14 : (match
== '!' ? 20 :
989 (match
== 'y' && isDoubled
? 4 : (match
== 'o' ? 3 : 2))));
990 var digits
= new RegExp('^\\d{1,' + size
+ '}');
991 var num
= value
.substring(iValue
).match(digits
);
993 throw 'Missing number at position ' + iValue
;
994 iValue
+= num
[0].length
;
995 return parseInt(num
[0], 10);
997 // Extract a name from the string value and convert to an index
998 var getName = function(match
, shortNames
, longNames
) {
999 var names
= (lookAhead(match
) ? longNames
: shortNames
);
1000 for (var i
= 0; i
< names
.length
; i
++) {
1001 if (value
.substr(iValue
, names
[i
].length
).toLowerCase() == names
[i
].toLowerCase()) {
1002 iValue
+= names
[i
].length
;
1006 throw 'Unknown name at position ' + iValue
;
1008 // Confirm that a literal character matches the string value
1009 var checkLiteral = function() {
1010 if (value
.charAt(iValue
) != format
.charAt(iFormat
))
1011 throw 'Unexpected literal at position ' + iValue
;
1015 for (var iFormat
= 0; iFormat
< format
.length
; iFormat
++) {
1017 if (format
.charAt(iFormat
) == "'" && !lookAhead("'"))
1022 switch (format
.charAt(iFormat
)) {
1024 day
= getNumber('d');
1027 getName('D', dayNamesShort
, dayNames
);
1030 doy
= getNumber('o');
1033 month
= getNumber('m');
1036 month
= getName('M', monthNamesShort
, monthNames
);
1039 year
= getNumber('y');
1042 var date
= new Date(getNumber('@'));
1043 year
= date
.getFullYear();
1044 month
= date
.getMonth() + 1;
1045 day
= date
.getDate();
1048 var date
= new Date((getNumber('!') - this._ticksTo1970
) / 10000);
1049 year
= date
.getFullYear();
1050 month
= date
.getMonth() + 1;
1051 day
= date
.getDate();
1064 year
= new Date().getFullYear();
1065 else if (year
< 100)
1066 year
+= new Date().getFullYear() - new Date().getFullYear() % 100 +
1067 (year
<= shortYearCutoff
? 0 : -100);
1072 var dim
= this._getDaysInMonth(year
, month
- 1);
1079 var date
= this._daylightSavingAdjust(new Date(year
, month
- 1, day
));
1080 if (date
.getFullYear() != year
|| date
.getMonth() + 1 != month
|| date
.getDate() != day
)
1081 throw 'Invalid date'; // E.g. 31/02/*
1085 /* Standard date formats. */
1086 ATOM
: 'yy-mm-dd', // RFC 3339 (ISO 8601)
1087 COOKIE
: 'D, dd M yy',
1088 ISO_8601
: 'yy-mm-dd',
1089 RFC_822
: 'D, d M y',
1090 RFC_850
: 'DD, dd-M-y',
1091 RFC_1036
: 'D, d M y',
1092 RFC_1123
: 'D, d M yy',
1093 RFC_2822
: 'D, d M yy',
1094 RSS
: 'D, d M y', // RFC 822
1097 W3C
: 'yy-mm-dd', // ISO 8601
1099 _ticksTo1970
: (((1970 - 1) * 365 + Math
.floor(1970 / 4) - Math
.floor(1970 / 100) +
1100 Math
.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
1102 /* Format a date object into a string value.
1103 The format can be combinations of the following:
1104 d - day of month (no leading zero)
1105 dd - day of month (two digit)
1106 o - day of year (no leading zeros)
1107 oo - day of year (three digit)
1110 m - month of year (no leading zero)
1111 mm - month of year (two digit)
1112 M - month name short
1113 MM - month name long
1114 y - year (two digit)
1115 yy - year (four digit)
1116 @ - Unix timestamp (ms since 01/01/1970)
1117 ! - Windows ticks (100ns since 01/01/0001)
1118 '...' - literal text
1121 @param format string - the desired format of the date
1122 @param date Date - the date value to format
1123 @param settings Object - attributes include:
1124 dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
1125 dayNames string[7] - names of the days from Sunday (optional)
1126 monthNamesShort string[12] - abbreviated names of the months (optional)
1127 monthNames string[12] - names of the months (optional)
1128 @return string - the date in the above format */
1129 formatDate: function (format
, date
, settings
) {
1132 var dayNamesShort
= (settings
? settings
.dayNamesShort
: null) || this._defaults
.dayNamesShort
;
1133 var dayNames
= (settings
? settings
.dayNames
: null) || this._defaults
.dayNames
;
1134 var monthNamesShort
= (settings
? settings
.monthNamesShort
: null) || this._defaults
.monthNamesShort
;
1135 var monthNames
= (settings
? settings
.monthNames
: null) || this._defaults
.monthNames
;
1136 // Check whether a format character is doubled
1137 var lookAhead = function(match
) {
1138 var matches
= (iFormat
+ 1 < format
.length
&& format
.charAt(iFormat
+ 1) == match
);
1143 // Format a number, with leading zero if necessary
1144 var formatNumber = function(match
, value
, len
) {
1145 var num
= '' + value
;
1146 if (lookAhead(match
))
1147 while (num
.length
< len
)
1151 // Format a name, short or long as requested
1152 var formatName = function(match
, value
, shortNames
, longNames
) {
1153 return (lookAhead(match
) ? longNames
[value
] : shortNames
[value
]);
1156 var literal
= false;
1158 for (var iFormat
= 0; iFormat
< format
.length
; iFormat
++) {
1160 if (format
.charAt(iFormat
) == "'" && !lookAhead("'"))
1163 output
+= format
.charAt(iFormat
);
1165 switch (format
.charAt(iFormat
)) {
1167 output
+= formatNumber('d', date
.getDate(), 2);
1170 output
+= formatName('D', date
.getDay(), dayNamesShort
, dayNames
);
1173 output
+= formatNumber('o',
1174 (date
.getTime() - new Date(date
.getFullYear(), 0, 0).getTime()) / 86400000, 3);
1177 output
+= formatNumber('m', date
.getMonth() + 1, 2);
1180 output
+= formatName('M', date
.getMonth(), monthNamesShort
, monthNames
);
1183 output
+= (lookAhead('y') ? date
.getFullYear() :
1184 (date
.getYear() % 100 < 10 ? '0' : '') + date
.getYear() % 100);
1187 output
+= date
.getTime();
1190 output
+= date
.getTime() * 10000 + this._ticksTo1970
;
1199 output
+= format
.charAt(iFormat
);
1205 /* Extract all possible characters from the date format. */
1206 _possibleChars: function (format
) {
1208 var literal
= false;
1209 // Check whether a format character is doubled
1210 var lookAhead = function(match
) {
1211 var matches
= (iFormat
+ 1 < format
.length
&& format
.charAt(iFormat
+ 1) == match
);
1216 for (var iFormat
= 0; iFormat
< format
.length
; iFormat
++)
1218 if (format
.charAt(iFormat
) == "'" && !lookAhead("'"))
1221 chars
+= format
.charAt(iFormat
);
1223 switch (format
.charAt(iFormat
)) {
1224 case 'd': case 'm': case 'y': case '@':
1225 chars
+= '0123456789';
1228 return null; // Accept anything
1236 chars
+= format
.charAt(iFormat
);
1241 /* Get a setting value, defaulting if necessary. */
1242 _get: function(inst
, name
) {
1243 return inst
.settings
[name
] !== undefined ?
1244 inst
.settings
[name
] : this._defaults
[name
];
1247 /* Parse existing date and initialise date picker. */
1248 _setDateFromField: function(inst
, noDefault
) {
1249 if (inst
.input
.val() == inst
.lastVal
) {
1252 var dateFormat
= this._get(inst
, 'dateFormat');
1253 var dates
= inst
.lastVal
= inst
.input
? inst
.input
.val() : null;
1254 var date
, defaultDate
;
1255 date
= defaultDate
= this._getDefaultDate(inst
);
1256 var settings
= this._getFormatConfig(inst
);
1258 date
= this.parseDate(dateFormat
, dates
, settings
) || defaultDate
;
1261 dates
= (noDefault
? '' : dates
);
1263 inst
.selectedDay
= date
.getDate();
1264 inst
.drawMonth
= inst
.selectedMonth
= date
.getMonth();
1265 inst
.drawYear
= inst
.selectedYear
= date
.getFullYear();
1266 inst
.currentDay
= (dates
? date
.getDate() : 0);
1267 inst
.currentMonth
= (dates
? date
.getMonth() : 0);
1268 inst
.currentYear
= (dates
? date
.getFullYear() : 0);
1269 this._adjustInstDate(inst
);
1272 /* Retrieve the default date shown on opening. */
1273 _getDefaultDate: function(inst
) {
1274 return this._restrictMinMax(inst
,
1275 this._determineDate(inst
, this._get(inst
, 'defaultDate'), new Date()));
1278 /* A date may be specified as an exact value or a relative one. */
1279 _determineDate: function(inst
, date
, defaultDate
) {
1280 var offsetNumeric = function(offset
) {
1281 var date
= new Date();
1282 date
.setDate(date
.getDate() + offset
);
1285 var offsetString = function(offset
) {
1287 return $.datepicker
.parseDate($.datepicker
._get(inst
, 'dateFormat'),
1288 offset
, $.datepicker
._getFormatConfig(inst
));
1293 var date
= (offset
.toLowerCase().match(/^c/) ?
1294 $.datepicker
._getDate(inst
) : null) || new Date();
1295 var year
= date
.getFullYear();
1296 var month
= date
.getMonth();
1297 var day
= date
.getDate();
1298 var pattern
= /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
1299 var matches
= pattern
.exec(offset
);
1301 switch (matches
[2] || 'd') {
1302 case 'd' : case 'D' :
1303 day
+= parseInt(matches
[1],10); break;
1304 case 'w' : case 'W' :
1305 day
+= parseInt(matches
[1],10) * 7; break;
1306 case 'm' : case 'M' :
1307 month
+= parseInt(matches
[1],10);
1308 day
= Math
.min(day
, $.datepicker
._getDaysInMonth(year
, month
));
1310 case 'y': case 'Y' :
1311 year
+= parseInt(matches
[1],10);
1312 day
= Math
.min(day
, $.datepicker
._getDaysInMonth(year
, month
));
1315 matches
= pattern
.exec(offset
);
1317 return new Date(year
, month
, day
);
1319 var newDate
= (date
== null || date
=== '' ? defaultDate
: (typeof date
== 'string' ? offsetString(date
) :
1320 (typeof date
== 'number' ? (isNaN(date
) ? defaultDate
: offsetNumeric(date
)) : new Date(date
.getTime()))));
1321 newDate
= (newDate
&& newDate
.toString() == 'Invalid Date' ? defaultDate
: newDate
);
1323 newDate
.setHours(0);
1324 newDate
.setMinutes(0);
1325 newDate
.setSeconds(0);
1326 newDate
.setMilliseconds(0);
1328 return this._daylightSavingAdjust(newDate
);
1331 /* Handle switch to/from daylight saving.
1332 Hours may be non-zero on daylight saving cut-over:
1333 > 12 when midnight changeover, but then cannot generate
1334 midnight datetime, so jump to 1AM, otherwise reset.
1335 @param date (Date) the date to check
1336 @return (Date) the corrected date */
1337 _daylightSavingAdjust: function(date
) {
1338 if (!date
) return null;
1339 date
.setHours(date
.getHours() > 12 ? date
.getHours() + 2 : 0);
1343 /* Set the date(s) directly. */
1344 _setDate: function(inst
, date
, noChange
) {
1346 var origMonth
= inst
.selectedMonth
;
1347 var origYear
= inst
.selectedYear
;
1348 var newDate
= this._restrictMinMax(inst
, this._determineDate(inst
, date
, new Date()));
1349 inst
.selectedDay
= inst
.currentDay
= newDate
.getDate();
1350 inst
.drawMonth
= inst
.selectedMonth
= inst
.currentMonth
= newDate
.getMonth();
1351 inst
.drawYear
= inst
.selectedYear
= inst
.currentYear
= newDate
.getFullYear();
1352 if ((origMonth
!= inst
.selectedMonth
|| origYear
!= inst
.selectedYear
) && !noChange
)
1353 this._notifyChange(inst
);
1354 this._adjustInstDate(inst
);
1356 inst
.input
.val(clear
? '' : this._formatDate(inst
));
1360 /* Retrieve the date(s) directly. */
1361 _getDate: function(inst
) {
1362 var startDate
= (!inst
.currentYear
|| (inst
.input
&& inst
.input
.val() == '') ? null :
1363 this._daylightSavingAdjust(new Date(
1364 inst
.currentYear
, inst
.currentMonth
, inst
.currentDay
)));
1368 /* Generate the HTML for the current state of the date picker. */
1369 _generateHTML: function(inst
) {
1370 var today
= new Date();
1371 today
= this._daylightSavingAdjust(
1372 new Date(today
.getFullYear(), today
.getMonth(), today
.getDate())); // clear time
1373 var isRTL
= this._get(inst
, 'isRTL');
1374 var showButtonPanel
= this._get(inst
, 'showButtonPanel');
1375 var hideIfNoPrevNext
= this._get(inst
, 'hideIfNoPrevNext');
1376 var navigationAsDateFormat
= this._get(inst
, 'navigationAsDateFormat');
1377 var numMonths
= this._getNumberOfMonths(inst
);
1378 var showCurrentAtPos
= this._get(inst
, 'showCurrentAtPos');
1379 var stepMonths
= this._get(inst
, 'stepMonths');
1380 var isMultiMonth
= (numMonths
[0] != 1 || numMonths
[1] != 1);
1381 var currentDate
= this._daylightSavingAdjust((!inst
.currentDay
? new Date(9999, 9, 9) :
1382 new Date(inst
.currentYear
, inst
.currentMonth
, inst
.currentDay
)));
1383 var minDate
= this._getMinMaxDate(inst
, 'min');
1384 var maxDate
= this._getMinMaxDate(inst
, 'max');
1385 var drawMonth
= inst
.drawMonth
- showCurrentAtPos
;
1386 var drawYear
= inst
.drawYear
;
1387 if (drawMonth
< 0) {
1392 var maxDraw
= this._daylightSavingAdjust(new Date(maxDate
.getFullYear(),
1393 maxDate
.getMonth() - (numMonths
[0] * numMonths
[1]) + 1, maxDate
.getDate()));
1394 maxDraw
= (minDate
&& maxDraw
< minDate
? minDate
: maxDraw
);
1395 while (this._daylightSavingAdjust(new Date(drawYear
, drawMonth
, 1)) > maxDraw
) {
1397 if (drawMonth
< 0) {
1403 inst
.drawMonth
= drawMonth
;
1404 inst
.drawYear
= drawYear
;
1405 var prevText
= this._get(inst
, 'prevText');
1406 prevText
= (!navigationAsDateFormat
? prevText
: this.formatDate(prevText
,
1407 this._daylightSavingAdjust(new Date(drawYear
, drawMonth
- stepMonths
, 1)),
1408 this._getFormatConfig(inst
)));
1409 var prev
= (this._canAdjustMonth(inst
, -1, drawYear
, drawMonth
) ?
1410 '<a class="ui-datepicker-prev ui-corner-all" onclick="DP_jQuery_' + dpuuid
+
1411 '.datepicker._adjustDate(\'#' + inst
.id
+ '\', -' + stepMonths
+ ', \'M\');"' +
1412 ' title="' + prevText
+ '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL
? 'e' : 'w') + '">' + prevText
+ '</span></a>' :
1413 (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>'));
1414 var nextText
= this._get(inst
, 'nextText');
1415 nextText
= (!navigationAsDateFormat
? nextText
: this.formatDate(nextText
,
1416 this._daylightSavingAdjust(new Date(drawYear
, drawMonth
+ stepMonths
, 1)),
1417 this._getFormatConfig(inst
)));
1418 var next
= (this._canAdjustMonth(inst
, +1, drawYear
, drawMonth
) ?
1419 '<a class="ui-datepicker-next ui-corner-all" onclick="DP_jQuery_' + dpuuid
+
1420 '.datepicker._adjustDate(\'#' + inst
.id
+ '\', +' + stepMonths
+ ', \'M\');"' +
1421 ' title="' + nextText
+ '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL
? 'w' : 'e') + '">' + nextText
+ '</span></a>' :
1422 (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>'));
1423 var currentText
= this._get(inst
, 'currentText');
1424 var gotoDate
= (this._get(inst
, 'gotoCurrent') && inst
.currentDay
? currentDate
: today
);
1425 currentText
= (!navigationAsDateFormat
? currentText
:
1426 this.formatDate(currentText
, gotoDate
, this._getFormatConfig(inst
)));
1427 var controls
= (!inst
.inline
? '<button type="button" class="ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all" onclick="DP_jQuery_' + dpuuid
+
1428 '.datepicker._hideDatepicker();">' + this._get(inst
, 'closeText') + '</button>' : '');
1429 var buttonPanel
= (showButtonPanel
) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL
? controls
: '') +
1430 (this._isInRange(inst
, gotoDate
) ? '<button type="button" class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" onclick="DP_jQuery_' + dpuuid
+
1431 '.datepicker._gotoToday(\'#' + inst
.id
+ '\');"' +
1432 '>' + currentText
+ '</button>' : '') + (isRTL
? '' : controls
) + '</div>' : '';
1433 var firstDay
= parseInt(this._get(inst
, 'firstDay'),10);
1434 firstDay
= (isNaN(firstDay
) ? 0 : firstDay
);
1435 var showWeek
= this._get(inst
, 'showWeek');
1436 var dayNames
= this._get(inst
, 'dayNames');
1437 var dayNamesShort
= this._get(inst
, 'dayNamesShort');
1438 var dayNamesMin
= this._get(inst
, 'dayNamesMin');
1439 var monthNames
= this._get(inst
, 'monthNames');
1440 var monthNamesShort
= this._get(inst
, 'monthNamesShort');
1441 var beforeShowDay
= this._get(inst
, 'beforeShowDay');
1442 var showOtherMonths
= this._get(inst
, 'showOtherMonths');
1443 var selectOtherMonths
= this._get(inst
, 'selectOtherMonths');
1444 var calculateWeek
= this._get(inst
, 'calculateWeek') || this.iso8601Week
;
1445 var defaultDate
= this._getDefaultDate(inst
);
1447 for (var row
= 0; row
< numMonths
[0]; row
++) {
1449 for (var col
= 0; col
< numMonths
[1]; col
++) {
1450 var selectedDate
= this._daylightSavingAdjust(new Date(drawYear
, drawMonth
, inst
.selectedDay
));
1451 var cornerClass
= ' ui-corner-all';
1454 calender
+= '<div class="ui-datepicker-group';
1455 if (numMonths
[1] > 1)
1457 case 0: calender
+= ' ui-datepicker-group-first';
1458 cornerClass
= ' ui-corner-' + (isRTL
? 'right' : 'left'); break;
1459 case numMonths
[1]-1: calender
+= ' ui-datepicker-group-last';
1460 cornerClass
= ' ui-corner-' + (isRTL
? 'left' : 'right'); break;
1461 default: calender
+= ' ui-datepicker-group-middle'; cornerClass
= ''; break;
1465 calender
+= '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass
+ '">' +
1466 (/all|left/.test(cornerClass
) && row
== 0 ? (isRTL
? next
: prev
) : '') +
1467 (/all|right/.test(cornerClass
) && row
== 0 ? (isRTL
? prev
: next
) : '') +
1468 this._generateMonthYearHeader(inst
, drawMonth
, drawYear
, minDate
, maxDate
,
1469 row
> 0 || col
> 0, monthNames
, monthNamesShort
) + // draw month headers
1470 '</div><table class="ui-datepicker-calendar"><thead>' +
1472 var thead
= (showWeek
? '<th class="ui-datepicker-week-col">' + this._get(inst
, 'weekHeader') + '</th>' : '');
1473 for (var dow
= 0; dow
< 7; dow
++) { // days of the week
1474 var day
= (dow
+ firstDay
) % 7;
1475 thead
+= '<th' + ((dow
+ firstDay
+ 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
1476 '<span title="' + dayNames
[day
] + '">' + dayNamesMin
[day
] + '</span></th>';
1478 calender
+= thead
+ '</tr></thead><tbody>';
1479 var daysInMonth
= this._getDaysInMonth(drawYear
, drawMonth
);
1480 if (drawYear
== inst
.selectedYear
&& drawMonth
== inst
.selectedMonth
)
1481 inst
.selectedDay
= Math
.min(inst
.selectedDay
, daysInMonth
);
1482 var leadDays
= (this._getFirstDayOfMonth(drawYear
, drawMonth
) - firstDay
+ 7) % 7;
1483 var numRows
= (isMultiMonth
? 6 : Math
.ceil((leadDays
+ daysInMonth
) / 7)); // calculate the number of rows to generate
1484 var printDate
= this._daylightSavingAdjust(new Date(drawYear
, drawMonth
, 1 - leadDays
));
1485 for (var dRow
= 0; dRow
< numRows
; dRow
++) { // create date picker rows
1487 var tbody
= (!showWeek
? '' : '<td class="ui-datepicker-week-col">' +
1488 this._get(inst
, 'calculateWeek')(printDate
) + '</td>');
1489 for (var dow
= 0; dow
< 7; dow
++) { // create date picker days
1490 var daySettings
= (beforeShowDay
?
1491 beforeShowDay
.apply((inst
.input
? inst
.input
[0] : null), [printDate
]) : [true, '']);
1492 var otherMonth
= (printDate
.getMonth() != drawMonth
);
1493 var unselectable
= (otherMonth
&& !selectOtherMonths
) || !daySettings
[0] ||
1494 (minDate
&& printDate
< minDate
) || (maxDate
&& printDate
> maxDate
);
1495 tbody
+= '<td class="' +
1496 ((dow
+ firstDay
+ 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
1497 (otherMonth
? ' ui-datepicker-other-month' : '') + // highlight days from other months
1498 ((printDate
.getTime() == selectedDate
.getTime() && drawMonth
== inst
.selectedMonth
&& inst
._keyEvent
) || // user pressed key
1499 (defaultDate
.getTime() == printDate
.getTime() && defaultDate
.getTime() == selectedDate
.getTime()) ?
1500 // or defaultDate is current printedDate and defaultDate is selectedDate
1501 ' ' + this._dayOverClass
: '') + // highlight selected day
1502 (unselectable
? ' ' + this._unselectableClass
+ ' ui-state-disabled': '') + // highlight unselectable days
1503 (otherMonth
&& !showOtherMonths
? '' : ' ' + daySettings
[1] + // highlight custom dates
1504 (printDate
.getTime() == currentDate
.getTime() ? ' ' + this._currentClass
: '') + // highlight selected day
1505 (printDate
.getTime() == today
.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
1506 ((!otherMonth
|| showOtherMonths
) && daySettings
[2] ? ' title="' + daySettings
[2] + '"' : '') + // cell title
1507 (unselectable
? '' : ' onclick="DP_jQuery_' + dpuuid
+ '.datepicker._selectDay(\'#' +
1508 inst
.id
+ '\',' + printDate
.getMonth() + ',' + printDate
.getFullYear() + ', this);return false;"') + '>' + // actions
1509 (otherMonth
&& !showOtherMonths
? ' ' : // display for other months
1510 (unselectable
? '<span class="ui-state-default">' + printDate
.getDate() + '</span>' : '<a class="ui-state-default' +
1511 (printDate
.getTime() == today
.getTime() ? ' ui-state-highlight' : '') +
1512 (printDate
.getTime() == currentDate
.getTime() ? ' ui-state-active' : '') + // highlight selected day
1513 (otherMonth
? ' ui-priority-secondary' : '') + // distinguish dates from other months
1514 '" href="#">' + printDate
.getDate() + '</a>')) + '</td>'; // display selectable date
1515 printDate
.setDate(printDate
.getDate() + 1);
1516 printDate
= this._daylightSavingAdjust(printDate
);
1518 calender
+= tbody
+ '</tr>';
1521 if (drawMonth
> 11) {
1525 calender
+= '</tbody></table>' + (isMultiMonth
? '</div>' +
1526 ((numMonths
[0] > 0 && col
== numMonths
[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
1531 html
+= buttonPanel
+ ($.browser
.msie
&& parseInt($.browser
.version
,10) < 7 && !inst
.inline
?
1532 '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
1533 inst
._keyEvent
= false;
1537 /* Generate the month and year header. */
1538 _generateMonthYearHeader: function(inst
, drawMonth
, drawYear
, minDate
, maxDate
,
1539 secondary
, monthNames
, monthNamesShort
) {
1540 var changeMonth
= this._get(inst
, 'changeMonth');
1541 var changeYear
= this._get(inst
, 'changeYear');
1542 var showMonthAfterYear
= this._get(inst
, 'showMonthAfterYear');
1543 var html
= '<div class="ui-datepicker-title">';
1546 if (secondary
|| !changeMonth
)
1547 monthHtml
+= '<span class="ui-datepicker-month">' + monthNames
[drawMonth
] + '</span>';
1549 var inMinYear
= (minDate
&& minDate
.getFullYear() == drawYear
);
1550 var inMaxYear
= (maxDate
&& maxDate
.getFullYear() == drawYear
);
1551 monthHtml
+= '<select class="ui-datepicker-month" ' +
1552 'onchange="DP_jQuery_' + dpuuid
+ '.datepicker._selectMonthYear(\'#' + inst
.id
+ '\', this, \'M\');" ' +
1553 'onclick="DP_jQuery_' + dpuuid
+ '.datepicker._clickMonthYear(\'#' + inst
.id
+ '\');"' +
1555 for (var month
= 0; month
< 12; month
++) {
1556 if ((!inMinYear
|| month
>= minDate
.getMonth()) &&
1557 (!inMaxYear
|| month
<= maxDate
.getMonth()))
1558 monthHtml
+= '<option value="' + month
+ '"' +
1559 (month
== drawMonth
? ' selected="selected"' : '') +
1560 '>' + monthNamesShort
[month
] + '</option>';
1562 monthHtml
+= '</select>';
1564 if (!showMonthAfterYear
)
1565 html
+= monthHtml
+ (secondary
|| !(changeMonth
&& changeYear
) ? ' ' : '');
1567 inst
.yearshtml
= '';
1568 if (secondary
|| !changeYear
)
1569 html
+= '<span class="ui-datepicker-year">' + drawYear
+ '</span>';
1571 // determine range of years to display
1572 var years
= this._get(inst
, 'yearRange').split(':');
1573 var thisYear
= new Date().getFullYear();
1574 var determineYear = function(value
) {
1575 var year
= (value
.match(/c[+-].*/) ? drawYear
+ parseInt(value
.substring(1), 10) :
1576 (value
.match(/[+-].*/) ? thisYear
+ parseInt(value
, 10) :
1577 parseInt(value
, 10)));
1578 return (isNaN(year
) ? thisYear
: year
);
1580 var year
= determineYear(years
[0]);
1581 var endYear
= Math
.max(year
, determineYear(years
[1] || ''));
1582 year
= (minDate
? Math
.max(year
, minDate
.getFullYear()) : year
);
1583 endYear
= (maxDate
? Math
.min(endYear
, maxDate
.getFullYear()) : endYear
);
1584 inst
.yearshtml
+= '<select class="ui-datepicker-year" ' +
1585 'onchange="DP_jQuery_' + dpuuid
+ '.datepicker._selectMonthYear(\'#' + inst
.id
+ '\', this, \'Y\');" ' +
1586 'onclick="DP_jQuery_' + dpuuid
+ '.datepicker._clickMonthYear(\'#' + inst
.id
+ '\');"' +
1588 for (; year
<= endYear
; year
++) {
1589 inst
.yearshtml
+= '<option value="' + year
+ '"' +
1590 (year
== drawYear
? ' selected="selected"' : '') +
1591 '>' + year
+ '</option>';
1593 inst
.yearshtml
+= '</select>';
1594 //when showing there is no need for later update
1595 if( ! $.browser
.mozilla
){
1596 html
+= inst
.yearshtml
;
1597 inst
.yearshtml
= null;
1599 // will be replaced later with inst.yearshtml
1600 html
+= '<select class="ui-datepicker-year"><option value="' + drawYear
+ '" selected="selected">' + drawYear
+ '</option></select>';
1603 html
+= this._get(inst
, 'yearSuffix');
1604 if (showMonthAfterYear
)
1605 html
+= (secondary
|| !(changeMonth
&& changeYear
) ? ' ' : '') + monthHtml
;
1606 html
+= '</div>'; // Close datepicker_header
1610 /* Adjust one of the date sub-fields. */
1611 _adjustInstDate: function(inst
, offset
, period
) {
1612 var year
= inst
.drawYear
+ (period
== 'Y' ? offset
: 0);
1613 var month
= inst
.drawMonth
+ (period
== 'M' ? offset
: 0);
1614 var day
= Math
.min(inst
.selectedDay
, this._getDaysInMonth(year
, month
)) +
1615 (period
== 'D' ? offset
: 0);
1616 var date
= this._restrictMinMax(inst
,
1617 this._daylightSavingAdjust(new Date(year
, month
, day
)));
1618 inst
.selectedDay
= date
.getDate();
1619 inst
.drawMonth
= inst
.selectedMonth
= date
.getMonth();
1620 inst
.drawYear
= inst
.selectedYear
= date
.getFullYear();
1621 if (period
== 'M' || period
== 'Y')
1622 this._notifyChange(inst
);
1625 /* Ensure a date is within any min/max bounds. */
1626 _restrictMinMax: function(inst, date) {
1627 var minDate = this._getMinMaxDate(inst, 'min');
1628 var maxDate = this._getMinMaxDate(inst, 'max');
1629 var newDate = (minDate && date < minDate ? minDate : date);
1630 newDate = (maxDate && newDate > maxDate ? maxDate : newDate);
1634 /* Notify change of month/year. */
1635 _notifyChange: function(inst) {
1636 var onChange = this._get(inst, 'onChangeMonthYear');
1638 onChange.apply((inst.input ? inst.input[0] : null),
1639 [inst.selectedYear, inst.selectedMonth + 1, inst]);
1642 /* Determine the number of months to show. */
1643 _getNumberOfMonths: function(inst
) {
1644 var numMonths
= this._get(inst
, 'numberOfMonths');
1645 return (numMonths
== null ? [1, 1] : (typeof numMonths
== 'number' ? [1, numMonths
] : numMonths
));
1648 /* Determine the current maximum date - ensure no time components are set. */
1649 _getMinMaxDate: function(inst
, minMax
) {
1650 return this._determineDate(inst
, this._get(inst
, minMax
+ 'Date'), null);
1653 /* Find the number of days in a given month. */
1654 _getDaysInMonth: function(year
, month
) {
1655 return 32 - new Date(year
, month
, 32).getDate();
1658 /* Find the day of the week of the first of a month. */
1659 _getFirstDayOfMonth: function(year
, month
) {
1660 return new Date(year
, month
, 1).getDay();
1663 /* Determines if we should allow a "next/prev" month display change. */
1664 _canAdjustMonth: function(inst, offset, curYear, curMonth) {
1665 var numMonths = this._getNumberOfMonths(inst);
1666 var date = this._daylightSavingAdjust(new Date(curYear,
1667 curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
1669 date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
1670 return this._isInRange(inst, date);
1673 /* Is the given date in the accepted range? */
1674 _isInRange: function(inst
, date
) {
1675 var minDate
= this._getMinMaxDate(inst
, 'min');
1676 var maxDate
= this._getMinMaxDate(inst
, 'max');
1677 return ((!minDate
|| date
.getTime() >= minDate
.getTime()) &&
1678 (!maxDate
|| date
.getTime() <= maxDate
.getTime()));
1681 /* Provide the configuration settings for formatting/parsing. */
1682 _getFormatConfig: function(inst) {
1683 var shortYearCutoff = this._get(inst, 'shortYearCutoff');
1684 shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
1685 new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
1686 return {shortYearCutoff: shortYearCutoff,
1687 dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
1688 monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
1691 /* Format the given date for display. */
1692 _formatDate: function(inst
, day
, month
, year
) {
1694 inst
.currentDay
= inst
.selectedDay
;
1695 inst
.currentMonth
= inst
.selectedMonth
;
1696 inst
.currentYear
= inst
.selectedYear
;
1698 var date
= (day
? (typeof day
== 'object' ? day
:
1699 this._daylightSavingAdjust(new Date(year
, month
, day
))) :
1700 this._daylightSavingAdjust(new Date(inst
.currentYear
, inst
.currentMonth
, inst
.currentDay
)));
1701 return this.formatDate(this._get(inst
, 'dateFormat'), date
, this._getFormatConfig(inst
));
1705 /* jQuery extend now ignores nulls! */
1706 function extendRemove(target
, props
) {
1707 $.extend(target
, props
);
1708 for (var name
in props
)
1709 if (props
[name
] == null || props
[name
] == undefined)
1710 target
[name
] = props
[name
];
1714 /* Determine whether an object is an array. */
1715 function isArray(a
) {
1716 return (a
&& (($.browser
.safari
&& typeof a
== 'object' && a
.length
) ||
1717 (a
.constructor && a
.constructor.toString().match(/\Array\(\)/))));
1720 /* Invoke the datepicker functionality.
1721 @param options string - a command, optionally followed by additional parameters or
1722 Object - settings for attaching new datepicker functionality
1723 @return jQuery object */
1724 $.fn
.datepicker = function(options
){
1726 /* Initialise the date picker. */
1727 if (!$.datepicker
.initialized
) {
1728 $(document
).mousedown($.datepicker
._checkExternalClick
).
1729 find('body').append($.datepicker
.dpDiv
);
1730 $.datepicker
.initialized
= true;
1733 var otherArgs
= Array
.prototype.slice
.call(arguments
, 1);
1734 if (typeof options
== 'string' && (options
== 'isDisabled' || options
== 'getDate' || options
== 'widget'))
1735 return $.datepicker
['_' + options
+ 'Datepicker'].
1736 apply($.datepicker
, [this[0]].concat(otherArgs
));
1737 if (options
== 'option' && arguments
.length
== 2 && typeof arguments
[1] == 'string')
1738 return $.datepicker
['_' + options
+ 'Datepicker'].
1739 apply($.datepicker
, [this[0]].concat(otherArgs
));
1740 return this.each(function() {
1741 typeof options
== 'string' ?
1742 $.datepicker
['_' + options
+ 'Datepicker'].
1743 apply($.datepicker
, [this].concat(otherArgs
)) :
1744 $.datepicker
._attachDatepicker(this, options
);
1748 $.datepicker
= new Datepicker(); // singleton instance
1749 $.datepicker
.initialized
= false;
1750 $.datepicker
.uuid
= new Date().getTime();
1751 $.datepicker
.version
= "1.8.7";
1753 // Workaround for #4055
1754 // Add another global to avoid noConflict issues with inline event handlers
1755 window
['DP_jQuery_' + dpuuid
] = $;