I've just started working on a website on which some developer was working previously. He has implemented Datepicker widget in one of the web pages.
When I go through the code of this implementation I'm not understanding what does the code actually do? I'm not able to figure out the way logic has been written.
I also gone through the jQuery UI API documentation of Datepicker widget regarding functions 'beforeShowDay' and 'onSelect' but couldn't find the clue there as well, so asking for help in make me understand the following code in easier and descriptive manner.
Can someone please make me understand the usage of functions 'beforeShowDay' and 'onSelect' in following implementation in simple and lucid language?
HTML Code :
<div class="col-md-2 voffset2 rightpad">
<div class="col-sm-3">
<div id="datepicker"></div>
</div>
</div>
Javascript Code :
<script type="application/javascript">
$(document).ready(function() {
/******* Display Calender and events highlighted *******/
/*Not understood what does below array variable has role to play */
var myDates = $.parseJSON('["1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31","1969-12-31"]');
$( "#datepicker" ).datepicker({
beforeShowDay: function(date) {
var dateObj = new Date(date);
var month = dateObj.getMonth() + 1;
if(month < 10) {
month = "0"+month;
}
var day = dateObj.getDate();
if(day < 10) {
day = "0"+day;
}
var year = dateObj.getFullYear();
thisdate = year + "-" + month + "-" + day;
if($.inArray(thisdate, myDates) != -1) {
return [true, 'eventDateCls', ''];
} else {
return [true, '', ''];
}
},
onSelect: function(dateText, inst) {
var dateAsString = dateText;
console.log(dateAsString);
url = "http://localhost/CKWEB_28-12-2015/ajax_event.php";
$.ajax({
url: url,
type: "POST",
data: {event_date:dateAsString},
beforeSend: function() {
$('#loader-icon').show();
},
complete: function() {
$('#loader-icon').hide();
},
success: function(data) {
$("#eventListing").html(data);
$('#loader-icon').hide();
},
error: function(){}
});
}
});
/******* Display Calender and events highlighted *******/
});
</script>