Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is not a very elegant solution, but it does seem to work. Can someone please come up with something better?</p> <p><strong>EDIT:</strong> Here's a jsFiddle with the code running: <a href="http://jsfiddle.net/Tobbe/JrkSN/3/" rel="nofollow">http://jsfiddle.net/Tobbe/JrkSN/3/</a></p> <p><strong>EDIT2:</strong> It works until I click on a date, then all the events disappears because the <code>beforeShowDay</code> callback isn't called in that case. How do I work around that?</p> <pre><code>getEvents(); $(function() { $('#dateDiv').datepicker({ altField: '#dateInput', altFormat: 'yy-mm-dd', dateFormat: 'yy-mm-dd', firstDay: '1', showOtherMonths: 'true', beforeShowDay: beforeShowDay, onChangeMonthYear: getEvents }); }); var enqueuedDates = []; var tryCounter = 0; var events = []; function getEvents() { events = []; enqueuedDates = []; $.getJSON('events.json', function(json) { events = json; }); } function beforeShowDay(date) { enqueuedDates.push(new Date(date)); if (enqueuedDates.length == 35) { processEnqueuedDates(); } return [true, '', '']; } function processEnqueuedDates() { if (!events || events.length === 0) { tryCounter++; if (tryCounter &lt; 100) { setTimeout(processEnqueuedDates, 10); } else { tryCounter = 0; } return; } tryCounter = 0; for (var i = 0; i &lt; enqueuedDates.length; ++i) { var event = getEvent(events, enqueuedDates[i]); if (event) { var theDateCells = $('#dateDiv .ui-datepicker-calendar td'); var hideTimeoutID; theDateCells.eq(i).addClass('eventPlanned'). bind('mouseenter', function(eventText) { return function() { if (hideTimeoutID) { clearTimeout(hideTimeoutID); hideTimeoutID = null; } var popup = $('#eventPopup'); if (popup.size() == 0) { popup = $('&lt;div&gt;&lt;/div&gt;').attr('id', 'eventPopup'); $('body').append(popup); } var pos = $(this).offset(); popup.html('&lt;p&gt;' + eventText + '&lt;/p&gt;'). css('left', pos.left + 5 + 'px'). css('top', (pos.top - popup.height() - 2) + 'px'). bind('mouseenter', function() { clearTimeout(hideTimeoutID); hideTimeoutID = null; }). bind('mouseleave', function() { $(this).hide(); }). show(); } }(event.text)). bind('mouseleave', function(eventObject) { hideTimeoutID = setTimeout(function() { $('#eventPopup').hide(); }, 200); }); } } } function getEvent(events, date) { return events.filter(function(event, index, arr) { return date - $.datepicker.parseDate('yy-mm-dd', event.date) === 0; })[0]; } </code></pre>
    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. This table or related slice is empty.
    1. 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