Last active
August 11, 2017 18:02
-
-
Save exlcodeshare/2473125a398db9532492 to your computer and use it in GitHub Desktop.
Alma Library Opening Hours API Example
This file contains 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
<!doctype html> | |
<!-- | |
***************************************************************************************************** | |
Author : Jeremy Steelberg | |
Date : 04/09/2015 | |
sDescription: This program creates a fullcalendar calendar and loads events that are in the JSON | |
document that is included as a string in the file. | |
***************************************************************************************************** | |
--> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>University Library Calendar</title> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script src='http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js'></script> | |
<script src="http://fullcalendar.io/js/fullcalendar-2.4.0/fullcalendar.min.js"></script> | |
<link rel='stylesheet' href='http://fullcalendar.io/js/fullcalendar-2.4.0/fullcalendar.min.css' /> | |
</head> | |
<body> | |
<div id='calendar'></div> | |
<script> | |
function parseCalendar(jsonDoc) { | |
var description = new Array(); | |
var openDays = new Array(); | |
var fromHour = new Array(); | |
var toHour = new Array(); | |
if (jsonDoc.days.day instanceof Array) { | |
$.each(jsonDoc.days.day, function(i, v) { | |
openDays.push(v.date.substring(0, 10)); | |
fromHour = []; | |
toHour = []; | |
if (v.hours.hour instanceof Array) { | |
$.each(v.hours.hour, function(j, w) { | |
fromHour.push(w.from); | |
toHour.push(w.to); | |
}) | |
} else { | |
fromHour.push(v.hours.hour.from); | |
toHour.push(v.hours.hour.to); | |
} | |
var hoursDescription = "\nFrom: "; | |
var arrayLength = fromHour.length; | |
for (var ix = 0; ix < arrayLength; ix++) { | |
hoursDescription = hoursDescription + fromHour.shift() + " To: " + toHour.shift() + "\nFrom: "; | |
} | |
var workDesc = "Open: " + v.day_of_week["-desc"] + hoursDescription; | |
var n = workDesc.length; | |
description.push(workDesc.substring(0, n - 6)); | |
}); | |
} else { | |
openDays.push(jsonDoc.days.day.date.substring(0, 10)); | |
fromHour = []; | |
toHour = []; | |
if (jsonDoc.days.day.hours.hour instanceof Array) { | |
$.each(jsonDoc.days.day.hours.hour, function(j, w) { | |
fromHour.push(w.from); | |
toHour.push(w.to); | |
}) | |
} else { | |
fromHour.push(jsonDoc.days.day.hours.hour.from); | |
toHour.push(jsonDoc.days.day.hours.hour.to); | |
} | |
var hoursDescription = "\nFrom: "; | |
var arrayLength = fromHour.length; | |
for (var ix = 0; ix < arrayLength; ix++) { | |
hoursDescription = hoursDescription + fromHour.shift() + " To: " + toHour.shift() + "\nFrom: "; | |
} | |
var workDesc = "Open: " + jsonDoc.days.day.day_of_week["-desc"] + hoursDescription; | |
var n = workDesc.length; | |
description.push(workDesc.substring(0, n - 6)); | |
} | |
var events = []; | |
for (var i = 0; i < openDays.length; i++) { | |
events.push({ | |
title: description[i], | |
start: openDays[i] | |
}) | |
} | |
return events; | |
} | |
$(document).ready(function() { | |
$.getJSON("https://gist.githubusercontent.com/exlcodeshare/2473125a398db9532492/raw/0a5b7ef997aaabfb8edf4606d390cfcaee0ef59d/openLibraryJSON.json", | |
function(json) { | |
var events = parseCalendar(json); | |
$('#calendar').fullCalendar({ | |
header: { | |
left: 'title', | |
center: '', | |
right: 'prev,next prevYear,nextYear today' | |
}, | |
titleFormat: 'MMMM YYYY', | |
eventLimit: true, // allow "more" link when too many events | |
events: events | |
}); | |
var d = new Date("September 1, 2015 1:00:00"); | |
$('#calendar').fullCalendar('gotoDate', d); | |
}); | |
}); | |
</script> | |
</body> | |
</html> | |
This file contains 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
{ | |
"days":{ | |
"day":[ | |
{ | |
"date":"2015-09-15Z", | |
"day_of_week":{ | |
"-desc":"Tuesday", | |
"#text":"3" | |
}, | |
"hours":{ | |
"hour":{ | |
"from":"08:00", | |
"to":"17:00" | |
} | |
} | |
}, | |
{ | |
"date":"2015-09-16Z", | |
"day_of_week":{ | |
"-desc":"Wednesday", | |
"#text":"4" | |
}, | |
"hours":{ | |
"hour":[ | |
{ | |
"from":"06:00", | |
"to":"11:00" | |
}, | |
{ | |
"from":"13:00", | |
"to":"17:00" | |
}, | |
{ | |
"from":"19:00", | |
"to":"23:00" | |
} | |
] | |
} | |
}, | |
{ | |
"date":"2015-09-17Z", | |
"day_of_week":{ | |
"-desc":"Thursday", | |
"#text":"5" | |
}, | |
"hours":{ | |
"hour":{ | |
"from":"08:00", | |
"to":"17:00" | |
} | |
} | |
}, | |
{ | |
"date":"2015-09-18Z", | |
"day_of_week":{ | |
"-desc":"Friday", | |
"#text":"6" | |
}, | |
"hours":{ | |
"hour":{ | |
"from":"08:00", | |
"to":"17:00" | |
} | |
} | |
}, | |
{ | |
"date":"2015-09-19Z", | |
"day_of_week":{ | |
"-desc":"Saturday", | |
"#text":"7" | |
}, | |
"hours":{ | |
"hour":{ | |
"from":"10:00", | |
"to":"15:00" | |
} | |
} | |
}, | |
{ | |
"date":"2015-09-21Z", | |
"day_of_week":{ | |
"-desc":"Monday", | |
"#text":"2" | |
}, | |
"hours":{ | |
"hour":{ | |
"from":"08:00", | |
"to":"17:00" | |
} | |
} | |
} | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment