$(document).ready( function() { // ---------------------- INITIALIZE ------------------------------ var fluxCalID = '#fluxCalendar'; // reference element on site $.fluxCal = $(fluxCalID); var fetchingRecords = false; // tracks if an AJAX request is active var weekStr = ""; $.ajaxSetup({cache:false}); var debug = 0; var mobileBreakPoint = 420; // ---------------------------------------------------------------- if (debug) { $("
") .css('position', 'fixed') .css('top', '5px') .css('right', '45px') .css('padding', '5px') .css('background-color', '#fff') .css('border', '1px solid #000') .appendTo('body'); } function loadEvents(){ var json = null; fetchingRecords = true; if ($.fluxCal.data('params')) { $.params = '&'+$.fluxCal.data('params'); } else { $.params = ''; } if ($.fluxCal.data('pastevents')) { $.pastevents = '&pastevents='+$.fluxCal.data('pastevents'); } else { $.pastevents = ''; } $.ajax({ 'async': false, 'global': false, 'url': 'https://calendar.instone.com/get.php?cal='+$.fluxCal.data('id')+$.params+'&offset='+$.fluxCal.data('offset')+'&limit='+$.fluxCal.data('limit')+$.pastevents, 'dataType': "jsonp", 'success': function(response) { if (!response.length==0) { // if we have events to show // append new records for (i in response) { // ------------- calendar template start ----------------- if (response[i].WeekEnd==1) { dayClass='holiday' } else {dayClass='weekday'} if (response[i].LocationName!=0) {locationData=""+response[i].LocationName+""} else {locationData=' '} if (response[i].TravelTime!='') {travelTime=response[i].TravelTime+' minutes'} else {travelTime=' '} if (response[i].ArriveTimeDT!='') {arriveBy=response[i].ArriveTime} else {arriveBy=' '} if (response[i].BusTime) {busTime=response[i].BusTime;} else {busTime='';} if (response[i].Opponent) {opponent=response[i].Opponent} else {opponent=' '} if (response[i].Score) {score=response[i].Score} else {score=' '} if (response[i].Description) {description=""+response[i].Description+" |
"+response[i].PostponedContent+" |
Week "+response[i].Week+"
"; } else { weekStr = ""; } $.fluxCal.data('weeknum', response[i].Week); } // same layout for desktop/mobile; table layout for school calendars // BusTime field added calStr = weekStr + "There are no future events to show. Login
").appendTo("#calWrap"); } else { $("End of future events.
").appendTo("#calWrap"); } } }); } if ($.fluxCal.length>0) {// if a fluxcalendar is embedded // toggle description box for a calendar event $("body").on('click', ".fLocation a", function(){ $(".descrBlck").hide(); $(".descrBlck", $(this).closest('.fieldsBlck')).toggle(); return false; }); // triggering reachBottom event $(window).scroll( function(){ if ($(".calendarElm").length != 0) { // if there is an embedded calendar with future events if ( ($(window).scrollTop() - $(".calendarElm").last().offset().top + $(window).height()) > -($(window).height() ) && !fetchingRecords ) { $.fluxCal.trigger({type:'reachBottom'}); // trigger event } } }); // additional load of content $(document).on('reachBottom', fluxCalID, loadEvents); // initial load of content (function(){ $.fluxCal.empty(); $("").appendTo(fluxCalID); loadEvents(); })(); } });