Skip to content

Instantly share code, notes, and snippets.

@macedd
Created November 20, 2014 23:35
Show Gist options
  • Save macedd/4c8e962b898eaa06fde0 to your computer and use it in GitHub Desktop.
Save macedd/4c8e962b898eaa06fde0 to your computer and use it in GitHub Desktop.
magnificPopup to allow youtube playlists and embeded videos
$.extend(true, $.magnificPopup.defaults, {
// Allow embed youtube (playlist, etc)
iframe: {
patterns: {
youtube: {
index: 'youtube.com',
id: function(src)
{
// link pattern
var mt = src.match(/v=([^&]+)(&(.*))?/);
if (mt)
return mt[1] +'?'+ mt[3];
// embed pattern
mt = src.match(/embed\/([^\?\/]+)(\?(.*))?/);
if (mt)
return mt[1] +'?'+ mt[3];
},
src: '//www.youtube.com/embed/%id%&autoplay=1&rel=0'
}
}
},
// When elemened is focused, some mobile browsers in some cases zoom in
// It looks not nice, so we disable it:
callbacks: {
beforeOpen: function() {
if ($(window).width() < 700)
this.st.focus = false;
}
}
});
@LechDutkiewicz
Copy link

Thanks a lot for this solution. It really helped me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment