开发者

jquery datePicker -- How to put events on particular dates and show them as tooltip

开发者 https://www.devze.com 2023-03-19 13:25 出处:网络
I\'m getting problem while adding events on dates in Jquery UI datepicker. I have to do following things:

I'm getting problem while adding events on dates in Jquery UI datepicker.

I have to do following things:

  • show events as tooltip also

  • onclick show them separately also like adding a new div

I have already done the following for this:

(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){ 
 //   return eventArr;
  return {11: "My birthday.", 23: "My anniversary" }; 
} 

// Receives January->1 
function addTipsys(year, month, calendarId){

   var theEvents = getMonthEvents(year, month, calendarId); 
   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. 
        alert(eventDay);
        theDateLinks.eq(eventDay-1)  // select the right link 
     开发者_如何转开发   .attr('original-title', theEvents[eventDay])  // set the text 
        .tipsy().css('background-color', '#DC143C');   // init the tipsy, set your properties. 

      // select the right link 
   } 
} 

// 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; 
alert('HI'+$.datepicker.initialized); 
// 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()
   // 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);

but here it gives --uncaught exception: Missing instance data for this datepicker --

please guide how to move further

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号