diff --git a/ui/ui.datepicker.js b/ui/ui.datepicker.js index 2ddca2889..1fdae67c9 100644 --- a/ui/ui.datepicker.js +++ b/ui/ui.datepicker.js @@ -306,7 +306,8 @@ $.extend(Datepicker.prototype, { @param target element - the target input field or division or span */ _enableDatepicker: function(target) { target.disabled = false; - $(target).siblings('button.' + this._triggerClass).each(function() { this.disabled = false; }).end(). + $(target).siblings('button.' + this._triggerClass). + each(function() { this.disabled = false; }).end(). siblings('img.' + this._triggerClass).css({opacity: '1.0', cursor: ''}); this._disabledInputs = $.map(this._disabledInputs, function(value) { return (value == target ? null : value); }); // delete entry @@ -316,7 +317,8 @@ $.extend(Datepicker.prototype, { @param target element - the target input field or division or span */ _disableDatepicker: function(target) { target.disabled = true; - $(target).siblings('button.' + this._triggerClass).each(function() { this.disabled = true; }).end(). + $(target).siblings('button.' + this._triggerClass). + each(function() { this.disabled = true; }).end(). siblings('img.' + this._triggerClass).css({opacity: '0.5', cursor: 'default'}); this._disabledInputs = $.map(this._disabledInputs, function(value) { return (value == target ? null : value); }); // delete entry @@ -497,7 +499,7 @@ $.extend(Datepicker.prototype, { _updateDatepicker: function(inst) { var dims = {width: inst.dpDiv.width() + 4, height: inst.dpDiv.height() + 4}; - inst.dpDiv.empty().append(this._generateDatepicker(inst)). + inst.dpDiv.empty().append(this._generateHTML(inst)). find('iframe.ui-datepicker-cover'). css({width: dims.width, height: dims.height}); var numMonths = this._getNumberOfMonths(inst); @@ -818,6 +820,7 @@ $.extend(Datepicker.prototype, { var year = -1; var month = -1; var day = -1; + var doy = -1; var literal = false; // Check whether a format character is doubled var lookAhead = function(match) { @@ -829,7 +832,7 @@ $.extend(Datepicker.prototype, { // Extract a number from the string value var getNumber = function(match) { lookAhead(match); - var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : 2)); + var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2))); var size = origSize; var num = 0; while (size > 0 && iValue < value.length && @@ -879,6 +882,9 @@ $.extend(Datepicker.prototype, { case 'D': getName('D', dayNamesShort, dayNames); break; + case 'o': + doy = getNumber('o'); + break; case 'm': month = getNumber('m'); break; @@ -907,6 +913,17 @@ $.extend(Datepicker.prototype, { if (year < 100) year += new Date().getFullYear() - new Date().getFullYear() % 100 + (year <= shortYearCutoff ? 0 : -100); + if (doy > -1) { + month = 1; + day = doy; + do { + var dim = this._getDaysInMonth(year, month - 1); + if (day <= dim) + break; + month++; + day -= dim; + } while (true); + } var date = new Date(year, month - 1, day); if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) throw 'Invalid date'; // E.g. 31/02/* @@ -930,6 +947,8 @@ $.extend(Datepicker.prototype, { The format can be combinations of the following: d - day of month (no leading zero) dd - day of month (two digit) + o - day of year (no leading zeros) + oo - day of year (three digit) D - day name short DD - day name long m - month of year (no leading zero) @@ -965,8 +984,12 @@ $.extend(Datepicker.prototype, { return matches; }; // Format a number, with leading zero if necessary - var formatNumber = function(match, value) { - return (lookAhead(match) && value < 10 ? '0' : '') + value; + var formatNumber = function(match, value, len) { + var num = '' + value; + if (lookAhead(match)) + while (num.length < len) + num = '0' + num; + return num; }; // Format a name, short or long as requested var formatName = function(match, value, shortNames, longNames) { @@ -984,13 +1007,19 @@ $.extend(Datepicker.prototype, { else switch (format.charAt(iFormat)) { case 'd': - output += formatNumber('d', date.getDate()); + output += formatNumber('d', date.getDate(), 2); break; case 'D': output += formatName('D', date.getDay(), dayNamesShort, dayNames); break; + case 'o': + var doy = date.getDate(); + for (var m = date.getMonth() - 1; m >= 0; m--) + doy += this._getDaysInMonth(date.getFullYear(), m); + output += formatNumber('o', doy, 3); + break; case 'm': - output += formatNumber('m', date.getMonth() + 1); + output += formatNumber('m', date.getMonth() + 1, 2); break; case 'M': output += formatName('M', date.getMonth(), monthNamesShort, monthNames); @@ -1166,19 +1195,20 @@ $.extend(Datepicker.prototype, { }, /* Generate the HTML for the current state of the date picker. */ - _generateDatepicker: function(inst) { + _generateHTML: function(inst) { var today = new Date(); today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time var showStatus = this._get(inst, 'showStatus'); + var initStatus = this._get(inst, 'initStatus') || ' '; var isRTL = this._get(inst, 'isRTL'); // build the date picker HTML var clear = (this._get(inst, 'mandatory') ? '' : '
'); var controls = '' + this._get(inst, 'weekHeader') + ' | ' : ''); + (showWeeks ? '' + + this._get(inst, 'weekHeader') + ' | ' : ''); for (var dow = 0; dow < 7; dow++) { // days of the week var day = (dow + firstDay) % 7; var dayStatus = (status.indexOf('DD') > -1 ? status.replace(/DD/, dayNames[day]) : @@ -1261,7 +1293,7 @@ $.extend(Datepicker.prototype, { html += '= 5 ? ' class="ui-datepicker-week-end-cell"' : '') + '>' + (!changeFirstDay ? '' + + this._addStatus(showStatus, inst.id, dayStatus, initStatus) + ' title="' + dayNames[day] + '">' + dayNamesMin[day] + (changeFirstDay ? '' : '') + ' | '; } html += '
' + calculateWeek(printDate) + ' | ' : ''); + (showWeeks ? '' + + calculateWeek(printDate) + ' | ' : ''); for (var dow = 0; dow < 7; dow++) { // create date picker days var daySettings = (beforeShowDay ? beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']); @@ -1297,11 +1331,11 @@ $.extend(Datepicker.prototype, { (highlightWeek ? '.parent().addClass(\'ui-datepicker-week-over\')' : '') + ';' + // highlight selection week (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + inst.id + '\').html(\'' + (dateStatus.apply((inst.input ? inst.input[0] : null), - [printDate, inst]) || ' ') +'\');') + '"' + + [printDate, inst]) || initStatus) +'\');') + '"' + ' onmouseout="jQuery(this).removeClass(\'ui-datepicker-days-cell-over\')' + // unhighlight selection (highlightWeek ? '.parent().removeClass(\'ui-datepicker-week-over\')' : '') + ';' + // unhighlight selection week (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + - inst.id + '\').html(\' \');') + '" onclick="jQuery.datepicker._selectDay(\'#' + + inst.id + '\').html(\'' + initStatus + '\');') + '" onclick="jQuery.datepicker._selectDay(\'#' + inst.id + '\',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions (otherMonth ? (showOtherMonths ? printDate.getDate() : ' ') : // display for other months (unselectable ? printDate.getDate() : '' + printDate.getDate() + '')) + ''; // display for this month @@ -1317,7 +1351,7 @@ $.extend(Datepicker.prototype, { html += '