1(function($) { 2 let modalId = $('#image-gallery'); 3 4 $(document) 5 .ready(function () { 6 7 loadGallery(true, 'a.thumbnail'); 8 9 //This function disables buttons when needed 10 function disableButtons(counter_max, counter_current) { 11 $('#show-previous-image, #show-next-image') 12 .show(); 13 if (counter_max === counter_current) { 14 $('#show-next-image') 15 .hide(); 16 } else if (counter_current === 1) { 17 $('#show-previous-image') 18 .hide(); 19 } 20 } 21 22 /** 23 * 24 * @param setIDs Sets IDs when DOM is loaded. If using a PHP counter, set to false. 25 * @param setClickAttr Sets the attribute for the click handler. 26 */ 27 28 function loadGallery(setIDs, setClickAttr) { 29 let current_image, 30 selector, 31 counter = 0; 32 33 $('#show-next-image, #show-previous-image') 34 .click(function () { 35 if ($(this) 36 .attr('id') === 'show-previous-image') { 37 current_image--; 38 } else { 39 current_image++; 40 } 41 42 selector = $('[data-image-id="' + current_image + '"]'); 43 updateGallery(selector); 44 }); 45 46 function updateGallery(selector) { 47 let $sel = selector; 48 current_image = $sel.data('image-id'); 49 $('#image-gallery-title') 50 .text($sel.data('title')); 51 $('#image-gallery-image') 52 .attr('src', $sel.data('image')); 53 disableButtons(counter, $sel.data('image-id')); 54 } 55 56 if (setIDs == true) { 57 $('[data-image-id]') 58 .each(function () { 59 counter++; 60 $(this) 61 .attr('data-image-id', counter); 62 }); 63 } 64 $(setClickAttr) 65 .on('click', function () { 66 updateGallery($(this)); 67 }); 68 } 69 }); 70 71 // build key actions 72 $(document) 73 .keydown(function (e) { 74 switch (e.which) { 75 case 37: // left 76 if ((modalId.data('bs.modal') || {})._isShown && $('#show-previous-image').is(":visible")) { 77 $('#show-previous-image') 78 .click(); 79 } 80 break; 81 82 case 39: // right 83 if ((modalId.data('bs.modal') || {})._isShown && $('#show-next-image').is(":visible")) { 84 $('#show-next-image') 85 .click(); 86 } 87 break; 88 89 default: 90 return; // exit this handler for other keys 91 } 92 e.preventDefault(); // prevent the default action (scroll / move caret) 93 }); 94})(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.