1jQuery(function($) { 2 3 var getYouTubeVideoId = function(url) { 4 var match = url.match(/youtu\.be\/(.+)$/); 5 if (match && match.length == 2) { 6 return match[1]; 7 } 8 match = url.match(/[\?\&]v=([^&]+)/); 9 if (match && match.length == 2) { 10 return match[1]; 11 } 12 }; 13 14 var overlay = $('<div id="cmloc-gallery-overlay">'); 15 var overlayShadow = $('<div id="cmloc-gallery-overlay-shadow"></div>'); 16 var overlayContent = $('<div id="cmloc-gallery-overlay-content"></div>'); 17 overlay.append(overlayShadow); 18 overlay.append(overlayContent); 19 $('body').append(overlay); 20 overlay.hide(); 21 overlayShadow.click(function() { 22 overlay.hide(); 23 overlayContent.html(''); 24 }); 25 26 var galleryStack = $('a.cmloc-gallery'); 27 for (var i=0; i<galleryStack.length; i++) { 28 $(galleryStack[i]).data('galleryIndex', i); 29 } 30 var currentGalleryIndex = null; 31 32 galleryStack.click(function(ev) { 33 ev.stopPropagation(); 34 ev.preventDefault(); 35 36 var obj = $(this); 37 currentGalleryIndex = obj.data('galleryIndex'); 38 39 overlayContent.html(''); 40 overlay.show(); 41 42 var url = obj.attr('href'); 43 if (url.match(/https?:\/\/(www\.)?(youtube\.com|youtu\.be)\//)) { 44 var width = $(window).width()-100; 45 var height = Math.floor(width * 315/560); 46 if (height > $(window).height()-100) { 47 height = $(window).height()-100; 48 //console.log(height); 49 width = Math.floor(height * 560/315); 50 } 51 var content = $('<iframe frameborder="0" allowfullscreen></iframe>'); 52 content.attr('src', 'https://www.youtube.com/embed/' + getYouTubeVideoId(url)); 53 content.css('width', width + 'px'); 54 content.css('height', height + 'px'); 55 overlayContent.css('left', (($(window).width()-width)/2) + 'px'); 56 overlayContent.css('top', (($(window).height()-height)/2) + 'px'); 57 overlayContent.append(content); 58 var contentclose = '<span class="close">X</span>'; 59 overlayContent.append(contentclose); 60 } 61 else if (url.match(new RegExp('\.(jpe?g|png|gif|bmp|webp|bpg)$', 'i'))) { 62 var content = $('<img/>', {src: url}); 63 content.css('max-width', $(window).width()+'px'); 64 content.css('max-height', '100%'); 65 content.css('display', 'none'); 66 overlayContent.append(content); 67 overlayContent.css('height', '100%'); 68 setTimeout(function() { 69 var url_arr = url.split("-"); 70 var image_size = url_arr[url_arr.length-1]; 71 var image_width_arr = image_size.split("x"); 72 var image_width = image_width_arr[0]; 73 if (content.width()) { 74 if(content.height() > $(window).height()) { 75 content.css('height', '100%'); 76 } 77 overlayContent.css('left', ($(window).width()/2) - (content.width()/2) + 'px'); 78 if(content.width() > $(window).width()) { 79 content.css('width', '100%'); 80 } 81 overlayContent.css('top', ($(window).height()/2) - (content.height()/2) + 'px'); 82 } else { 83 if(image_width) { 84 overlayContent.css('left', Math.floor(($(window).width() - image_width)/2) + 'px'); 85 } else { 86 content.css('width', '50%'); 87 overlayContent.css('left', '25%'); 88 } 89 } 90 var contentclose = '<span class="close">X</span>'; 91 overlayContent.append(contentclose); 92 content.fadeIn('slow'); 93 }, 100); 94 } 95 else if (url.match(new RegExp('\.(mp4|avi|mpe?g|ogg|webm|mkv|flv|vob|ogv|mov|wmv|rm|rmvb|m4p|m4v|3gp)$', 'i'))) { 96 content = $('<video>Your browser does not support video.</video>'); 97 //, {src: url, controls: 'controls', autoplay: 'autoplay'}); 98 content.attr('src', url); 99 content.attr('controls', 'controls'); 100 content.attr('autoplay', 'autoplay'); 101 overlayContent.append(content); 102 var contentclose = '<span class="close">X</span>'; 103 overlayContent.append(contentclose); 104 content[0].play(); 105 content.attr('width', Math.floor($(window).width()/2)); 106 overlayContent.css('left', '25%'); 107 } 108 }); 109 110 $(document).bind('keydown', function(e) { 111 if (!overlay.is(':visible')) return; 112 if ( 39 == e.which ) { // next 113 if (currentGalleryIndex < galleryStack.length-1) { 114 currentGalleryIndex++; 115 galleryStack[currentGalleryIndex].click(); 116 } 117 } 118 else if ( 37 == e.which ) { // prev 119 if (currentGalleryIndex > 0) { 120 currentGalleryIndex--; 121 galleryStack[currentGalleryIndex].click(); 122 } 123 } 124 else if ( 27 == e.which ) { // escape 125 overlay.hide(); 126 overlayContent.html(''); 127 } 128 }); 129 130 $('body').on('click', '#cmloc-gallery-overlay-content span.close',function(e) { 131 overlay.hide(); 132 overlayContent.html(''); 133 }); 134 135});
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.