Merge pull request #32 from psquid/ytembed

Auto-embed youtube videos, in much the same way as images are already done.
This commit is contained in:
Luke Slater 2012-03-14 07:17:58 -07:00
commit 28474f5465
2 changed files with 33 additions and 3 deletions

22
public/ytembed.js Normal file
View File

@ -0,0 +1,22 @@
// let's fetch us some goddamn API
var apiEmbed = document.createElement('script');
apiEmbed.src = 'http://www.youtube.com/player_api';
document.getElementsByTagName('script')[0].parentNode.insertBefore(apiEmbed, document.getElementsByTagName('script')[0]);
// this will be called by the player API when it's finished downloading
function onYouTubePlayerAPIReady() {
var youTubePlaceholders = document.getElementsByClassName('ytplaceholder');
for(var i = 0; i < youTubePlaceholders.length; i++) {
var videoURL = youTubePlaceholders[i].innerHTML;
var videoIDMaybe = videoURL.match(/[?&]v=([A-Za-z0-9\-_]+)(?:[?&]|$)/);
youTubePlaceholders[i].innerText = '';
if(videoIDMaybe) {
var ytVideoID = videoIDMaybe[1];
var player = new YT.Player(youTubePlaceholders[i], {
height: '203',
width: '336',
videoId: ytVideoID
});
}
}
}

View File

@ -1,11 +1,19 @@
ul#quotelist ul#quotelist
-var hasYouTubeVids=false
-each quote in quotes -each quote in quotes
-if(quote.match(locals.url_regex)) -if(quote.match(locals.url_regex))
li.quote li.quote
a(href=quote) -if(quote.match(/(jpg|png|gif|jpeg|tiff)$/))
-if(quote.match(/(jpg|png|gif|jpeg|tiff)$/)) a(href=quote)
img(src=quote) img(src=quote)
-else -else if(quote.match(/youtube.com\/watch/))
-hasYouTubeVids = true
span(class='ytplaceholder')
=quote
-else
a(href=quote)
=quote =quote
-else -else
li.quote #{quote} li.quote #{quote}
-if(hasYouTubeVids)
script(src='/ytembed.js')