Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That sounds pretty cool,</p> <p>Here's my solution. Read the comments.</p> <pre><code>(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 {11: "My birthday.", 23: "My anniversary" }; } // Receives January-&gt;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. theDateLinks.eq(eventDay-1) // select the right link .attr('original-title', theEvents[eventDay]) // set the text .tipsy(); // 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(); // Gets the date and initializes the first round of tipsies. var currentDate = $('#datepicker').datepicker('getDate'); // month+1 because the event considers January-&gt;1 // Last element is null, because, it doesn't actualy get used in the hanlder. addTipsys(currentDate.getYear(), currentDate.getMonth()+1, 'datepicker'); }); })(jQuery); </code></pre> <p><strong>Inconveniences:</strong></p> <ol> <li><p>The <code>_updateDatepicker</code> method get's called also when the user selects a day form the visible month, or when you set a date via <code>datepicker('setDate', theDate)</code>, which could be a little inefficient.</p></li> <li><p>It relies in a private function of the Datepicker, if in future versions they decide to change it's functionality, or change the name, this code will break. Although because of the nature of the function I don't see that happening soon.</p></li> </ol> <p><strong>NOTE:</strong> My first approach was to hook to the <code>onChangeMonthYear</code> event of the <code>ui.datepicker</code>, but because the event is triggered, before the replacing of the dates in the calendar, the <code>addTipsys</code> method, would add the tipsy's to the calendar dates that are about to get cleared. Therefore the need to call the <code>addTipsys</code> event AFTER the elements get refreshed.</p> <p><strong>EASY HACK:</strong> Hook a method to the <code>onChangeMonthYear</code> event of your calendar, and do a setTimeout to call the tipsy's. Some validation will need to be done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload