Skip to content

Instantly share code, notes, and snippets.

@jonwilcox
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonwilcox/185db78250ac4c432b2c to your computer and use it in GitHub Desktop.
Save jonwilcox/185db78250ac4c432b2c to your computer and use it in GitHub Desktop.
Add News Story Featured Video
$('.lw_related_url:contains("YouTube Video")').each(function(){ // Get any related content links that contain the text "YouTube Video"
var link = $(this).find('a').attr('href'); // Get the href of the YouTube Link
var ID = RegExp('[?&]v=([^&]*)').exec(link)[1]; // Use a regular expression to get the video ID from the 'v' parameter
var $iframe = $('<iframe width="700" height="394" src="https://www.youtube.com/embed/'+ID+'" frameborder="0" allowfullscreen></iframe>'); // construct an iframe using the video ID
$('.news_image').addClass('video').prepend($iframe).fitVids(); // Add a class of 'video' to the .news_image div, prepend the iframe, and run fitvids on it
if($('.lw_related_url').length == 1) { // if that was the only link in the related content section
$('.related_content').remove(); // remove the whole section
} else {
$(this).remove(); // otherwise just remove that link
}
})
// hide the slideshow that would otherwise show on the page
.news_image.video .lw_slideshow_wrapper {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment