(function ($) { $(function () { var options = $.extend({ youtube_url_patterns: undefined, autoplay_id: undefined }, anv_user); $video = $('.abaninja-video'); $video.magnificPopup({ type: 'iframe', iframe: { markup: '
'+ '
'+ ''+ '
', patterns: { youtube: { index: 'youtube.com/', id: function (url) { for (var i in options.youtube_url_patterns) { if (!options.youtube_url_patterns.hasOwnProperty(i)) continue; var re = new RegExp(options.youtube_url_patterns[i]); var result = re.exec(url); if (result) { return result[1]; } } alert('YouTube URL is in wrong format.'); }, src: '//www.youtube.com/embed/%id%?autoplay=1&showinfo=0&vq=hd1080&output=embed' }, vimeo: { index: 'vimeo.com/', id: function (url) { var m = url.match(/(https?:\/\/)?(www.)?(player.)?vimeo.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/); if (!m || !m[5]) return null; return m[5]; }, src: '//player.vimeo.com/video/%id%?autoplay=1' } }, srcAction: 'iframe_src' } }); $(".video-block__play").on('click.anv', function() { var video_id = $(this).data('video'), embed_frame = '', embed_container = $(this).parents('.video-block__wrapper').find('.video-block__embed'); embed_container.append(embed_frame); embed_container.addClass('video-block__embed--shown'); }); $('.video-block__embed').on('click.anv', '.video-close', function() { var aembed_container = $(this).parents('.video-block__embed'); aembed_container.removeClass('video-block__embed--shown'); setTimeout(function() { $('.video-embed').remove(); $('.video-close').remove(); }, 300); }); if (options.autoplay_id) { $('ul.grid-box--videos li').each(function (i, el) { if ($(el).find('[data-video-id="' + options.autoplay_id + '"]').length) { $video.magnificPopup('open', i); return false; } }); } }); })(jQuery);