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') ? '' : '
' + + this._addStatus(showStatus, inst.id, this._get(inst, 'clearStatus'), initStatus) + '>' + this._get(inst, 'clearText') + '
'); var controls = '
' + (isRTL ? '' : clear) + '
' + + this._addStatus(showStatus, inst.id, this._get(inst, 'closeStatus'), initStatus) + '>' + this._get(inst, 'closeText') + '
' + (isRTL ? clear : '') + '
'; var prompt = this._get(inst, 'prompt'); var closeAtTop = this._get(inst, 'closeAtTop'); @@ -1211,25 +1241,25 @@ $.extend(Datepicker.prototype, { prevText, new Date(drawYear, drawMonth - stepMonths, 1), this._getFormatConfig(inst))); var prev = '
' + (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ? '' + prevText + '' : + this._addStatus(showStatus, inst.id, this._get(inst, 'prevStatus'), initStatus) + '>' + prevText + '' : (hideIfNoPrevNext ? '' : '')) + '
'; var nextText = this._get(inst, 'nextText'); nextText = (!navigationAsDateFormat ? nextText : this.formatDate( nextText, new Date(drawYear, drawMonth + stepMonths, 1), this._getFormatConfig(inst))); var next = '
' + (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ? '' + nextText + '' : + this._addStatus(showStatus, inst.id, this._get(inst, 'nextStatus'), initStatus) + '>' + nextText + '' : (hideIfNoPrevNext ? '' : '')) + '
'; var currentText = this._get(inst, 'currentText'); - currentText = (!navigationAsDateFormat ? currentText: this.formatDate( - currentText, today, this._getFormatConfig(inst))); + var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today); + currentText = (!navigationAsDateFormat ? currentText : + this.formatDate(currentText, gotoDate, this._getFormatConfig(inst))); var html = (prompt ? '
' + prompt + '
' : '') + (closeAtTop && !inst.inline ? controls : '') + '' : '') + (!closeAtTop && !inst.inline ? controls : '') + '
' + ($.browser.msie && parseInt($.browser.version) < 7 && !inst.inline ? @@ -1327,7 +1361,7 @@ $.extend(Datepicker.prototype, { /* Generate the month and year header. */ _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, - selectedDate, secondary, showStatus, monthNames) { + selectedDate, secondary, showStatus, initStatus, monthNames) { minDate = (inst.rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate); var html = '
'; // month selection @@ -1339,7 +1373,7 @@ $.extend(Datepicker.prototype, { html += ''; + this._addStatus(showStatus, inst.id, this._get(inst, 'yearStatus'), initStatus) + '>'; for (; year <= endYear; year++) { html += '