Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save VictorPietro/4fae4b1f5ada67fe1dc217d24430559b to your computer and use it in GitHub Desktop.

Select an option

Save VictorPietro/4fae4b1f5ada67fe1dc217d24430559b to your computer and use it in GitHub Desktop.
Retrigger After Jet Engine "Load More" event handler
// ## Description
// This code listens for the `jet-engine/listing-grid/after-load-more` event triggered by JetEngine's infinite scroll or "load more" feature. When the event is fired (i.e., new content is loaded into the listing grid), it reinitializes custom scripts by calling the `initializeCustomScripts` function.
// ## How to Use
// 1. Ensure you have a function named `initializeCustomScripts` defined in your JavaScript. This function will handle reinitialization of any custom functionality for the newly loaded content.
// 2. Include this script in your project. It will automatically attach a listener to the `jet-engine/listing-grid/after-load-more` event.
// 3. Check the browser console for the log message: `"Infinite scroll content loaded (after-load-more). Reinitializing custom scripts..."` to confirm the event is being detected.
(($) => {
$(document).ready(function () {
// Listen for the 'jet-engine/listing-grid/after-load-more' event
$(document).on('jet-engine/listing-grid/after-load-more', function () {
console.log('Infinite scroll content loaded (after-load-more). Reinitializing custom scripts...');
if (typeof initializeCustomScripts === 'function') {
initializeCustomScripts();
} else {
console.error('initializeCustomScripts function is not defined.');
}
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment