I am using Adam Shaw's Full Calender on my bookings page.
Now I want to customize this calender in such a way that every empty cell should have a link "Place Booking". Clicking on this anchor should open it in a new tab and takes the date of that cell in the URL.
Here is my code
$('.fc-day-number').each(function() {
var day = parseInt($(this).html());
$(this).html('<a href="http://www.example.com/booking.php?booking_date='booking date of the cell'" target="_blank">' + day + '</a>');
});
For the time being I have placed the anchor on day number of the cell. But the problem is that the anchors disappear when I change the month from back and forward buttons of the plugin also I am unable to get the date of cell.
I am not an expert in JS any help will be much appreciated.
Try this:
$('#calendar').fullCalendar({
viewRender: function(view, $element) {
$element.find('.fc-day-number').each(function() {
var $this = $(this);
var match = (/^(\d+)\-(\d+)\-(\d+)$/).exec($this.attr('data-date'));
var date = new Date(+match[1], +match[2], +match[3]);
$(this).wrapInner('<a href="http://www.example.com/booking.php?booking_date=' + encodeURIComponent(date.toUTCString()) + '" target="_blank"></a>');
});
}
});
<link href="http://fullcalendar.io/js/fullcalendar-2.7.2/fullcalendar.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="http://fullcalendar.io/js/fullcalendar-2.7.2/fullcalendar.min.js"></script>
<div id="calendar"></div>