1(function() { 2 'use strict'; 3 4 function debounce(fn, delay) { 5 let timeout; 6 return function() { 7 const context = this; 8 const args = arguments; 9 clearTimeout(timeout); 10 timeout = setTimeout(function() { 11 fn.apply(context, args); 12 }, delay); 13 }; 14 } 15 16 function initMasonryGrid(grid) { 17 if (!grid) { 18 return; 19 } 20 21 const gutter = parseInt(grid.getAttribute('data-masonry-gutter'), 10) || 24; 22 23 const masonryInstance = new Masonry(grid, { 24 itemSelector: '.portfolio-gallery-masonry-item', 25 columnWidth: '.portfolio-gallery-masonry-sizer', 26 gutter: gutter, 27 percentPosition: true, 28 transitionDuration: '0.3s' 29 }); 30 31 const images = grid.querySelectorAll('img'); 32 33 if (!images.length) { 34 masonryInstance.layout(); 35 return masonryInstance; 36 } 37 38 let loadedImages = 0; 39 const totalImages = images.length; 40 41 const updateLayout = function() { 42 loadedImages += 1; 43 if (loadedImages >= totalImages) { 44 masonryInstance.layout(); 45 } 46 }; 47 48 images.forEach(function(image) { 49 if (image.complete && image.naturalWidth !== 0) { 50 updateLayout(); 51 } else { 52 image.addEventListener('load', updateLayout, { once: true }); 53 image.addEventListener('error', updateLayout, { once: true }); 54 } 55 }); 56 57 window.addEventListener('resize', debounce(function() { 58 masonryInstance.layout(); 59 }, 200)); 60 61 return masonryInstance; 62 } 63 64 document.addEventListener('DOMContentLoaded', function() { 65 if (typeof Masonry === 'undefined') { 66 console.warn('Masonry library is not loaded. Portfolio masonry layout cannot be initialized.'); 67 return; 68 } 69 70 const grids = document.querySelectorAll('[data-masonry-grid]'); 71 72 if (!grids.length) { 73 return; 74 } 75 76 grids.forEach(function(grid) { 77 initMasonryGrid(grid); 78 }); 79 }); 80})(); 81
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.