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