function Schedule(hallId) { var events = []; this.update = function() { $.getJSON("https://cfp.openfest.org/schedule.json", function(data) { var scheduleEvents = $.map(data[hallId], function(event) { event['startTime'] = moment(event['startTime']).subtract(2, 'hours'); event['endTime'] = moment(event['endTime']).subtract(2, 'hours'); return event; }); events = scheduleEvents; }); } this.addEvent = function(event) { events.push(event); events = _.sortBy(events, function(event) { return event.startTime.unix() }); } this.upcomingEvents = function() { return _.select(events, function(event) { return event.startTime.isAfter(moment()); }); } this.nextEvent = function() { return _.first(this.upcomingEvents()); } this.currentEvent = function() { var latestEvent = _.last(this.pastEvents()); var nextEvent = this.nextEvent(); if (typeof nextEvent != 'undefined' && moment(nextEvent.startTime).subtract('minutes', 10).isAfter(moment())) { return latestEvent; } else { return undefined; } } this.futureEvents = function() { return this.upcomingEvents().splice(1); } this.pastEvents = function() { return _.select(events, function(event) { return event.startTime.isBefore(moment()); }); } this.allEvents = function() { return events; } this.addDelay = function(time) { _.each(this.upcomingEvents(), function(event, index, agenda) { event.startTime.add(time); }); } } $.urlParam = function(name){ var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results==null){ return null; } else{ return results[1] || 0; } } var schedule = new Schedule(parseInt($.urlParam('roomId')));