...
We can also do a Deal of the Month. See Chesaco RV for an example.
Deal of the Month
Place this script on the page that holds the countdown and link to the /deals-of-the-month page.
Note that this version needs to be manually synced with the dates on /deals-of-the-month.
Code Block |
---|
<!-- Deal of the Month Modification -->
<script>
$(function () {
function getEndOfMonthDay() {
var date = new Date();
var month_offset = 1; //Number of month to offset the current month by
var days_offset = 8; //Number of days to offset the first date of the month
var hours_offset = 1; //Number of hours to offset from midnight
date = new Date(date.getFullYear(), date.getMonth() + month_offset, days_offset, hours_offset);
return date
}
var newMonth = getEndOfMonthDay();
$('#defaultCountdown').countdown({until: newMonth, format: 'dHMS'});
});
</script> |
Deal of the Month - Synced Version
The variation of the above script makes an AJAX call to /deals-of-the-month to get the countdown end date value. If the value cannot be found, the countdown will default to manually specified parameter. Place this script on the page that hosts the countdown element linking to /deals-of-the-month.
Code Block |
---|
<!-- Deal of the Month Synced Version -->
<script>
$(function () {
function getEndOfMonthDay() {
var date = new Date();
var month_offset = 1; //Number of month to offset the current month by
var days_offset = 8; //Number of days to offset the first date of the month
var hours_offset = 1; //Number of hours to offset from midnight
date = new Date(date.getFullYear(), date.getMonth() + month_offset, days_offset, hours_offset);
return date
}
var newMonth = getEndOfMonthDay();
console.log(newMonth);
$(document).ready(function () {
const xhttp = new XMLHttpRequest();
const ajaxURL = "/deals-of-the-month"
xhttp.onload = function () {
var unitCountdown = $($.parseHTML(this.responseText)).find(".dow-unit-countdown")
var unitCountdownVal
if (unitCountdown.length > 0) {
unitCountdownVal = new Date(unitCountdown.data("end-date"));
console.log("Found Countdown end value on " + ajaxURL + ": " + unitCountdownVal);
$('#defaultCountdown').countdown({ until: unitCountdownVal, format: 'dHMS' });
}
else {
console.log("Countdown value not found. Defaulting to " + unitCountdownVal);
$('#defaultCountdown').countdown({ until: newMonth, format: 'dHMS' });
}
}
xhttp.open("GET", ajaxURL, true);
xhttp.send();
})
});
</script> |