1jQuery(document).ready(function($) { 2 // global variables for script 3 console.log('1') 4 var current, size; 5 $('.wp-block-gallery .blocks-gallery-item').on('click',function(e) { 6 // prevent default click event 7 e.preventDefault(); 8 // get href from clicked element 9 var image_href = $(this).find('a').attr("href"); 10 console.log('image_href', image_href); 11 // determine the index of clicked trigger 12 var slideNum = $('.wp-block-gallery .blocks-gallery-item').index(this); 13 console.log('slideNum', slideNum); 14 15 // find out if #ggbl_lightbox exists 16 if ($('#ggbl_lightbox').length > 0) { 17 // if it does 18 $('#ggbl_lightbox').fadeIn(300); 19 // otherwise 20 } else { 21 // create HTML markup for lightbox window 22 var lightbox = 23 '<div id="ggbl_lightbox">' + 24 '<div class="ggbl_close"></div>' + 25 '<ul id="ggbl_slider"></ul>' + 26 '<div class="ggbl_nav">' + 27 '<a href="#" class="ggbl_prev ggbl_slide-nav"></a>' + 28 '<a href="#" class="ggbl_next ggbl_slide-nav"></a>' + 29 '</div><!-- .ggbl_nav -->' + 30 '</div><!-- #ggbl_lightbox -->'; 31 // add lightbox HTML to the DOM 32 $('body').append(lightbox); 33 // make sure the user can't scroll while the lightbox is showing 34 $('body').addClass("ggbl_noscroll"); 35 // fill lightbox with .blocks-gallery-grid a hrefs 36 $('.wp-block-gallery').find('.blocks-gallery-item a').each(function() { 37 var $href = $(this).attr('href'); 38 $('#ggbl_slider').append( 39 '<li>' + 40 '<img src="' + $href + '">' + 41 '</li>' 42 ); 43 }); 44 } 45 // set the slider size based on number of objects in slideshow 46 size = $('#ggbl_slider > li').length; 47 // hide all slides, then show the selected slide 48 $('#ggbl_slider > li').hide(); 49 $('#ggbl_slider > li:eq(' + slideNum + ')').show(); 50 // set current to selected slide 51 current = slideNum; 52 }); 53 // click anywhere on the page to get rid of lightbox window 54 $('body').on('click', '#ggbl_lightbox', function() { // using .on() instead of .live(). more modern, and fixes event bubbling issues 55 $('#ggbl_lightbox').fadeOut(300); 56 $('body').removeClass("ggbl_noscroll"); 57 }); 58 // navigation left/right arrow keys, esc to close 59 60 document.onkeydown = checkKey; 61 62 function checkKey(e) { 63 64 e = e || window.event; 65 if (e.keyCode == '37') { 66 e.preventDefault(); 67 e.stopPropagation(); 68 var $this = $(this); 69 var dest; 70 dest = current - 1; 71 if (dest < 0) { 72 dest = size - 1; 73 } 74 // fadeOut current slide, fadeIn next/prev slide 75 $('#ggbl_slider > li:eq(' + current + ')').fadeOut(750); 76 $('#ggbl_slider > li:eq(' + dest + ')').fadeIn(750); 77 // update current slide 78 current = dest; 79 } else if (e.keyCode == '39') { 80 e.preventDefault(); 81 e.stopPropagation(); 82 var $this = $(this); 83 var dest; 84 dest = current + 1; 85 if (dest > size - 1) { 86 dest = 0; 87 } 88 89 // fadeOut current slide, fadeIn next/prev slide 90 $('#ggbl_slider > li:eq(' + current + ')').fadeOut(750); 91 $('#ggbl_slider > li:eq(' + dest + ')').fadeIn(750); 92 // update current slide 93 current = dest; 94 } else if (e.keyCode == '27') { 95 $('#ggbl_lightbox').fadeOut(300); 96 $('body').removeClass("ggbl_noscroll"); 97 } 98 99 } 100 101 102 103 // navigation prev/next 104 $('body').on('click', '.ggbl_slide-nav', function(e) { 105 // prevent link from firing and lightbox from accidentally closing 106 e.preventDefault(); 107 e.stopPropagation(); 108 var $this = $(this); 109 var dest; 110 // check if prev arrow was clicked 111 if ($this.hasClass('ggbl_prev')) { 112 dest = current - 1; 113 if (dest < 0) { 114 dest = size - 1; 115 } 116 } else { 117 // otherwise they clicked next 118 dest = current + 1; 119 if (dest > size - 1) { 120 dest = 0; 121 } 122 } 123 // fadeOut current slide, fadeIn next/prev slide 124 $('#ggbl_slider > li:eq(' + current + ')').fadeOut(750); 125 $('#ggbl_slider > li:eq(' + dest + ')').fadeIn(750); 126 // update current slide 127 current = dest; 128 }); 129});
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.