From: Scott González Date: Mon, 4 Apr 2011 11:55:42 +0000 (-0400) Subject: Datepicker: Only generate yearshtml once. Fixes #7176 - Datepicker shows only single... X-Git-Tag: 1.8.12~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a8fc3da62885c2d7c692e24f8416e320886e1e7b;p=jquery-ui.git Datepicker: Only generate yearshtml once. Fixes #7176 - Datepicker shows only single year in year dropdown if numberOfMonths > 1. (cherry picked from commit 98c53d8432990f2c674e3a1274141b64a87d8ee9) --- diff --git a/ui/jquery.ui.datepicker.js b/ui/jquery.ui.datepicker.js index b07a5ee72..61c2b69b4 100644 --- a/ui/jquery.ui.datepicker.js +++ b/ui/jquery.ui.datepicker.js @@ -1575,40 +1575,42 @@ $.extend(Datepicker.prototype, { if (!showMonthAfterYear) html += monthHtml + (secondary || !(changeMonth && changeYear) ? ' ' : ''); // year selection - inst.yearshtml = ''; - if (secondary || !changeYear) - html += '' + drawYear + ''; - else { - // determine range of years to display - var years = this._get(inst, 'yearRange').split(':'); - var thisYear = new Date().getFullYear(); - var determineYear = function(value) { - var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) : - (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) : - parseInt(value, 10))); - return (isNaN(year) ? thisYear : year); - }; - var year = determineYear(years[0]); - var endYear = Math.max(year, determineYear(years[1] || '')); - year = (minDate ? Math.max(year, minDate.getFullYear()) : year); - endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear); - inst.yearshtml += ''; - //when showing there is no need for later update - if( ! $.browser.mozilla ){ - html += inst.yearshtml; - inst.yearshtml = null; - } else { - // will be replaced later with inst.yearshtml - html += ''; + if ( !inst.yearshtml ) { + inst.yearshtml = ''; + if (secondary || !changeYear) + html += '' + drawYear + ''; + else { + // determine range of years to display + var years = this._get(inst, 'yearRange').split(':'); + var thisYear = new Date().getFullYear(); + var determineYear = function(value) { + var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) : + (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) : + parseInt(value, 10))); + return (isNaN(year) ? thisYear : year); + }; + var year = determineYear(years[0]); + var endYear = Math.max(year, determineYear(years[1] || '')); + year = (minDate ? Math.max(year, minDate.getFullYear()) : year); + endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear); + inst.yearshtml += ''; + //when showing there is no need for later update + if( ! $.browser.mozilla ){ + html += inst.yearshtml; + inst.yearshtml = null; + } else { + // will be replaced later with inst.yearshtml + html += ''; + } } } html += this._get(inst, 'yearSuffix');