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