Skip to content

Instantly share code, notes, and snippets.

@stormwarning
Created June 26, 2015 15:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormwarning/1a6de7501a3085cb06a8 to your computer and use it in GitHub Desktop.
Save stormwarning/1a6de7501a3085cb06a8 to your computer and use it in GitHub Desktop.
Enable support for YouTube short URLs in Magnific Popup
$('.video').magnificPopup({
type: 'iframe',
iframe: {
patterns: {
youtu: {
index: 'youtu.be',
id: function( url ) {
// Capture everything after the hostname, excluding possible querystrings.
var m = url.match( /^.+youtu.be\/([^?]+)/ );
if ( null !== m ) {
return m[1];
}
return null;
},
// Use the captured video ID in an embed URL.
// Add/remove querystrings as desired.
src: '//www.youtube.com/embed/%id%?autoplay=1&rel=0'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment