Changeset 447
- Timestamp:
- 07/11/08 03:55:16 (20 months ago)
- Files:
-
- 1 modified
-
trunk/ui/ui.datepicker.js (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ui/ui.datepicker.js
r423 r447 307 307 _enableDatepicker: function(target) { 308 308 target.disabled = false; 309 $(target).siblings('button.' + this._triggerClass).each(function() { this.disabled = false; }).end(). 309 $(target).siblings('button.' + this._triggerClass). 310 each(function() { this.disabled = false; }).end(). 310 311 siblings('img.' + this._triggerClass).css({opacity: '1.0', cursor: ''}); 311 312 this._disabledInputs = $.map(this._disabledInputs, … … 317 318 _disableDatepicker: function(target) { 318 319 target.disabled = true; 319 $(target).siblings('button.' + this._triggerClass).each(function() { this.disabled = true; }).end(). 320 $(target).siblings('button.' + this._triggerClass). 321 each(function() { this.disabled = true; }).end(). 320 322 siblings('img.' + this._triggerClass).css({opacity: '0.5', cursor: 'default'}); 321 323 this._disabledInputs = $.map(this._disabledInputs, … … 498 500 var dims = {width: inst.dpDiv.width() + 4, 499 501 height: inst.dpDiv.height() + 4}; 500 inst.dpDiv.empty().append(this._generate Datepicker(inst)).502 inst.dpDiv.empty().append(this._generateHTML(inst)). 501 503 find('iframe.ui-datepicker-cover'). 502 504 css({width: dims.width, height: dims.height}); … … 819 821 var month = -1; 820 822 var day = -1; 823 var doy = -1; 821 824 var literal = false; 822 825 // Check whether a format character is doubled … … 830 833 var getNumber = function(match) { 831 834 lookAhead(match); 832 var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : 2));835 var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2))); 833 836 var size = origSize; 834 837 var num = 0; … … 880 883 getName('D', dayNamesShort, dayNames); 881 884 break; 885 case 'o': 886 doy = getNumber('o'); 887 break; 882 888 case 'm': 883 889 month = getNumber('m'); … … 908 914 year += new Date().getFullYear() - new Date().getFullYear() % 100 + 909 915 (year <= shortYearCutoff ? 0 : -100); 916 if (doy > -1) { 917 month = 1; 918 day = doy; 919 do { 920 var dim = this._getDaysInMonth(year, month - 1); 921 if (day <= dim) 922 break; 923 month++; 924 day -= dim; 925 } while (true); 926 } 910 927 var date = new Date(year, month - 1, day); 911 928 if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) … … 931 948 d - day of month (no leading zero) 932 949 dd - day of month (two digit) 950 o - day of year (no leading zeros) 951 oo - day of year (three digit) 933 952 D - day name short 934 953 DD - day name long … … 966 985 }; 967 986 // Format a number, with leading zero if necessary 968 var formatNumber = function(match, value) { 969 return (lookAhead(match) && value < 10 ? '0' : '') + value; 987 var formatNumber = function(match, value, len) { 988 var num = '' + value; 989 if (lookAhead(match)) 990 while (num.length < len) 991 num = '0' + num; 992 return num; 970 993 }; 971 994 // Format a name, short or long as requested … … 985 1008 switch (format.charAt(iFormat)) { 986 1009 case 'd': 987 output += formatNumber('d', date.getDate() );1010 output += formatNumber('d', date.getDate(), 2); 988 1011 break; 989 1012 case 'D': 990 1013 output += formatName('D', date.getDay(), dayNamesShort, dayNames); 991 1014 break; 1015 case 'o': 1016 var doy = date.getDate(); 1017 for (var m = date.getMonth() - 1; m >= 0; m--) 1018 doy += this._getDaysInMonth(date.getFullYear(), m); 1019 output += formatNumber('o', doy, 3); 1020 break; 992 1021 case 'm': 993 output += formatNumber('m', date.getMonth() + 1 );1022 output += formatNumber('m', date.getMonth() + 1, 2); 994 1023 break; 995 1024 case 'M': … … 1167 1196 1168 1197 /* Generate the HTML for the current state of the date picker. */ 1169 _generate Datepicker: function(inst) {1198 _generateHTML: function(inst) { 1170 1199 var today = new Date(); 1171 1200 today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time 1172 1201 var showStatus = this._get(inst, 'showStatus'); 1202 var initStatus = this._get(inst, 'initStatus') || ' '; 1173 1203 var isRTL = this._get(inst, 'isRTL'); 1174 1204 // build the date picker HTML 1175 1205 var clear = (this._get(inst, 'mandatory') ? '' : 1176 1206 '<div class="ui-datepicker-clear"><a onclick="jQuery.datepicker._clearDate(\'#' + inst.id + '\');"' + 1177 (showStatus ? this._addStatus(inst, this._get(inst, 'clearStatus') || ' ') : '') + '>' +1207 this._addStatus(showStatus, inst.id, this._get(inst, 'clearStatus'), initStatus) + '>' + 1178 1208 this._get(inst, 'clearText') + '</a></div>'); 1179 1209 var controls = '<div class="ui-datepicker-control">' + (isRTL ? '' : clear) + 1180 1210 '<div class="ui-datepicker-close"><a onclick="jQuery.datepicker._hideDatepicker();"' + 1181 (showStatus ? this._addStatus(inst, this._get(inst, 'closeStatus') || ' ') : '') + '>' +1211 this._addStatus(showStatus, inst.id, this._get(inst, 'closeStatus'), initStatus) + '>' + 1182 1212 this._get(inst, 'closeText') + '</a></div>' + (isRTL ? clear : '') + '</div>'; 1183 1213 var prompt = this._get(inst, 'prompt'); … … 1212 1242 var prev = '<div class="ui-datepicker-prev">' + (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ? 1213 1243 '<a onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' + 1214 (showStatus ? this._addStatus(inst, this._get(inst, 'prevStatus') || ' ') : '') + '>' + prevText + '</a>' :1244 this._addStatus(showStatus, inst.id, this._get(inst, 'prevStatus'), initStatus) + '>' + prevText + '</a>' : 1215 1245 (hideIfNoPrevNext ? '' : '<label>' + prevText + '</label>')) + '</div>'; 1216 1246 var nextText = this._get(inst, 'nextText'); … … 1219 1249 var next = '<div class="ui-datepicker-next">' + (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ? 1220 1250 '<a onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' + 1221 (showStatus ? this._addStatus(inst, this._get(inst, 'nextStatus') || ' ') : '') + '>' + nextText + '</a>' :1251 this._addStatus(showStatus, inst.id, this._get(inst, 'nextStatus'), initStatus) + '>' + nextText + '</a>' : 1222 1252 (hideIfNoPrevNext ? '' : '<label>' + nextText + '</label>')) + '</div>'; 1223 1253 var currentText = this._get(inst, 'currentText'); 1224 currentText = (!navigationAsDateFormat ? currentText: this.formatDate( 1225 currentText, today, this._getFormatConfig(inst))); 1254 var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today); 1255 currentText = (!navigationAsDateFormat ? currentText : 1256 this.formatDate(currentText, gotoDate, this._getFormatConfig(inst))); 1226 1257 var html = (prompt ? '<div class="' + this._promptClass + '">' + prompt + '</div>' : '') + 1227 1258 (closeAtTop && !inst.inline ? controls : '') + 1228 1259 '<div class="ui-datepicker-links">' + (isRTL ? next : prev) + 1229 (this._isInRange(inst, (this._get(inst, 'gotoCurrent') && inst.currentDay ? 1230 currentDate : today)) ? '<div class="ui-datepicker-current">' + 1260 (this._isInRange(inst, gotoDate) ? '<div class="ui-datepicker-current">' + 1231 1261 '<a onclick="jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' + 1232 (showStatus ? this._addStatus(inst, this._get(inst, 'currentStatus') || ' ') : '') + '>' +1262 this._addStatus(showStatus, inst.id, this._get(inst, 'currentStatus'), initStatus) + '>' + 1233 1263 currentText + '</a></div>' : '') + (isRTL ? prev : next) + '</div>'; 1234 1264 var firstDay = this._get(inst, 'firstDay'); … … 1243 1273 var showWeeks = this._get(inst, 'showWeeks'); 1244 1274 var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week; 1245 var status = (showStatus ? this._get(inst, 'dayStatus') || ' ' : ''); 1275 var weekStatus = this._get(inst, 'weekStatus'); 1276 var status = (showStatus ? this._get(inst, 'dayStatus') || initStatus : ''); 1246 1277 var dateStatus = this._get(inst, 'statusForDate') || this.dateStatus; 1247 1278 var endDate = inst.endDay ? new Date(inst.endYear, inst.endMonth, inst.endDay) : currentDate; … … 1251 1282 html += '<div class="ui-datepicker-one-month' + (col == 0 ? ' ui-datepicker-new-row' : '') + '">' + 1252 1283 this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate, 1253 selectedDate, row > 0 || col > 0, showStatus, monthNames) + // draw month headers1284 selectedDate, row > 0 || col > 0, showStatus, initStatus, monthNames) + // draw month headers 1254 1285 '<table class="ui-datepicker" cellpadding="0" cellspacing="0"><thead>' + 1255 1286 '<tr class="ui-datepicker-title-row">' + 1256 (showWeeks ? '<td>' + this._get(inst, 'weekHeader') + '</td>' : ''); 1287 (showWeeks ? '<td' + this._addStatus(showStatus, inst.id, weekStatus, initStatus) + '>' + 1288 this._get(inst, 'weekHeader') + '</td>' : ''); 1257 1289 for (var dow = 0; dow < 7; dow++) { // days of the week 1258 1290 var day = (dow + firstDay) % 7; … … 1262 1294 (!changeFirstDay ? '<span' : 1263 1295 '<a onclick="jQuery.datepicker._changeFirstDay(\'#' + inst.id + '\', ' + day + ');"') + 1264 (showStatus ? this._addStatus(inst, dayStatus) : '') + ' title="' + dayNames[day] + '">' +1296 this._addStatus(showStatus, inst.id, dayStatus, initStatus) + ' title="' + dayNames[day] + '">' + 1265 1297 dayNamesMin[day] + (changeFirstDay ? '</a>' : '</span>') + '</td>'; 1266 1298 } … … 1274 1306 for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows 1275 1307 html += '<tr class="ui-datepicker-days-row">' + 1276 (showWeeks ? '<td class="ui-datepicker-week-col">' + calculateWeek(printDate) + '</td>' : ''); 1308 (showWeeks ? '<td class="ui-datepicker-week-col"' + 1309 this._addStatus(showStatus, inst.id, weekStatus, initStatus) + '>' + 1310 calculateWeek(printDate) + '</td>' : ''); 1277 1311 for (var dow = 0; dow < 7; dow++) { // create date picker days 1278 1312 var daySettings = (beforeShowDay ? … … 1298 1332 (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + 1299 1333 inst.id + '\').html(\'' + (dateStatus.apply((inst.input ? inst.input[0] : null), 1300 [printDate, inst]) || ' ') +'\');') + '"' +1334 [printDate, inst]) || initStatus) +'\');') + '"' + 1301 1335 ' onmouseout="jQuery(this).removeClass(\'ui-datepicker-days-cell-over\')' + // unhighlight selection 1302 1336 (highlightWeek ? '.parent().removeClass(\'ui-datepicker-week-over\')' : '') + ';' + // unhighlight selection week 1303 1337 (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + 1304 inst.id + '\').html(\'  \');') + '" onclick="jQuery.datepicker._selectDay(\'#' +1338 inst.id + '\').html(\'' + initStatus + '\');') + '" onclick="jQuery.datepicker._selectDay(\'#' + 1305 1339 inst.id + '\',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions 1306 1340 (otherMonth ? (showOtherMonths ? printDate.getDate() : ' ') : // display for other months … … 1318 1352 } 1319 1353 html += (showStatus ? '<div style="clear: both;"></div><div id="ui-datepicker-status-' + inst.id + 1320 '" class="ui-datepicker-status">' + (this._get(inst, 'initStatus') || ' ')+ '</div>' : '') +1354 '" class="ui-datepicker-status">' + initStatus + '</div>' : '') + 1321 1355 (!closeAtTop && !inst.inline ? controls : '') + 1322 1356 '<div style="clear: both;"></div>' + … … 1328 1362 /* Generate the month and year header. */ 1329 1363 _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, 1330 selectedDate, secondary, showStatus, monthNames) {1364 selectedDate, secondary, showStatus, initStatus, monthNames) { 1331 1365 minDate = (inst.rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate); 1332 1366 var html = '<div class="ui-datepicker-header">'; … … 1340 1374 'onchange="jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' + 1341 1375 'onclick="jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' + 1342 (showStatus ? this._addStatus(inst, this._get(inst, 'monthStatus') || ' ') : '') + '>';1376 this._addStatus(showStatus, inst.id, this._get(inst, 'monthStatus'), initStatus) + '>'; 1343 1377 for (var month = 0; month < 12; month++) { 1344 1378 if ((!inMinYear || month >= minDate.getMonth()) && … … 1374 1408 'onchange="jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' + 1375 1409 'onclick="jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' + 1376 (showStatus ? this._addStatus(inst, this._get(inst, 'yearStatus') || ' ') : '') + '>';1410 this._addStatus(showStatus, inst.id, this._get(inst, 'yearStatus'), initStatus) + '>'; 1377 1411 for (; year <= endYear; year++) { 1378 1412 html += '<option value="' + year + '"' + … … 1387 1421 1388 1422 /* Provide code to set and clear the status panel. */ 1389 _addStatus: function(inst, text) { 1390 return ' onmouseover="jQuery(\'#ui-datepicker-status-' + inst.id + '\').html(\'' + text + '\');" ' + 1391 'onmouseout="jQuery(\'#ui-datepicker-status-' + inst.id + '\').html(\' \');"'; 1423 _addStatus: function(showStatus, id, text, initStatus) { 1424 return (showStatus ? ' onmouseover="jQuery(\'#ui-datepicker-status-' + id + 1425 '\').html(\'' + (text || initStatus) + '\');" ' + 1426 'onmouseout="jQuery(\'#ui-datepicker-status-' + id + 1427 '\').html(\'' + initStatus + '\');"' : ''); 1392 1428 }, 1393 1429