init(); function init() { var lastid = 99; (function($) { $( document ).ajaxError(function() { $( ".log" ).text( "Triggered ajaxError handler." ); }); })(jQuery); (function($) { var mycalendar = $('.calendar'); $.post('/api/calendar/generate', { month: "7", year: "2018" } , function(data) { mycalendar.replaceWith(data); console.log('Calendar Initialised'); }); })(jQuery); } function calsetactive(myid) { if (lastid != 99) { document.getElementById(lastid).classList.toggle("calendar-btn-active"); } var myDate = document.getElementById(myid); myDate.classList.toggle("calendar-btn-active"); lastid = myid; if (myDate.classList.contains("calendar-nothing")) { calendarEmptyDay(myid); } else { calendarOpen(myid); } } function calendarOpen(myid) { var mydate = document.getElementById(myid).name; $(function() { var loadingDiv = $('#calendarmodalload'); $.get('/adminV2/assets/lib/calendar/calendarmodal.php?date='+mydate, function(data) { loadingDiv.replaceWith(data); console.log("Loading day: "+mydate); }); }); } function calendarEmptyDay(myid) { var mydate = document.getElementById(myid).name; $(function() { var loadingDiv = $('#calendarmodalload'); $.get('/adminV2/assets/lib/calendar/calendarEmptyDay.php?date='+mydate, function(data) { loadingDiv.replaceWith(data); console.log("Loading empty day: "+mydate); }); }); } //Modal Calendar // When the user clicks on (x), close the modal function calendarmodalClose() { document.getElementById('calendar-modal').style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == document.getElementById('calendar-modal')) { document.getElementById('calendar-modal').style.display = "none"; } } // Boutton Back and Next on calendar Head function calendarback() { console.log("click detect"); lastid = 99; $(function() { var mycalendar = $('.calendar'); varmonth = varmonth - 1; if (varmonth < 1) { varyear = varyear - 1; varmonth = 12; } $.get('/adminV2/assets/lib/calendar/calendar.php?month='+varmonth+'&year='+varyear, function(data) { mycalendar.replaceWith(data); console.log("Going next"); }); }); } function calendarnext(){ console.log("click detect"); lastid = 99; $(function() { var mycalendar = $('.calendar'); varmonth = varmonth + 1; if (varmonth > 12) { varyear = varyear + 1; varmonth = 1; } $.get('/adminV2/assets/lib/calendar/calendar.php?month='+varmonth+'&year='+varyear, function(data) { mycalendar.replaceWith(data); console.log("Going next"); }); }); }