HEX
Server: nginx/1.18.0
System: Linux mail.dakarash.co.id 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User: www-data (33)
PHP: 8.1.2-1ubuntu2.23
Disabled: NONE
Upload Files
File: /home/dakarash.co.id/public_html/plugins/visual-portfolio/assets/js/3rd/plugin-jetpack.js
import $ from 'jquery';
import { debounce } from 'throttle-debounce';

let jetpackLazyImagesLoadEvent;
try {
	jetpackLazyImagesLoadEvent = new Event('jetpack-lazy-images-load', {
		bubbles: true,
		cancelable: true,
	});
} catch (e) {
	jetpackLazyImagesLoadEvent = document.createEvent('Event');
	jetpackLazyImagesLoadEvent.initEvent(
		'jetpack-lazy-images-load',
		true,
		true
	);
}

// Fix AJAX loaded images.
$(document).on('loadedNewItems.vpf', function (event) {
	if (event.namespace !== 'vpf') {
		return;
	}

	$('body').get(0).dispatchEvent(jetpackLazyImagesLoadEvent);
});

// Fix masonry reloading when Jetpack images lazy loaded.
// https://github.com/Automattic/jetpack/issues/9595
//
// p.s. it looks like this fix is not working at all in Safari browser.
const runReLayout = debounce(200, ($gallery) => {
	$gallery.vpf('imagesLoaded');
});

$(document.body).on('jetpack-lazy-loaded-image', '.vp-portfolio', function () {
	const $this = $(this).closest('.vp-portfolio');

	if ($this && $this.length) {
		runReLayout($this);
	}
});