1/* 2 GitHub URL: https://github.com/gucastiliao/video-popup-js 3*/ 4 5(function($) { 6 $.fn.videoPopup = function(options) { 7 var videoPopup = { 8 embedLink: '' 9 } 10 11 var settings = $.extend({ 12 autoplay: false, 13 showControls: true, 14 controlsColor: null, 15 loopVideo: false, 16 showVideoInformations: true, 17 width: null, 18 customOptions: {} 19 }, options); 20 21 var parsers = { 22 youtube: { 23 regex: /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/, 24 test: function (videoUrl, regex) { 25 var match = videoUrl.match(regex); 26 return (match && match[7].length==11) ? match[7] : false; 27 }, 28 mount: function (videoCode) { 29 var youtubeOptions = { 30 autoplay: settings.autoplay, 31 color: settings.controlsColor, 32 loop: settings.loopVideo, 33 controls: settings.showControls, 34 showinfo: settings.showVideoInformations, 35 } 36 37 Object.assign(youtubeOptions, settings.customOptions); 38 39 return "https://www.youtube.com/embed/"+videoCode+"/?"+$.param(youtubeOptions); 40 } 41 }, 42 vimeo: { 43 regex: /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/, 44 test: function (videoUrl, regex) { 45 var match = videoUrl.match(regex); 46 return (match && match[5].length) ? match[5] : false; 47 }, 48 mount: function (videoCode) { 49 var vimeoOptions = { 50 autoplay: settings.autoplay, 51 color: settings.controlsColor, 52 loop: settings.loopVideo, 53 controls: settings.showControls, 54 title: settings.showVideoInformations, 55 } 56 57 Object.assign(vimeoOptions, settings.customOptions); 58 59 return "https://player.vimeo.com/video/"+videoCode+"/?"+$.param(vimeoOptions); 60 } 61 } 62 } 63 64 function mountEmbedLink(videoUrl) { 65 $.each(parsers, function(index, parser){ 66 var videoCode = parser.test(videoUrl, parser.regex); 67 68 if(videoCode) { 69 videoPopup.embedLink = parser.mount(videoCode); 70 return this; 71 } 72 }) 73 } 74 75 function mountIframe() { 76 var iframeElement = '<iframe src="'+videoPopup.embedLink+'" allowfullscreen frameborder="0" width="'+settings.width+'"></iframe>'; 77 78 if(!videoPopup.embedLink) { 79 iframeElement = '<div class="videopopupjs__block--notfound">Video not found</div>'; 80 } 81 82 return '<div class="videopopupjs videopopupjs--animation">'+ 83 '<div class="videopopupjs__content">'+ 84 '<span class="videopopupjs__close"></span>'+ 85 iframeElement+ 86 '</div>'+ 87 '</div>'; 88 } 89 90 $(this).css('cursor', 'pointer'); 91 $(this).on('click', function (event) { 92 event.preventDefault(); 93 94 var videoUrl = $(this).attr("video-url"); 95 var videoIframe = mountEmbedLink(videoUrl); 96 97 $("body").append(mountIframe()); 98 99 $('.videopopupjs__content').css('max-width', 700); 100 if(settings.width) { 101 $('.videopopupjs__content').css('max-width', settings.width); 102 } 103 104 if($('.videopopupjs').hasClass('videopopupjs--animation')){ 105 setTimeout(function() { 106 $('.videopopupjs').removeClass("videopopupjs--animation"); 107 }, 200); 108 } 109 110 $(".videopopupjs, .videopopupjs__close").click(function(){ 111 $(".videopopupjs").addClass("videopopupjs--hide").delay(515).queue(function() { $(this).remove(); }); 112 }); 113 }); 114 115 $(document).keyup(function(event) { 116 if (event.keyCode == 27){ 117 $('.videopopupjs__close').click(); 118 } 119 }); 120 121 return this; 122 }; 123}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.