diff --git a/README.md b/README.md index 8ffd2b7..565aea2 100644 --- a/README.md +++ b/README.md @@ -12,28 +12,32 @@ Just copy the files into your php capable webserver directory. Be sure, that the Just call the url. You can filter by categories by adding /?filter=category to the request. You can expand the period of the events by adding /?period= to the request. The number represents the amount of future months as an integer between 1..12. -## Example integration using jQuery. +## Example integration using vanilla ja You will need to include a ``
`` placeholder in your html page and embed also the jQuery js library. ``` -(function($) { +document.addEventListener("DOMContentLoaded", function () { var cal_uri = "https://YOURDOMAIN/hackcal/"; - var uri_regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.]*(\?\S+)?)?)?)/ig + var uri_regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/\-_\.\:]*(\?\S+)?)?)?)/ig - $.getJSON(cal_uri, function(data) { - var items = []; - $.each(data, function(date, day) { - items.push("" + day.name + "" + day.weekday + ""); - $.each(day.events, function(uid, event) { - event.description = event.description.replace(/\n/g,"
").replace(uri_regex, "$1"); - items.push("" + event.datestr + "" + event.summary + "" + ((event.location)?event.location:'') + "" + ((event.description)?event.description:'') + ""); + fetch(cal_uri).then(res => res.json()).then(data => { + var items = []; + Object.keys(data).forEach(function (date) { + var day = new Date(date); + items.push("
" + day.toLocaleDateString(true, {weekday:'short', day:'numeric', month:'long', year: 'numeric'}) + "
"); + Object.keys(data[date].events).forEach(function (uid) { + var event = data[date].events[uid]; + if(event.location) event.location = event.location.replace(/\n/g,"
").replace(uri_regex, "$1"); + if(event.description) event.description = event.description.replace(/\n/g,"
").replace(uri_regex, (url) => {event.summary = `${event.summary}`; return "";}); + items.push("
" + event.datestr + "" + event.summary + " | " + ((event.location)?event.location:'') + "
" + ((event.description)?event.description:'') + "
"); }); }); - $('#hackcal').html("" + items.join( "" ) + "
"); + document.querySelector('#hackcal').innerHTML = items.join( "" ); }); -})(jQuery); +}); + ```