Changeset 447

Show
Ignore:
Timestamp:
07/11/08 03:55:16 (20 months ago)
Author:
kbwood.au
Message:

Add day-of-year to format and parse date routines
Correct status display

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ui/ui.datepicker.js

    r423 r447  
    307307        _enableDatepicker: function(target) { 
    308308                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(). 
    310311                        siblings('img.' + this._triggerClass).css({opacity: '1.0', cursor: ''}); 
    311312                this._disabledInputs = $.map(this._disabledInputs, 
     
    317318        _disableDatepicker: function(target) { 
    318319                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(). 
    320322                        siblings('img.' + this._triggerClass).css({opacity: '0.5', cursor: 'default'}); 
    321323                this._disabledInputs = $.map(this._disabledInputs, 
     
    498500                var dims = {width: inst.dpDiv.width() + 4, 
    499501                        height: inst.dpDiv.height() + 4}; 
    500                 inst.dpDiv.empty().append(this._generateDatepicker(inst)). 
     502                inst.dpDiv.empty().append(this._generateHTML(inst)). 
    501503                        find('iframe.ui-datepicker-cover'). 
    502504                        css({width: dims.width, height: dims.height}); 
     
    819821                var month = -1; 
    820822                var day = -1; 
     823                var doy = -1; 
    821824                var literal = false; 
    822825                // Check whether a format character is doubled 
     
    830833                var getNumber = function(match) { 
    831834                        lookAhead(match); 
    832                         var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : 2)); 
     835                        var origSize = (match == '@' ? 14 : (match == 'y' ? 4 : (match == 'o' ? 3 : 2))); 
    833836                        var size = origSize; 
    834837                        var num = 0; 
     
    880883                                                getName('D', dayNamesShort, dayNames); 
    881884                                                break; 
     885                                        case 'o': 
     886                                                doy = getNumber('o'); 
     887                                                break; 
    882888                                        case 'm':  
    883889                                                month = getNumber('m'); 
     
    908914                        year += new Date().getFullYear() - new Date().getFullYear() % 100 + 
    909915                                (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                } 
    910927                var date = new Date(year, month - 1, day); 
    911928                if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day) 
     
    931948           d  - day of month (no leading zero) 
    932949           dd - day of month (two digit) 
     950           o  - day of year (no leading zeros) 
     951           oo - day of year (three digit) 
    933952           D  - day name short 
    934953           DD - day name long 
     
    966985                }; 
    967986                // 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; 
    970993                }; 
    971994                // Format a name, short or long as requested 
     
    9851008                                        switch (format.charAt(iFormat)) { 
    9861009                                                case 'd': 
    987                                                         output += formatNumber('d', date.getDate());  
     1010                                                        output += formatNumber('d', date.getDate(), 2); 
    9881011                                                        break; 
    9891012                                                case 'D':  
    9901013                                                        output += formatName('D', date.getDay(), dayNamesShort, dayNames); 
    9911014                                                        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; 
    9921021                                                case 'm':  
    993                                                         output += formatNumber('m', date.getMonth() + 1);  
     1022                                                        output += formatNumber('m', date.getMonth() + 1, 2); 
    9941023                                                        break; 
    9951024                                                case 'M': 
     
    11671196 
    11681197        /* Generate the HTML for the current state of the date picker. */ 
    1169         _generateDatepicker: function(inst) { 
     1198        _generateHTML: function(inst) { 
    11701199                var today = new Date(); 
    11711200                today = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // clear time 
    11721201                var showStatus = this._get(inst, 'showStatus'); 
     1202                var initStatus = this._get(inst, 'initStatus') || '&#xa0;'; 
    11731203                var isRTL = this._get(inst, 'isRTL'); 
    11741204                // build the date picker HTML 
    11751205                var clear = (this._get(inst, 'mandatory') ? '' : 
    11761206                        '<div class="ui-datepicker-clear"><a onclick="jQuery.datepicker._clearDate(\'#' + inst.id + '\');"' + 
    1177                         (showStatus ? this._addStatus(inst, this._get(inst, 'clearStatus') || '&#xa0;') : '') + '>' + 
     1207                        this._addStatus(showStatus, inst.id, this._get(inst, 'clearStatus'), initStatus) + '>' + 
    11781208                        this._get(inst, 'clearText') + '</a></div>'); 
    11791209                var controls = '<div class="ui-datepicker-control">' + (isRTL ? '' : clear) + 
    11801210                        '<div class="ui-datepicker-close"><a onclick="jQuery.datepicker._hideDatepicker();"' + 
    1181                         (showStatus ? this._addStatus(inst, this._get(inst, 'closeStatus') || '&#xa0;') : '') + '>' + 
     1211                        this._addStatus(showStatus, inst.id, this._get(inst, 'closeStatus'), initStatus) + '>' + 
    11821212                        this._get(inst, 'closeText') + '</a></div>' + (isRTL ? clear : '')  + '</div>'; 
    11831213                var prompt = this._get(inst, 'prompt'); 
     
    12121242                var prev = '<div class="ui-datepicker-prev">' + (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?  
    12131243                        '<a onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', -' + stepMonths + ', \'M\');"' + 
    1214                         (showStatus ? this._addStatus(inst, this._get(inst, 'prevStatus') || '&#xa0;') : '') + '>' + prevText + '</a>' : 
     1244                        this._addStatus(showStatus, inst.id, this._get(inst, 'prevStatus'), initStatus) + '>' + prevText + '</a>' : 
    12151245                        (hideIfNoPrevNext ? '' : '<label>' + prevText + '</label>')) + '</div>'; 
    12161246                var nextText = this._get(inst, 'nextText'); 
     
    12191249                var next = '<div class="ui-datepicker-next">' + (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ? 
    12201250                        '<a onclick="jQuery.datepicker._adjustDate(\'#' + inst.id + '\', +' + stepMonths + ', \'M\');"' + 
    1221                         (showStatus ? this._addStatus(inst, this._get(inst, 'nextStatus') || '&#xa0;') : '') + '>' + nextText + '</a>' : 
     1251                        this._addStatus(showStatus, inst.id, this._get(inst, 'nextStatus'), initStatus) + '>' + nextText + '</a>' : 
    12221252                        (hideIfNoPrevNext ? '' : '<label>' + nextText + '</label>')) + '</div>'; 
    12231253                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))); 
    12261257                var html = (prompt ? '<div class="' + this._promptClass + '">' + prompt + '</div>' : '') + 
    12271258                        (closeAtTop && !inst.inline ? controls : '') + 
    12281259                        '<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">' + 
    12311261                        '<a onclick="jQuery.datepicker._gotoToday(\'#' + inst.id + '\');"' + 
    1232                         (showStatus ? this._addStatus(inst, this._get(inst, 'currentStatus') || '&#xa0;') : '') + '>' + 
     1262                        this._addStatus(showStatus, inst.id, this._get(inst, 'currentStatus'), initStatus) + '>' + 
    12331263                        currentText + '</a></div>' : '') + (isRTL ? prev : next) + '</div>'; 
    12341264                var firstDay = this._get(inst, 'firstDay'); 
     
    12431273                var showWeeks = this._get(inst, 'showWeeks'); 
    12441274                var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week; 
    1245                 var status = (showStatus ? this._get(inst, 'dayStatus') || '&#xa0;' : ''); 
     1275                var weekStatus = this._get(inst, 'weekStatus'); 
     1276                var status = (showStatus ? this._get(inst, 'dayStatus') || initStatus : ''); 
    12461277                var dateStatus = this._get(inst, 'statusForDate') || this.dateStatus; 
    12471278                var endDate = inst.endDay ? new Date(inst.endYear, inst.endMonth, inst.endDay) : currentDate; 
     
    12511282                                html += '<div class="ui-datepicker-one-month' + (col == 0 ? ' ui-datepicker-new-row' : '') + '">' + 
    12521283                                        this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate, 
    1253                                         selectedDate, row > 0 || col > 0, showStatus, monthNames) + // draw month headers 
     1284                                        selectedDate, row > 0 || col > 0, showStatus, initStatus, monthNames) + // draw month headers 
    12541285                                        '<table class="ui-datepicker" cellpadding="0" cellspacing="0"><thead>' +  
    12551286                                        '<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>' : ''); 
    12571289                                for (var dow = 0; dow < 7; dow++) { // days of the week 
    12581290                                        var day = (dow + firstDay) % 7; 
     
    12621294                                                (!changeFirstDay ? '<span' : 
    12631295                                                '<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] + '">' + 
    12651297                                                dayNamesMin[day] + (changeFirstDay ? '</a>' : '</span>') + '</td>'; 
    12661298                                } 
     
    12741306                                for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows 
    12751307                                        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>' : ''); 
    12771311                                        for (var dow = 0; dow < 7; dow++) { // create date picker days 
    12781312                                                var daySettings = (beforeShowDay ? 
     
    12981332                                                        (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + 
    12991333                                                        inst.id + '\').html(\'' + (dateStatus.apply((inst.input ? inst.input[0] : null), 
    1300                                                         [printDate, inst]) || '&#xa0;') +'\');') + '"' + 
     1334                                                        [printDate, inst]) || initStatus) +'\');') + '"' + 
    13011335                                                        ' onmouseout="jQuery(this).removeClass(\'ui-datepicker-days-cell-over\')' + // unhighlight selection 
    13021336                                                        (highlightWeek ? '.parent().removeClass(\'ui-datepicker-week-over\')' : '') + ';' + // unhighlight selection week 
    13031337                                                        (!showStatus || (otherMonth && !showOtherMonths) ? '' : 'jQuery(\'#ui-datepicker-status-' + 
    1304                                                         inst.id + '\').html(\'&#xa0;\');') + '" onclick="jQuery.datepicker._selectDay(\'#' + 
     1338                                                        inst.id + '\').html(\'' + initStatus + '\');') + '" onclick="jQuery.datepicker._selectDay(\'#' + 
    13051339                                                        inst.id + '\',' + drawMonth + ',' + drawYear + ', this);"') + '>' + // actions 
    13061340                                                        (otherMonth ? (showOtherMonths ? printDate.getDate() : '&#xa0;') : // display for other months 
     
    13181352                        } 
    13191353                html += (showStatus ? '<div style="clear: both;"></div><div id="ui-datepicker-status-' + inst.id +  
    1320                         '" class="ui-datepicker-status">' + (this._get(inst, 'initStatus') || '&#xa0;') + '</div>' : '') + 
     1354                        '" class="ui-datepicker-status">' + initStatus + '</div>' : '') + 
    13211355                        (!closeAtTop && !inst.inline ? controls : '') + 
    13221356                        '<div style="clear: both;"></div>' +  
     
    13281362        /* Generate the month and year header. */ 
    13291363        _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate, 
    1330                         selectedDate, secondary, showStatus, monthNames) { 
     1364                        selectedDate, secondary, showStatus, initStatus, monthNames) { 
    13311365                minDate = (inst.rangeStart && minDate && selectedDate < minDate ? selectedDate : minDate); 
    13321366                var html = '<div class="ui-datepicker-header">'; 
     
    13401374                                'onchange="jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' + 
    13411375                                'onclick="jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' + 
    1342                                 (showStatus ? this._addStatus(inst, this._get(inst, 'monthStatus') || '&#xa0;') : '') + '>'; 
     1376                                this._addStatus(showStatus, inst.id, this._get(inst, 'monthStatus'), initStatus) + '>'; 
    13431377                        for (var month = 0; month < 12; month++) { 
    13441378                                if ((!inMinYear || month >= minDate.getMonth()) && 
     
    13741408                                'onchange="jQuery.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' + 
    13751409                                'onclick="jQuery.datepicker._clickMonthYear(\'#' + inst.id + '\');"' + 
    1376                                 (showStatus ? this._addStatus(inst, this._get(inst, 'yearStatus') || '&#xa0;') : '') + '>'; 
     1410                                this._addStatus(showStatus, inst.id, this._get(inst, 'yearStatus'), initStatus) + '>'; 
    13771411                        for (; year <= endYear; year++) { 
    13781412                                html += '<option value="' + year + '"' + 
     
    13871421 
    13881422        /* 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(\'&#xa0;\');"'; 
     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 + '\');"' : ''); 
    13921428        }, 
    13931429