1/*skip-mtv-minify */ 2/** 3 * MTV Gallery Block JavaScript 4 * 5 * Handles PhotoSwipe lightbox initialization and gallery interactions 6 * WP Rocket compatible - uses absolute URLs for dynamic imports 7 * 8 * @package MotivareThemeTools 9 * @since 1.0.0 10 */ 11 12// Function to dynamically load and initialize the gallery module 13async function mtvLoadAndInitGallery() { 14 try { 15 // Use absolute URL from WordPress localization to avoid WP Rocket path issues 16 const moduleUrl = window.mtv_gallery_data?.gallery_module_url || './parts/gallery.js'; 17 const { initGallery } = await import(moduleUrl); 18 initGallery(); 19 } catch (error) { 20 console.error('Error loading gallery module:', error); 21 // Fallback to relative path if absolute URL fails 22 try { 23 const { initGallery } = await import('./parts/gallery.js'); 24 initGallery(); 25 } catch (fallbackError) { 26 console.error('Fallback gallery module loading also failed:', fallbackError); 27 } 28 } 29} 30 31// Assign the function to the global window object 32window.mtvLoadAndInitGallery = mtvLoadAndInitGallery; 33 34/** 35 * Check if we're in Gutenberg editor 36 */ 37function isGutenbergEditor() { 38 return document.body.classList.contains('block-editor-page') || 39 document.querySelector('.editor-styles-wrapper') !== null || 40 document.querySelector('.block-editor-block-preview__content') !== null; 41} 42 43/** 44 * Disable click events on gallery images in Gutenberg editor 45 */ 46function disableEditorClicks() { 47 if (!isGutenbergEditor()) { 48 return; 49 } 50 51 const galleryLinks = document.querySelectorAll('.mtv_gallery .mtv_gallery_item a.mtv-img-wrapper'); 52 53 galleryLinks.forEach(link => { 54 link.style.pointerEvents = 'none'; 55 link.style.cursor = 'default'; 56 57 link.addEventListener('click', function (e) { 58 e.preventDefault(); 59 e.stopPropagation(); 60 return false; 61 }, true); 62 63 const img = link.querySelector('img'); 64 if (img) { 65 img.style.pointerEvents = 'none'; 66 img.style.cursor = 'default'; 67 } 68 }); 69} 70 71/** 72 * Initialize grid layout columns CSS variable 73 */ 74function initGridLayout() { 75 const gridGalleries = document.querySelectorAll('.mtv_gallery.layout-grid'); 76 77 gridGalleries.forEach(gallery => { 78 const columns = gallery.getAttribute('data-columns') || 3; 79 gallery.style.setProperty('--grid-columns', columns); 80 }); 81} 82 83// Initialize gallery when DOM is ready 84document.addEventListener('DOMContentLoaded', function() { 85 if (document.querySelector('.mtv_gallery')) { 86 initGridLayout(); 87 disableEditorClicks(); 88 window.mtvLoadAndInitGallery(); 89 } 90 document.dispatchEvent(new Event('mtvGalleryScriptLoaded')); 91}); 92 93document.addEventListener('ewp_dynamic_block_on_change', function (e) { 94 if (e.detail.block.script == 'mtv-gallery-block-script') { 95 initGridLayout(); 96 disableEditorClicks(); 97 mtvLoadAndInitGallery(); 98 } 99});
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.