I have this array of events:
var events = {
"course": [{
"date": "9-4-2017",
"hour": "17:30",
"title": "lorem Ipsum",
"manager": "yada yada",
"link": "http://www.example.com"
},
{
"date": "9-5-2017",
"hour": "17:30",
"title": "lorem Ipsum",
"manager": "yada yada",
"link": "http://www.example.com"
},
]
};
While I managed to get the data I want while clicking on the dates, I didn't quit got how to use the "beforeShowDay" event to add a class to the dates in my array.
this is my "onSelect" code which works perfectly for now:
dateFormat: 'yyyy-mm-dd',
onSelect: function (date, el) {
$('.coursesDatesList ul').empty();
var day = el.selectedDay,
mon = el.selectedMonth,
year = el.selectedYear;
var el = $(el.dpDiv).find('[data-year="'+year+'"][data-month="'+mon+'"]').filter(function() {
return $(this).find('a').text().trim() == day;
});
var eventMonth = mon + 1;
var eventClass = ' event';
var eventDate = eventMonth+'-'+el.text()+'-'+year;
if(el[0].className == eventClass) {
$.each(events.course, function(i, v) {
if (v.date.search(eventDate) != -1) {
$('.coursesDatesContainer .courseDate').html(eventDate.replace(/-/g, '/'));
$('.coursesDatesContainer ul').append(
"<li>" +
"<span class='courseItemTime'>"+v.hour+"</span>" +
"<div class='courseItemName'><a title='"+v.title+"' href='"+v.link+"'>"+v.title+"</a></div>" +
"<span class='courseItemLecturer'>"+v.manager+"</span>" +
"<a class='goLink' href='"+v.link+"' title='"+v.title+"'>❯</a>" +
"</li>");
return;
}
});
} else {
//console.log('not an event day!');
}
}