1/** 2 * Lightbox 3 */ 4 5(function ($) { 6 7 $.fn.powerkitLightbox = function (options) { 8 9 var settings = $.extend({ 10 gallery: false, 11 }, options); 12 13 var objSelector = this; 14 var imageSelector = null; 15 var containerSelector = null; 16 var initGallery = []; 17 18 $(objSelector).each(function () { 19 var id = Math.random().toString(36).substr(2, 9); 20 21 if ($(this).is('img')) { 22 imageSelector = this; 23 } else { 24 imageSelector = $(this).find('img'); 25 } 26 27 $(imageSelector).each(function () { 28 29 var container = $(this).parent(); 30 31 if (!$(container).is('a')) { 32 return; 33 } 34 35 var imagehref = $(container).attr('href'); 36 if (!imagehref.match(/\.(gif|jpeg|jpg|png|webp)/)) { 37 return; 38 } 39 40 if (!($(container).closest('figure').length)) { 41 $(container).wrap('<figure class="pk-lightbox-container"></figure>'); 42 } 43 44 if (!$(container).closest('figure').hasClass('pk-lightbox-container')) { 45 $(container).closest('figure').addClass('pk-lightbox-container'); 46 } 47 48 // Img classes. 49 var imgClasses = ['alignnone', 'aligncenter', 'alignleft', 'alignright']; 50 51 imgClasses.forEach(function (el) { 52 if ($(container).find('img').hasClass(el)) { 53 $(container).find('img').removeClass(el); 54 $(container).find('img').closest('figure').addClass(el); 55 56 // Add width to figure. 57 var imgWidth = $(container).find('img').attr('width'); 58 59 if (parseInt(imgWidth) !== 'NaN') { 60 $(container).find('img').closest('figure').width(imgWidth); 61 } 62 } 63 }); 64 65 $(this).attr('loading', 'eager'); 66 $(this).attr('fetchpriority', 'high'); 67 68 container = $(container).parent(); 69 70 $('> a', container).not('.pk-pin-it').addClass('pk-image-popup'); 71 72 if (powerkit_lightbox_localize.zoom_icon) { 73 $('> a', container).not('.pk-pin-it').addClass('pk-zoom-icon-popup'); 74 } 75 76 if ($(objSelector).is('img')) { 77 containerSelector = container; 78 } 79 80 }); 81 82 if (!$(objSelector).is('img')) { 83 containerSelector = this; 84 } 85 86 if ($(containerSelector).is('[data-pk-uuid]')) { 87 return; 88 } 89 90 $(containerSelector).attr('data-pk-uuid', id); 91 92 initGallery[id] = GLightbox({ 93 loop: settings.gallery, 94 touchNavigation: true, 95 autoplayVideos: true, 96 selector: `[data-pk-uuid="${id}"] .pk-image-popup`, 97 }); 98 99 initGallery[id].on('slide_before_load', (data) => { 100 const { slideIndex, slideNode, slideConfig, player, trigger } = data; 101 102 let figure = $(trigger).closest('figure'); 103 104 let description = $(figure).find('img').data('lightbox-description') || ''; 105 106 if (!description) { 107 description = $(figure).find('.wp-caption-text').text(); 108 } 109 110 if (!description) { 111 description = $(figure).find('figcaption').text(); 112 } 113 114 if (description) { 115 slideConfig.title = description; 116 } 117 }); 118 }); 119 }; 120 121 122 function initPowerkitLightbox() { 123 var excludeSelectors = powerkit_lightbox_localize.exclude_selectors; 124 var imageSelectors = powerkit_lightbox_localize.single_image_selectors; 125 var gallerySelectors = powerkit_lightbox_localize.gallery_selectors 126 127 // Exclude. 128 var filterSelectors = null; 129 130 var filterPowerkitLightbox = function () { 131 if (filterSelectors) { 132 if ($(this).closest(filterSelectors).length > 0) { 133 return false; 134 } 135 } 136 return true; 137 } 138 139 // Single Init ----------------------------------- 140 $(imageSelectors).imagesLoaded(function () { 141 var exSplit = excludeSelectors.split(','); 142 var glSplit = gallerySelectors.split(','); 143 144 // Join exclude selectors. 145 filterSelectors = exSplit.concat(glSplit).filter(function (value) { 146 return !!value; 147 }).filter(function (value) { 148 return !this[value] && (this[value] = true); 149 }, Object.create(null)).join(','); 150 151 // Init. 152 $(imageSelectors).filter(filterPowerkitLightbox).powerkitLightbox(); 153 }); 154 155 // Gallery Init ----------------------------------- 156 $(gallerySelectors).imagesLoaded(function () { 157 filterSelectors = excludeSelectors; 158 159 // Init. 160 $(gallerySelectors).filter(filterPowerkitLightbox).powerkitLightbox({ gallery: true }); 161 }); 162 } 163
164 $(document).ready(function () { 165 initPowerkitLightbox(); 166 167 $(document.body).on('post-load image-load', function () { 168 initPowerkitLightbox(); 169 }); 170 }); 171 172})(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.