views:

20

answers:

0
<script type="text/javascript">
           $(function(){
             function getJsonDate(year, month) {
                 $.getJSON('dates.php?year='+year+'&month='+month, function(data) {
                     var i = 0;
                     for (i = 0; i < data.data.length; i++)
                     {
                         $('.ui-datepicker-calendar td a:exactly('+data.data[i]['d']+')')
                         .css({color: '#f00'})
                        .attr('href',data.data[i]['link'])
                         .parent().attr('onclick','');
                     }
                 });
             }
             $.expr[":"].exactly = function(el, i, m) {
                 var s = m[3];
                 if (!s) return false;
                 return eval("/^" + s + "$/i").test($(el).text());
            };
          $('#datepicker').datepicker({
                inline: true,
                 onSelect: function(dateText, inst) {
                     Date.prototype.toString = function () {return isNaN (this) ? 'NaN' : [this.getDate(), this.getMonth(), this.getFullYear()].join('/')}
                    d = new Date(dateText);
                     getJsonDate(d.getFullYear(), d.getMonth()+1);
                },
                 onChangeMonthYear: function(year, month, inst) {
                    //alert(year);
                     //alert(month);
                     getJsonDate(year, month);
                 }
            });
         });
    </script>

I found this code on some forums. It places links to the datepicker.

I created my own dates.php which outputs json that the datepicker will read.

First off the datepicker doesnt load the july links initially. After scrolling through the months a couple of times the July lniks are loaded in the different months. Then it loads for the correct month, July. Since it's grabbing from a database perhaps the josn is too slow to download?

Could someone help me understand this code?

btw I think clicking fast between the months changes the month before the links can be loaded, thus loading the links on a different month.