// for debugging in FF, so other browsers ignore the console commands.
var console;
if (!console) console = { 'log': function() {} };
/* This 'playlist' object defines the playlist IDs for each tab.
* Each name inside 'playlist' corresponds to class names for the tab that the playlists belong to (eg: "googleioTab" and "googleioBox" divs).
* Each string in 'ids' is the ID of a YouTube playlist that belongs in the corresponding tab.
*/
var playlists = {
'googleio' : {
'ids': ["734A052F802C96B9"]
},
'about' : {
'ids': ["D7C64411AF40DEA5","611F8C5DBF49CEC6"]
},
'developertips' : {
'ids': ["43E15866EF0033A2"]
},
'developersandbox' : {
'ids': ["77426907BBAD558E"]
}
};
/* Some playlists include the title in the description meta-data, so we need to account for this when building the thumbnail lists, so we don't show the title twice
* This string is read via indexOf(), so multiple IDs need only be comma-separated in this string.
*/
var playlistsWithTitleInDescription = "734A052F802C96B9";
/* This 'featured' object defines the Feature Videos list.
* Each playlist ID is paired with a custom video description.
'N6YdwzAvwOA' : "Make your user interface fast, with more efficient AdapterViews, better bitmap scaling, faster redrawing, ViewStub layouts, fewer Views, and more.",
// How Do I Code Thee?
'GARMe7Km_gk' : "If you'd like to augment your Android applications with pieces written in JavaScript or native code, watch this video."
};
/* When an event on the browser history occurs (back, forward, load),
* load the video found in the URL hash
*/
$(window).history(function(e, hash) {
if (location.href.indexOf("#v=") != -1) {
videoId = location.href.split("#v=");
clickVideo(videoId[1]); // click the link with a matching class
}
});
/* Load a video into the player box.
* @param id The YouTube video ID
* @param title The video title to display in the player box (character escaped)
* @param autoplay Whether to automatically play the video
*/
function loadVideo(id, title, autoplay) {
if($("." + id).hasClass("noplay")) {
console.log("noplay");
autoplay = false;
$("." + id).removeClass("noplay");
}
swfobject.embedSWF('http://www.youtube.com/v/' + id + '&rel=1&border=0&fs=1&autoplay=' +
$.history.add('v=' + id); // add the current video to the browser history
document.getElementById("doc-content").scrollTop = 0; // scroll the window to the top
}
/* Draw all videos from a playlist into a 'videoPreviews' list
* @param data The feed data returned from the youtube request
*/
function renderPlaylist(data) {
var MAX_DESC_LENGTH = 390; // the length at which we will trim the description
var feed = data.feed;
var entries = feed.entry || [];
var playlistId = feed.yt$playlistId.$t;
var ul = $('<ul class="videoPreviews" />');
// Loop through each entry (each video) and add it to the 'videoPreviews' list
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var title = entry.title.$t;
var id = entry.media$group.yt$videoid.$t;
var thumbUrl = entry.media$group.media$thumbnail[0].url;
var fullDescription = entry.media$group.media$description.$t;
var playerUrl = entry.media$group.media$content[0].url;
// Check whether this playlist includes the video title inside the description meta-data, so we can remove it
if (playlistsWithTitleInDescription.indexOf(playlistId) != -1) {
var lines = fullDescription.split("\n");
// If the first line includes the first 17 chars from the title, let's use the title from the desciption instead (because it's a more complete title)
// This accounts for, literally, "Google I/O 2009 -", which is (so far) the min AND max for properly identifying a title in the only playlist with titles in the description
if (lines[0].indexOf(title.slice(0,16)) != -1) {
h3Title = "<h3>" + lines[0] + "</h3>";
if (lines[2].length < 30) lines = lines.slice(3); // also, if the second line is very short (the speaker name), slice it out too
else lines = lines.slice(1); // otherwise, slice after the first line
}
fullDescription = lines.join("");
}
var shortDescription = fullDescription.substr(0, MAX_DESC_LENGTH);
shortDescription += shortDescription.length == MAX_DESC_LENGTH ? "..." : ""; // add ellipsis if we've chopped the description