Make WordPress Core

Ticket #4641: jcalendar-r5798-a.patch

File jcalendar-r5798-a.patch, 25.8 KB (added by tellyworth, 19 years ago)
  • wp-includes/js/jquery/jcalendar.js

     
     1/**
     2 * jCalendar 0.5
     3 *
     4 * Some code based on jQuery Date Picker (http://kelvinluck.com/assets/jquery/datePicker/)
     5 *
     6 * Copyright (c) 2007 Theodore Serbinski (http://tedserbinski.com)
     7 * Dual licensed under the MIT (MIT-LICENSE.txt)
     8 * and GPL (GPL-LICENSE.txt) licenses.
     9 */
     10jQuery.jcalendar = function() {
     11        var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     12        var days = ['S', 'M', 'Tu', 'W', 'Th', 'F', 'S'];
     13        var navLinks = {p:'Prev', n:'Next', t:'Today'};
     14        var _firstDayOfWeek;
     15        var _firstDate;
     16        var _lastDate;
     17        var _selectedDate;
     18
     19        var _drawCalendar = function(dateIn, a, day, month, year) {
     20          var today = new Date();
     21          var d;
     22
     23                if (dateIn == undefined) {
     24                        // start from this month.
     25                        d = new Date(today.getFullYear(), today.getMonth(), 1);
     26                        year.val(today.getFullYear());
     27                        month.val(today.getMonth()+1);
     28                        day.val(today.getDate());
     29                }
     30                else {
     31                        // start from the passed in date
     32                        d = dateIn;
     33                  d.setDate(1);
     34                }
     35
     36                // check that date is within allowed limits
     37                if ((d.getMonth() < _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear()) || d.getFullYear() < _firstDate.getFullYear()) {
     38                        d = new Date(_firstDate.getFullYear(), _firstDate.getMonth(), 1);
     39                }
     40                else if ((d.getMonth() > _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear()) || d.getFullYear() > _lastDate.getFullYear()) {
     41                        d = new Date(_lastDate.getFullYear(), _lastDate.getMonth(), 1);
     42                }
     43
     44                var firstMonth = true;
     45                var firstDate = _firstDate.getDate();
     46
     47                // create prev and next links
     48                if (!(d.getMonth() == _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear())) {
     49                        // not in first display month so show a previous link
     50                        firstMonth = false;
     51                        var lastMonth = d.getMonth() == 0 ? new Date(d.getFullYear()-1, 11, 1) : new Date(d.getFullYear(), d.getMonth()-1, 1);
     52                        var prevLink = jQuery('<a href="" class="link-prev">&lsaquo; '+ navLinks.p +'</a>').click(function() {
     53                                jQuery.jcalendar.changeMonth(lastMonth, this, day, month, year);
     54                                return false;
     55                        });
     56                }
     57
     58                var finalMonth = true;
     59                var lastDate = _lastDate.getDate();
     60
     61                if (!(d.getMonth() == _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear())) {
     62                        // in the last month - no next link
     63                        finalMonth = false;
     64                        var nextMonth = new Date(d.getFullYear(), d.getMonth()+1, 1);
     65                        var nextLink = jQuery('<a href="" class="link-next">'+ navLinks.n +' &rsaquo;</a>').click(function() {
     66                                jQuery.jcalendar.changeMonth(nextMonth, this, day, month, year);
     67                                return false;
     68                        });
     69                }
     70
     71                var todayLink = jQuery('<a href="" class="link-today">'+ navLinks.t +'</a>').click(function() {
     72                        day.val(today.getDate());
     73                        jQuery.jcalendar.changeMonth(today, this, day, month, year);
     74                        return false;
     75                });
     76
     77    // update the year and month select boxes
     78        year.val(d.getFullYear());
     79        month.val(d.getMonth()+1);
     80
     81                var headRow = jQuery("<tr></tr>");
     82                for (var i=_firstDayOfWeek; i<_firstDayOfWeek+7; i++) {
     83                        var weekday = i%7;
     84                        var wordday = days[weekday];
     85                        headRow.append('<th scope="col" abbr="'+ wordday +'" title="'+ wordday +'" class="'+ (weekday == 0 || weekday == 6 ? 'weekend' : 'weekday') +'">'+ wordday +'</th>');
     86                }
     87                headRow = jQuery("<thead></thead>").append(headRow);
     88
     89                var tBody = jQuery("<tbody></tbody>");
     90                var lastDay = (new Date(d.getFullYear(), d.getMonth()+1, 0)).getDate();
     91                var curDay = _firstDayOfWeek - d.getDay();
     92                if (curDay > 0) curDay -= 7;
     93
     94                var todayDate = today.getDate();
     95                var thisMonth = d.getMonth() == today.getMonth() && d.getFullYear() == today.getFullYear();
     96
     97    // render calendar
     98                do {
     99                  var thisRow = jQuery("<tr></tr>");
     100                for (var i=0; i<7; i++) {
     101                        var weekday = (_firstDayOfWeek + i) % 7;
     102                        var atts = {'class':(weekday == 0 || weekday == 6 ? 'weekend ' : 'weekday ')};
     103
     104                        if (curDay < 0 || curDay >= lastDay) {
     105                                dayStr = ' ';
     106                        }
     107                        else if (firstMonth && curDay < firstDate-1) {
     108                                dayStr = curDay+1;
     109                                atts['class'] += 'inactive';
     110                        }
     111                        else if (finalMonth && curDay > lastDate-1) {
     112                                dayStr = curDay+1;
     113                                atts['class'] += 'inactive';
     114                        }
     115                        else {
     116                                d.setDate(curDay+1);
     117
     118                                // attach a click handler to every day to select it if clicked
     119                                // we use the rel attribute to keep track of the day that is being clicked
     120                                dayStr = jQuery('<a href="" rel="'+ d +'">'+ (curDay+1) +'</a>').click(function(e) {
     121            if (_selectedDate) {
     122               _selectedDate.removeClass('selected');
     123            }
     124                        _selectedDate = jQuery(this);
     125                        _selectedDate.addClass('selected');
     126            day.val(new Date(_selectedDate.attr('rel')).getDate());
     127                                        return false;
     128                                });
     129
     130                                // highlight the current selected day
     131                                if (day.val() == d.getDate()) {
     132                                  _selectedDate = dayStr;
     133                                  _selectedDate.addClass('selected');
     134                                }
     135                        }
     136
     137                        if (thisMonth && curDay+1 == todayDate) {
     138                                atts['class'] += 'today';
     139                        }
     140                        thisRow.append(jQuery("<td></td>").attr(atts).append(dayStr));
     141                        curDay++;
     142      }
     143
     144                        tBody.append(thisRow);
     145                } while (curDay < lastDay);
     146
     147                jQuery('div.jcalendar').html('<table cellspacing="1"></table><div class="jcalendar-links"></div>');
     148                jQuery('div.jcalendar table').append(headRow, tBody);
     149                jQuery('div.jcalendar > div.jcalendar-links').append(prevLink, todayLink, nextLink);
     150        };
     151
     152        return {
     153                show: function(a, day, month, year) {
     154                        _firstDate = a._startDate;
     155                        _lastDate = a._endDate;
     156                        _firstDayOfWeek = a._firstDayOfWeek;
     157
     158                        // pass in the selected form date if one was set
     159                        var selected;
     160                        if (year.val() > 0 && month.val() > 0 && day.val() > 0) {
     161                          selected = new Date(year.val(), month.val()-1, day.val());
     162                        }
     163                        else {
     164                          selected = null;
     165                        }
     166                        _drawCalendar(selected, a, day, month, year);
     167                },
     168                changeMonth: function(d, e, day, month, year) {
     169                        _drawCalendar(d, e, day, month, year);
     170                },
     171                /**
     172                * Function: setLanguageStrings
     173                *
     174                * Allows you to localise the calendar by passing in relevant text for the english strings in the plugin.
     175                *
     176                * Arguments:
     177                * days          -       Array, e.g. ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
     178                * months        -       Array, e.g. ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     179                * navLinks      -       Object, e.g. {p:'Prev', n:'Next', c:'Close', b:'Choose date'}
     180                **/
     181                setLanguageStrings: function(aDays, aMonths, aNavLinks) {
     182                        days = aDays;
     183                        months = aMonths;
     184                        navLinks = aNavLinks;
     185                },
     186                /**
     187                * Function: setDateWindow
     188                *
     189                * Used internally to set the start and end dates for a given date select
     190                *
     191                * Arguments:
     192                * i                     -       The id of the INPUT element this date window is for
     193                * w                     -       The date window - an object containing startDate and endDate properties
     194                *                               e.g. {startDate:'24-11-1981', endDate:'25-12-2012}
     195                **/
     196                setDateWindow: function(i, w, year) {
     197                        if (w == undefined) w = {};
     198                        if (w.startDate == undefined) {
     199                                // set the minimum browseable date equal to January of the min year in the select box
     200                                // don't get the first option because that is an empty year
     201
     202                                // note we can't do this: year.find('option:eq(1)').val()
     203                                // it doesn't work in 1.0 since find() is destructive
     204                                // so we copy the object to a new var
     205                                i._startDate = new Date(jQuery(year).find('option:eq(1)').val(), 0, 1);
     206                        }
     207                        else {
     208                        dateParts = w.startDate.split('-');
     209                        i._startDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));
     210                        }
     211                        if (w.endDate == undefined) {
     212                          // set the maximum browseable date equal to December of the max year in the select box
     213
     214                          // note we can't do this: year.find('option:last').val()
     215                                // it doesn't work in 1.0 since find() is destructive
     216                                // so we copy the object to a new var
     217                                i._endDate = new Date(jQuery(year).find('option:last').val(), 11, 1);
     218                        }
     219                        else {
     220                        dateParts = w.endDate.split('-');
     221                        i._endDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));
     222                        }
     223                        i._firstDayOfWeek = w.firstDayOfWeek == undefined ? 0 : w.firstDayOfWeek;
     224                }
     225        };
     226}();
     227
     228jQuery.fn.jcalendar = function(a) {
     229        this.each(function() {
     230    var day = jQuery(this).find('select.jcalendar-select-day');
     231    var month = jQuery(this).find('select.jcalendar-select-month');
     232    var year = jQuery(this).find('select.jcalendar-select-year');
     233    jQuery('div.jcalendar-selects').after('<div class="jcalendar"></div>');
     234                jQuery.jcalendar.setDateWindow(this, a, year);
     235                jQuery.jcalendar.show(this, day, month, year);
     236
     237                day.change(function() {
     238                  // only if a valid day is selected
     239                  if (this.value > 0) {
     240                    d = new Date(year.val(), month.val()-1, this.value);
     241            jQuery.jcalendar.changeMonth(d, a, day, month, year);
     242          }
     243                });
     244
     245                month.change(function() {
     246                  // only if a valid month is selected
     247                  if (this.value > 0) {
     248                    d = new Date(year.val(), this.value-1, 1);
     249            jQuery.jcalendar.changeMonth(d, a, day, month, year);
     250          }
     251                });
     252
     253                year.change(function() {
     254                  // only if a valid year is selected
     255                  if (this.value > 0) {
     256                  d = new Date(this.value, month.val()-1, 1);
     257          jQuery.jcalendar.changeMonth(d, a, day, month, year);
     258        }
     259                });
     260
     261        });
     262        return this;
     263};
     264/**
     265 * jCalendar 0.5
     266 *
     267 * Some code based on jQuery Date Picker (http://kelvinluck.com/assets/jquery/datePicker/)
     268 *
     269 * Copyright (c) 2007 Theodore Serbinski (http://tedserbinski.com)
     270 * Dual licensed under the MIT (MIT-LICENSE.txt)
     271 * and GPL (GPL-LICENSE.txt) licenses.
     272 */
     273jQuery.jcalendar = function() {
     274        var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     275        var days = ['S', 'M', 'Tu', 'W', 'Th', 'F', 'S'];
     276        var navLinks = {p:'Prev', n:'Next', t:'Today'};
     277        var _firstDayOfWeek;
     278        var _firstDate;
     279        var _lastDate;
     280        var _selectedDate;
     281
     282        var _drawCalendar = function(dateIn, a, day, month, year) {
     283          var today = new Date();
     284          var d;
     285
     286                if (dateIn == undefined) {
     287                        // start from this month.
     288                        d = new Date(today.getFullYear(), today.getMonth(), 1);
     289                        year.val(today.getFullYear());
     290                        month.val(today.getMonth()+1);
     291                        day.val(today.getDate());
     292                }
     293                else {
     294                        // start from the passed in date
     295                        d = dateIn;
     296                  d.setDate(1);
     297                }
     298
     299                // check that date is within allowed limits
     300                if ((d.getMonth() < _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear()) || d.getFullYear() < _firstDate.getFullYear()) {
     301                        d = new Date(_firstDate.getFullYear(), _firstDate.getMonth(), 1);
     302                }
     303                else if ((d.getMonth() > _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear()) || d.getFullYear() > _lastDate.getFullYear()) {
     304                        d = new Date(_lastDate.getFullYear(), _lastDate.getMonth(), 1);
     305                }
     306
     307                var firstMonth = true;
     308                var firstDate = _firstDate.getDate();
     309
     310                // create prev and next links
     311                if (!(d.getMonth() == _firstDate.getMonth() && d.getFullYear() == _firstDate.getFullYear())) {
     312                        // not in first display month so show a previous link
     313                        firstMonth = false;
     314                        var lastMonth = d.getMonth() == 0 ? new Date(d.getFullYear()-1, 11, 1) : new Date(d.getFullYear(), d.getMonth()-1, 1);
     315                        var prevLink = jQuery('<a href="" class="link-prev">&lsaquo; '+ navLinks.p +'</a>').click(function() {
     316                                jQuery.jcalendar.changeMonth(lastMonth, this, day, month, year);
     317                                return false;
     318                        });
     319                }
     320
     321                var finalMonth = true;
     322                var lastDate = _lastDate.getDate();
     323
     324                if (!(d.getMonth() == _lastDate.getMonth() && d.getFullYear() == _lastDate.getFullYear())) {
     325                        // in the last month - no next link
     326                        finalMonth = false;
     327                        var nextMonth = new Date(d.getFullYear(), d.getMonth()+1, 1);
     328                        var nextLink = jQuery('<a href="" class="link-next">'+ navLinks.n +' &rsaquo;</a>').click(function() {
     329                                jQuery.jcalendar.changeMonth(nextMonth, this, day, month, year);
     330                                return false;
     331                        });
     332                }
     333
     334                var todayLink = jQuery('<a href="" class="link-today">'+ navLinks.t +'</a>').click(function() {
     335                        day.val(today.getDate());
     336                        jQuery.jcalendar.changeMonth(today, this, day, month, year);
     337                        return false;
     338                });
     339
     340    // update the year and month select boxes
     341        year.val(d.getFullYear());
     342        month.val(d.getMonth()+1);
     343
     344                var headRow = jQuery("<tr></tr>");
     345                for (var i=_firstDayOfWeek; i<_firstDayOfWeek+7; i++) {
     346                        var weekday = i%7;
     347                        var wordday = days[weekday];
     348                        headRow.append('<th scope="col" abbr="'+ wordday +'" title="'+ wordday +'" class="'+ (weekday == 0 || weekday == 6 ? 'weekend' : 'weekday') +'">'+ wordday +'</th>');
     349                }
     350                headRow = jQuery("<thead></thead>").append(headRow);
     351
     352                var tBody = jQuery("<tbody></tbody>");
     353                var lastDay = (new Date(d.getFullYear(), d.getMonth()+1, 0)).getDate();
     354                var curDay = _firstDayOfWeek - d.getDay();
     355                if (curDay > 0) curDay -= 7;
     356
     357                var todayDate = today.getDate();
     358                var thisMonth = d.getMonth() == today.getMonth() && d.getFullYear() == today.getFullYear();
     359
     360    // render calendar
     361                do {
     362                  var thisRow = jQuery("<tr></tr>");
     363                for (var i=0; i<7; i++) {
     364                        var weekday = (_firstDayOfWeek + i) % 7;
     365                        var atts = {'class':(weekday == 0 || weekday == 6 ? 'weekend ' : 'weekday ')};
     366
     367                        if (curDay < 0 || curDay >= lastDay) {
     368                                dayStr = ' ';
     369                        }
     370                        else if (firstMonth && curDay < firstDate-1) {
     371                                dayStr = curDay+1;
     372                                atts['class'] += 'inactive';
     373                        }
     374                        else if (finalMonth && curDay > lastDate-1) {
     375                                dayStr = curDay+1;
     376                                atts['class'] += 'inactive';
     377                        }
     378                        else {
     379                                d.setDate(curDay+1);
     380
     381                                // attach a click handler to every day to select it if clicked
     382                                // we use the rel attribute to keep track of the day that is being clicked
     383                                dayStr = jQuery('<a href="" rel="'+ d +'">'+ (curDay+1) +'</a>').click(function(e) {
     384            if (_selectedDate) {
     385               _selectedDate.removeClass('selected');
     386            }
     387                        _selectedDate = jQuery(this);
     388                        _selectedDate.addClass('selected');
     389            day.val(new Date(_selectedDate.attr('rel')).getDate());
     390                                        return false;
     391                                });
     392
     393                                // highlight the current selected day
     394                                if (day.val() == d.getDate()) {
     395                                  _selectedDate = dayStr;
     396                                  _selectedDate.addClass('selected');
     397                                }
     398                        }
     399
     400                        if (thisMonth && curDay+1 == todayDate) {
     401                                atts['class'] += 'today';
     402                        }
     403                        thisRow.append(jQuery("<td></td>").attr(atts).append(dayStr));
     404                        curDay++;
     405      }
     406
     407                        tBody.append(thisRow);
     408                } while (curDay < lastDay);
     409
     410                jQuery('div.jcalendar').html('<table cellspacing="1"></table><div class="jcalendar-links"></div>');
     411                jQuery('div.jcalendar table').append(headRow, tBody);
     412                jQuery('div.jcalendar > div.jcalendar-links').append(prevLink, todayLink, nextLink);
     413        };
     414
     415        return {
     416                show: function(a, day, month, year) {
     417                        _firstDate = a._startDate;
     418                        _lastDate = a._endDate;
     419                        _firstDayOfWeek = a._firstDayOfWeek;
     420
     421                        // pass in the selected form date if one was set
     422                        var selected;
     423                        if (year.val() > 0 && month.val() > 0 && day.val() > 0) {
     424                          selected = new Date(year.val(), month.val()-1, day.val());
     425                        }
     426                        else {
     427                          selected = null;
     428                        }
     429                        _drawCalendar(selected, a, day, month, year);
     430                },
     431                changeMonth: function(d, e, day, month, year) {
     432                        _drawCalendar(d, e, day, month, year);
     433                },
     434                /**
     435                * Function: setLanguageStrings
     436                *
     437                * Allows you to localise the calendar by passing in relevant text for the english strings in the plugin.
     438                *
     439                * Arguments:
     440                * days          -       Array, e.g. ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
     441                * months        -       Array, e.g. ['January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
     442                * navLinks      -       Object, e.g. {p:'Prev', n:'Next', c:'Close', b:'Choose date'}
     443                **/
     444                setLanguageStrings: function(aDays, aMonths, aNavLinks) {
     445                        days = aDays;
     446                        months = aMonths;
     447                        navLinks = aNavLinks;
     448                },
     449                /**
     450                * Function: setDateWindow
     451                *
     452                * Used internally to set the start and end dates for a given date select
     453                *
     454                * Arguments:
     455                * i                     -       The id of the INPUT element this date window is for
     456                * w                     -       The date window - an object containing startDate and endDate properties
     457                *                               e.g. {startDate:'24-11-1981', endDate:'25-12-2012}
     458                **/
     459                setDateWindow: function(i, w, year) {
     460                        if (w == undefined) w = {};
     461                        if (w.startDate == undefined) {
     462                                // set the minimum browseable date equal to January of the min year in the select box
     463                                // don't get the first option because that is an empty year
     464
     465                                // note we can't do this: year.find('option:eq(1)').val()
     466                                // it doesn't work in 1.0 since find() is destructive
     467                                // so we copy the object to a new var
     468                                i._startDate = new Date(jQuery(year).find('option:eq(1)').val(), 0, 1);
     469                        }
     470                        else {
     471                        dateParts = w.startDate.split('-');
     472                        i._startDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));
     473                        }
     474                        if (w.endDate == undefined) {
     475                          // set the maximum browseable date equal to December of the max year in the select box
     476
     477                          // note we can't do this: year.find('option:last').val()
     478                                // it doesn't work in 1.0 since find() is destructive
     479                                // so we copy the object to a new var
     480                                i._endDate = new Date(jQuery(year).find('option:last').val(), 11, 1);
     481                        }
     482                        else {
     483                        dateParts = w.endDate.split('-');
     484                        i._endDate = new Date(dateParts[2], Number(dateParts[1])-1, Number(dateParts[0]));
     485                        }
     486                        i._firstDayOfWeek = w.firstDayOfWeek == undefined ? 0 : w.firstDayOfWeek;
     487                }
     488        };
     489}();
     490
     491jQuery.fn.jcalendar = function(a) {
     492        this.each(function() {
     493    var day = jQuery(this).find('select.jcalendar-select-day');
     494    var month = jQuery(this).find('select.jcalendar-select-month');
     495    var year = jQuery(this).find('select.jcalendar-select-year');
     496    jQuery('div.jcalendar-selects').after('<div class="jcalendar"></div>');
     497                jQuery.jcalendar.setDateWindow(this, a, year);
     498                jQuery.jcalendar.show(this, day, month, year);
     499
     500                day.change(function() {
     501                  // only if a valid day is selected
     502                  if (this.value > 0) {
     503                    d = new Date(year.val(), month.val()-1, this.value);
     504            jQuery.jcalendar.changeMonth(d, a, day, month, year);
     505          }
     506                });
     507
     508                month.change(function() {
     509                  // only if a valid month is selected
     510                  if (this.value > 0) {
     511                    d = new Date(year.val(), this.value-1, 1);
     512            jQuery.jcalendar.changeMonth(d, a, day, month, year);
     513          }
     514                });
     515
     516                year.change(function() {
     517                  // only if a valid year is selected
     518                  if (this.value > 0) {
     519                  d = new Date(this.value, month.val()-1, 1);
     520          jQuery.jcalendar.changeMonth(d, a, day, month, year);
     521        }
     522                });
     523
     524        });
     525        return this;
     526};
  • wp-includes/script-loader.php

     
    7474                $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.3.1');
    7575                $this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '1.0.3');
    7676                $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2');
     77                $this->add( 'jcalendar', '/wp-includes/js/jquery/jcalendar.js', array('jquery'), '0.5' );
    7778
     79                // this would be much nicer if localize used json so it could handle arrays
     80                global $wp_locale;
     81                $this->localize( 'jcalendar', 'jcalendar_L10n', array(
     82                        'days' => array_values($wp_locale->weekday_abbrev),
     83                        'months' => array_values($wp_locale->month),
     84                        'navLinks' => array(
     85                                'p' => __('Prev'),
     86                                'n' => __('Next'),
     87                                't' => __('Today'),
     88                        ),
     89                ) );
     90
    7891                if ( is_admin() ) {
    7992                        global $pagenow;
    8093                        $man = false;
     
    205218
    206219                echo "<script type='text/javascript'>\n";
    207220                echo "/* <![CDATA[ */\n";
    208                 echo "\t$object_name = {\n";
    209                 $eol = '';
    210                 foreach ( $this->scripts[$handle]->l10n as $var => $val ) {
    211                         echo "$eol\t\t$var: \"" . js_escape( $val ) . '"';
    212                         $eol = ",\n";
    213                 }
    214                 echo "\n\t}\n";
    215                 echo "/* ]]> */\n";
     221                echo $this->js_encode_array( $object_name, $this->scripts[$handle]->l10n );
     222                echo "\n/* ]]> */\n";
    216223                echo "</script>\n";
    217224        }
    218225
    219226        /**
     227         * Poor man's json: recursively encode an associative array of strings or arrays as a javascript array definition
     228         */
     229        function js_encode_array( $name, $vals, $level=0 ) {
     230                $out = array();
     231                foreach ( $vals as $var => $val ) {
     232                        if ( is_array($val) )
     233                                $out[] = $this->js_encode_array( $var, $val, $level+1 );
     234                        else
     235                                $out[] = str_repeat("\t", $level+1) . "{$var}: \"" . js_escape( $val ) . '"';
     236                }
     237
     238                return str_repeat("\t", $level) . "{$name} " . ($level ? ':' : '=') . " {\n"
     239                        . join( ",\n", $out )
     240                        . "\n" . str_repeat("\t", $level) . "}";
     241        }
     242
     243        /**
    220244         * Determines dependencies of scripts
    221245         *
    222246         * Recursively builds hierarchical array of script dependencies.  Does NOT catch infinite loops.
  • wp-admin/post-new.php

     
    66wp_enqueue_script('prototype');
    77wp_enqueue_script('interface');
    88wp_enqueue_script('autosave');
     9wp_enqueue_script('jcalendar');
    910require_once ('./admin-header.php');
    1011
    1112if ( ! current_user_can('edit_posts') ) { ?>
  • wp-admin/includes/template.php

     
    416416
    417417}
    418418
     419// return an option/select list with correct html escaping
     420function input_dropdown($name, $vals, $selected=null, $class='', $onchange='') {
     421
     422        // cf. http://www.w3.org/TR/html401/appendix/notes.html#h-B.3.2.2
     423        $out = '<select name="' . htmlspecialchars($name) . '" class="' . htmlspecialchars($class) . '" onchange="' . htmlspecialchars($onchange) . '">' . "\n";
     424        foreach ($vals as $k=>$v) {
     425                $out .= '<option value="' . htmlspecialchars($k) . '"';
     426                if ( $selected !== null and $k == $selected )
     427                        $out .= ' selected="selected"';
     428                $out .= '>' . htmlspecialchars($v) . "</option>\n";
     429        }
     430        $out .= "</select>\n";
     431
     432        return $out;
     433}
     434
     435// return an array of month names for the current locale, indexed 1..12
     436function locale_months() {
     437        global $wp_locale;
     438
     439        $months = array();
     440        foreach ( range(1, 12) as $m )
     441                $months[$m] = $wp_locale->get_month( $m );
     442        return $months;
     443}
     444
    419445function touch_time( $edit = 1, $for_post = 1 ) {
    420446        global $wp_locale, $post, $comment;
    421447
    422448        if ( $for_post )
    423449                $edit = ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date ) ) ? false : true;
    424450
    425         echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
     451        echo '<fieldset class="jcalendar"><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__( 'Edit timestamp' ).'</label></legend>';
    426452
    427453        $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
    428454        $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
     
    433459        $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
    434460        $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
    435461
    436         echo "<select name=\"mm\" onchange=\"edit_date.checked=true\">\n";
    437         for ( $i = 1; $i < 13; $i = $i +1 ) {
    438                 echo "\t\t\t<option value=\"$i\"";
    439                 if ( $i == $mm )
    440                         echo ' selected="selected"';
    441                 echo '>' . $wp_locale->get_month( $i ) . "</option>\n";
    442         }
     462        echo '<div class="jcalendar-selects">';
     463        echo input_dropdown( 'mm', locale_months(), $mm, 'jcalendar-select-month', 'edit_date.checked=true' );
     464
     465        foreach ( range(1, 31) as $i )
     466                $days[$i] = $i;
     467        echo input_dropdown( 'jj', $days, $jj, 'jcalendar-select-day', 'edit_date.checked=true' );
     468
     469        foreach ( range(1970, 2038) as $i )
     470                $years[$i] = $i;
     471        echo input_dropdown( 'aa', $years, $aa, 'jcalendar-select-year', 'edit_date.checked=true' );
     472        echo '</div>';
     473
     474        $jcal_css_url = get_bloginfo('wpurl') . '/wp-includes/js/jquery/css/jcalendar.css?version=' . get_bloginfo('version');
     475
    443476?>
    444 </select>
    445 <input type="text" id="jj" name="jj" value="<?php echo $jj; ?>" size="2" maxlength="2" onchange="edit_date.checked=true"/>
    446 <input type="text" id="aa" name="aa" value="<?php echo $aa ?>" size="4" maxlength="5" onchange="edit_date.checked=true" /> @
    447 <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :
     477<script type="text/javascript">
     478<!--
     479jQuery(document).ready(function() {
     480        jQuery.jcalendar.setLanguageStrings(jcalendar_L10n.days, jcalendar_L10n.months, jcalendar_L10n.navLinks);
     481        jQuery('fieldset.jcalendar').jcalendar();
     482});
     483// -->
     484</script>
     485@ <input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" onchange="edit_date.checked=true" /> :
    448486<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
    449487<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" onchange="edit_date.checked=true" />
    450488<?php
     
    592630                echo '<input type="hidden" id="wp-old-slug" name="wp-old-slug" value="' . $name . '" />';
    593631}
    594632
    595 ?>
    596  No newline at end of file
     633?>
  • wp-admin/post.php

     
    5757                wp_enqueue_script('prototype');
    5858                wp_enqueue_script('autosave');
    5959        }
     60        wp_enqueue_script('jcalendar');
    6061        require_once('admin-header.php');
    6162
    6263        if ( !current_user_can('edit_post', $post_ID) )