Last active
April 20, 2025 13:16
-
-
Save JayGreentree/cb7564fdbf4cf839e499cec89a233765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
StartServiceLiveCheck(); | |
}); | |
function StartServiceLiveCheck() { | |
UpdateServiceLiveCheck(); | |
setTimeout("StartServiceLiveCheck()", 5000); | |
} | |
function UpdateServiceLiveCheck() { | |
$.ajax({ | |
url: "/isLive", | |
success: function(data) { | |
if (data.indexOf("true") != -1) { | |
$("#notlive").hide(); | |
$("#live").fadeIn('fast'); | |
$('.countdown').delay(2000).animate({ backgroundColor: "#7f3e19" }, 'slow'); | |
$(".mobile-liveservice").show(); | |
} | |
} | |
}); | |
goLive = function() { | |
$('#churchonline_counter .live').show(); | |
$('#churchonline_counter .co-header-countdown-time').hide(); | |
}; | |
} | |
jQuery(function() { | |
days = void 0; | |
hours = void 0; | |
minutes = void 0; | |
seconds = void 0; | |
intervalId = void 0; | |
return $.ajax({ | |
url: "/api/data.json", | |
dataType: "json", | |
success: function(data) { | |
var seconds_till; | |
const now = new Date(); | |
const eventStartTime = new Date(data.response.item.eventStartTime); | |
const eventEndTime = new Date(data.response.item.eventEndTime); | |
$("#churchonline_counter").show(); | |
if (data.response.item.isLive) { | |
return goLive(); | |
} else if (now > eventEndTime) { | |
$("#churchonline_counter .live").hide(); | |
$('#churchonline_counter .co-header-countdown-time').show(); | |
return; | |
} else { | |
seconds_till = (eventStartTime - now) / 1000; | |
days = Math.floor(seconds_till / 86400); | |
hours = Math.floor((seconds_till % 86400) / 3600); | |
minutes = Math.floor((seconds_till % 3600) / 60); | |
seconds = Math.floor(seconds_till % 60); | |
return intervalId = setInterval(function() { | |
if (--seconds < 0) { | |
seconds = 59; | |
if (--minutes < 0) { | |
minutes = 59; | |
if (--hours < 0) { | |
hours = 23; | |
if (--days < 0) { | |
days = 0; | |
} | |
} | |
} | |
} | |
if (days.toString() == 1) { | |
$(".co-countdown-days").html("1"); | |
} else { | |
$(".co-countdown-days").html((hours.toString().length < 2 ? days : days)); | |
}; | |
if (hours.toString() == 1) { | |
$(".co-countdown-hours").html("1"); | |
} else { | |
$(".co-countdown-hours").html((hours.toString().length < 2 ? hours : hours)); | |
}; | |
if (minutes.toString() == 1) { | |
$(".co-countdown-mins").html("1"); | |
} else { | |
$(".co-countdown-mins").html((minutes.toString().length < 2 ? minutes : minutes) + " "); | |
}; | |
$(".co-countdown-secs").html((seconds.toString().length < 2 ? "0" + seconds : seconds)); | |
if (days === 00) { | |
$('.daysAll').hide(); | |
}; | |
if (hours === 00) { | |
$('.hoursAll').hide(); | |
}; | |
if (seconds === 0 && minutes === 10 && hours === 0 && days === 0) { | |
return clearInterval(intervalId); | |
}; | |
$("#eventTitle").html((data.response.item.title)); | |
}, 1000); | |
} | |
}, | |
error: function(xhr, ajaxOptions, thrownError) { | |
return console.log(thrownError); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% header "Content-Type: application/json; charset=utf-8" %} | |
{% header "Access-Control-Allow-Origin: *" %} | |
{% set currentEventId = craft.app.request.segment(3) %} | |
{% for event in craft.calendar.events({id: 'not ' ~ currentEventId,rangeStart: 'today',rangeEnd: '1 month',limit: 1}) %} | |
{ | |
"meta": { | |
"status": 200 }, | |
"response": { | |
"item": { | |
"isLive": {% include 'isLive.twig' %}, | |
"eventStartTime": "{{ event.startDate.format("Y-m-d G:i:s") }}", | |
"eventEndTime": "{{ event.endDate.format("Y-m-d G:i:s") }}", | |
"title": "{{ event.title }}" | |
} | |
} | |
} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did not solve the issue. The problem seems to be on craft calendar side. Only thing this does is show event ended. It didnt allow the countdown to reset to the next event as I was needing.