Created
June 26, 2015 15:05
-
-
Save stormwarning/1a6de7501a3085cb06a8 to your computer and use it in GitHub Desktop.
Enable support for YouTube short URLs in Magnific Popup
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
$('.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