1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| (function($){
/**
* Returns a dictionary, where the keys are the day of the month,
* and the value is the text.
* @param year - The year of the events.
* @param month - The month of the events.
* @param calendarID - Events for a specific calendar.
*/
function getMonthEvents(year, month, calendarId, callback){
var param = "year="+year+"&month="+month;
var event;
$.ajax({
type: "GET",
url: "test.php",
data : param,
dataType: "script",
error:function(msg){
alert( "Error !: " + msg );
},
success:function(data){
callback(data);
}
});
}
// Receives January->1
function addTipsys(year, month, calendarId){
var theEvents = getMonthEvents(year, month, calendarId, function(data){
alert(data)
return data;
});
var theDateLinks = $('#' + calendarId + ' .ui-datepicker-calendar a');
for(eventDay in theEvents){
// Minus one, because the date in the tipies are regular dates (1-31)
// and the links are 0-based.
theDateLinks.eq(eventDay-1) // select the right link
.attr('original-title', theEvents[eventDay]) // set the text
.tipsy({html: true, gravity: 'w'}); // init the tipsy, set your properties.
}
}
// Because the the event `onChangeMonthYear` get's called before updating
// the items, we'll add our code after the elements get rebuilt. We will hook
// to the `_updateDatepicker` method in the `Datepicker`.
// Saves the original function.
var _updateDatepicker_o = $.datepicker._updateDatepicker;
// Replaces the function.
$.datepicker._updateDatepicker = function(inst){
// First we call the original function from the appropiate context.
_updateDatepicker_o.apply(this, [inst]);
// No we can update the Tipsys.
addTipsys(inst.drawYear, inst.drawMonth+1, inst.id);
};
// Finally the calendar initializer.
$(function(){
// Creates the date picker, with your options.
$("#datepicker").datepicker();
/*
* Ne sert à rien ! aucune date n'a encore été choisie !
* C'est _updateDatepicker_o ci-dessus qui fait le travail
*/
/*
// Gets the date and initializes the first round of tipsies.
var currentDate = $('#datepicker').datepicker('getDate');
// month+1 because the event considers January->1
// Last element is null, because, it doesn't actualy get used in the hanlder.
addTipsys(currentDate.getYear(), currentDate.getMonth()+1, 'datepicker');
*/
});
})(jQuery); |