1/** 2 * Global Lightbox extension â WP core images: refresh Fancybox + image-link â icon click. 3 */ 4( function () { 5 const config = typeof window.wpcp_lightbox === 'object' ? window.wpcp_lightbox : null; 6 7 const refreshFancybox = () => { 8 if ( typeof window.Fancybox !== 'undefined' && window.Fancybox.refresh ) { 9 window.Fancybox.refresh(); 10 } 11 }; 12 13 const bindWpImageLinkClicks = () => { 14 document.querySelectorAll( '.wpcp-wp-lightbox-host' ).forEach( ( host ) => { 15 const icon = host.querySelector( '.wpcp-advanced-image-lightbox-icon' ); 16 if ( ! icon ) { 17 return; 18 } 19 host.querySelectorAll( 'a.wpcp-wp-lightbox-image-link' ).forEach( ( link ) => { 20 if ( link.dataset.wpcpWpLbBound === '1' ) { 21 return; 22 } 23 link.dataset.wpcpWpLbBound = '1'; 24 link.addEventListener( 'click', ( event ) => { 25 event.preventDefault(); 26 icon.click(); 27 } ); 28 } ); 29 } ); 30 }; 31 32 const bindRightClickProtection = () => { 33 if ( ! config || ! config.rightClickProtection ) { 34 return; 35 } 36 37 if ( 38 document.documentElement.dataset.wpcpActiveLightboxContextmenuProtection !== 39 '1' 40 ) { 41 document.documentElement.dataset.wpcpActiveLightboxContextmenuProtection = '1'; 42 document.addEventListener( 43 'contextmenu', 44 ( event ) => { 45 const target = 46 event.target instanceof Element 47 ? event.target 48 : event.target?.parentElement; 49 if ( 50 target?.closest( 51 '.fancybox__container, .wpcp-lightbox-wrapper' 52 ) 53 ) { 54 event.preventDefault(); 55 event.stopPropagation(); 56 } 57 }, 58 true 59 ); 60 } 61 62 document.querySelectorAll( '.wpcp-wp-lightbox-host' ).forEach( ( host ) => { 63 if ( host.dataset.wpcpLightboxContextmenuProtection === '1' ) { 64 return; 65 } 66 host.dataset.wpcpLightboxContextmenuProtection = '1'; 67 host.addEventListener( 68 'contextmenu', 69 ( event ) => { 70 const target = 71 event.target instanceof Element 72 ? event.target 73 : event.target?.parentElement; 74 if ( 75 target?.closest( 76 'a[data-fancybox], .wpcp-wp-lightbox-image-link, .wpcp-advanced-image-lightbox-icon' 77 ) 78 ) { 79 event.preventDefault(); 80 event.stopPropagation(); 81 } 82 }, 83 true 84 ); 85 } ); 86 }; 87 88 const initWpLightbox = () => { 89 bindWpImageLinkClicks(); 90 bindRightClickProtection(); 91 refreshFancybox(); 92 }; 93 94 if ( config && config.wpImages ) { 95 if ( document.readyState === 'loading' ) { 96 document.addEventListener( 'DOMContentLoaded', initWpLightbox ); 97 } else { 98 initWpLightbox(); 99 } 100 window.addEventListener( 'load', initWpLightbox ); 101 } 102} )();
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.