Add global holidays to calendar, fix volume mute display
This commit is contained in:
parent
f55af1b68b
commit
ba93df4a1f
5 changed files with 115 additions and 4 deletions
51
Helpers/Holidays.js
Normal file
51
Helpers/Holidays.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
var _countryCode = null;
|
||||
var _holidaysCache = {};
|
||||
|
||||
function getCountryCode(callback) {
|
||||
if (_countryCode) {
|
||||
callback(_countryCode);
|
||||
return;
|
||||
}
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", "http://ip-api.com/json/", true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
_countryCode = response.countryCode;
|
||||
callback(_countryCode);
|
||||
}
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function getHolidays(year, countryCode, callback) {
|
||||
var cacheKey = year + "-" + countryCode;
|
||||
if (_holidaysCache[cacheKey]) {
|
||||
callback(_holidaysCache[cacheKey]);
|
||||
return;
|
||||
}
|
||||
var url = "https://date.nager.at/api/v3/PublicHolidays/" + year + "/" + countryCode;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
|
||||
var holidays = JSON.parse(xhr.responseText);
|
||||
_holidaysCache[cacheKey] = holidays;
|
||||
callback(holidays);
|
||||
}
|
||||
}
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function getHolidaysForMonth(year, month, callback) {
|
||||
getCountryCode(function(countryCode) {
|
||||
getHolidays(year, countryCode, function(holidays) {
|
||||
// 0-based months (0=Jan, 11=Dec)
|
||||
var filtered = holidays.filter(function(h) {
|
||||
var date = new Date(h.date);
|
||||
return date.getFullYear() === year && date.getMonth() === month;
|
||||
});
|
||||
callback(filtered);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue