Created
May 28, 2010 20:18
-
-
Save dscataglini/417674 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var start = new Date(); | |
var end = new Date(); | |
end.setDate(end.getDate() + 7); | |
$.fullCalendar.gcalFeed("http://www.google.com/calendar/feeds/b878ac83tpkjckoqh1mccmsrfk%40group.calendar.google.com/public/basic",{currentTimezone: 'America/New_York'})(start, end, function(events){ | |
var now = new Date(); | |
var VALID_SHOW_TITLES = ["The Ruby Show", "The Conversation", "The Big Web Show", "The Dev Show", "EE Podcast"]; | |
// auto detect from the page title if we should check for the next show for this page | |
var current_page_belongs_to_show = $.grep(VALID_SHOW_TITLES, function(el, idx){ | |
return document.title.indexOf(el) > -1; | |
})[0]; | |
// is there a live show right now? | |
var liveShow = function(events){ | |
$.each(events, function(evt){ | |
if(evt.start <= now && evt.stop >= now) return evt; | |
}); | |
return false; | |
}(events); | |
// What's the next show | |
var nextShow = function(events, title){ | |
if(title){ // if we're on the page of a show | |
var matchingShows= $.grep(events, function(el, idx){ | |
return (el.title == title) && (el.start > now); | |
}); | |
if(matchingShows.length > 0){ | |
return matchingShows[0]; | |
} | |
} | |
var farInFuture = new Date(); | |
farInFuture.setDate(farInFuture.getDate() + 8); | |
var firstEvent = {start : farInFuture}; | |
$.each(events, function(idx, el){ | |
if (el.start > now && el.start < firstEvent.start){ | |
firstEvent = el; | |
} | |
}); | |
return firstEvent; | |
}(events, current_page_belongs_to_show); | |
if(liveShow){ | |
console.log(liveShow.title + " is live right now! <link_to> live show </link_to>") | |
}else{ | |
console.log(nextShow); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment