function renderTodaysHours(){
const todaysHours = document.getElementById('todaysHours');
if(todaysHours){
var yyyymmdd = new Date().toISOString().split('T')[0].replace(/-/g, '');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.law.berkeley.edu/library/hours/hours.json');
xhr.responseType = 'json';
xhr.onload = function() {
console.log('here');
if (this.status === 200) {
const data = this.response; // Already an object
const filteredWeeks = data.weeks.filter(week => week.thisWeek == true);
const thisWeek = filteredWeeks[0];
const today = thisWeek[new Date().toLocaleDateString('en-US', { weekday: 'long'}).substring(0,2).toLowerCase()];
if(today.hours.mrr && today.hours.sa){
todaysHours.innerHTML = `
Today's Hours
- Service Desks: ${to12hhmm(today.hours.sa)}
- Main Reading Room (Law Community Only): ${to12hhmm(today.hours.mrr)}
Full hours and access
`;
}
}
};
xhr.send();
}
}
function fireTopDB(){
window.open(jQuery("select[name='topDatabase']").val(), '_blank');
return false;
}
function layCrumbs(pageID, terminalLabel = false){
var target = jQuery.find("#menu-library-menu .page-item-" + pageID)[0];
if(target) {
lis = jQuery(target).parentsUntil("#menu-library-menu").filter("li");
var crumbs = Array(lis.length);
for(var i = 0; i < lis.length; i++){
firstChild = jQuery(lis[i]).children()[0];
if(firstChild.tagName.match(/^a$/i)) {
crumbs[i] = firstChild.outerHTML;
} else if(firstChild.tagName.match(/button/i)){
crumbs[i] = firstChild.innerText;
}
}
crumbs.reverse();
if(terminalLabel) crumbs.push(terminalLabel);
crumbsString = crumbs.join(' ');
jQuery('.breadcrumbs .row li:last').html(crumbsString);
}
}
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
function to12hhmm(raw){ // 0730-2330, e.g.
var fromTo = raw.split('-');
var from = fromTo[0];
var to = fromTo[1];
var hh = from.substring(0,2);
var mm = from.substring(2,4);
var prepared = hh > 12 ? hh-12 : hh.replace(/^0/, '');
prepared += ':' + mm;
apm = hh > 12 ? 'pm' : 'am';
prepared += apm + '-';
var hh = to.substring(0,2);
var mm = to.substring(2,4);
prepared += hh > 12 ? hh-12 : hh;
prepared += ':' + mm;
apm = hh > 12 ? 'pm' : 'am';
prepared += apm;
return prepared;
}
jQuery(document).ready(function(){
renderTodaysHours();
jQuery('#menu-footer-menu').append("");
});