Callback Functions

Each Javascript callback function is dispatched directly from core Ajax Load More or one of the various add-ons. To utilize the following callback functions copy and paste a code example below into your site’s JavaScript file.


Change

almOnChange() is dispatched at the beginning of each Ajax Load More query.

window.almOnChange = function(alm){
	console.log("Ajax Load More is loading...");
};
JavaScript

Complete

almComplete() is dispatched after every successful Ajax Load More query – Learn More.

window.almComplete = function(alm){
	console.log("Ajax Load More Complete!");
};
JavaScript

Note: The alm object returned in the callback contains information about the current Ajax Load More instance. You can locate the most recently added content by accessing the el attribute of the alm object.

window.almComplete = function(alm){
	console.log( alm.last_loaded ); // <- Returns array of most recently loaded HTML elements.
};
JavaScript

Are you looking for examples?
You’re in luck, we are compiling a list of callback examples in use by Ajax Load More users.


Destroyed

almDestroyed() is dispatched after the destroy_after shortcode parameter is triggered.

window.almDestroyed = function(alm){
	console.log("Ajax Load More functionality has been destroyed!");
};
JavaScript

Done

almDone() is dispatched after all posts have been loaded and there are zero posts remaining.

window.almDone = function(){
	console.log('All posts have been loaded!');
};
JavaScript

Empty

almEmpty() is dispatched when zero results are returned in the initial Ajax Load More query.

window.almEmpty = function(alm){
	var el = alm.listing;
	var msg = 'Sorry, nothing found in this Ajax Load More query';
	
	var item = document.createElement('li');
	item.innerHTML = msg;
	el.appendChild(item); // Append to ALM
	
	//console.log("Nothing found in this Ajax Load More query :(");
};
JavaScript

Filter Complete

almFilterComplete() is dispatched after a successful call to the public function almFilter().

window.almFilterComplete = function(){
	console.log('Ajax Load More filter has completed!');
};
JavaScript

Load

almOnLoad() is dispatched when Ajax Load More initializes.

window.almOnLoad = function(alm){
	console.log("Ajax Load More is now loaded");
};
JavaScript

URL Update

almUrlUpdate() is dispatched after a successful URL update (pushState) from the Single Post, Filters and Search Engine Optimization add-on.

window.almUrlUpdate = function(permalink, type){
	// type = From which addon (previous-post | seo)
	// permalink = the updated url
	console.log("URL updated to " + permalink + '- dispatched from the '+ type + ' add-on.');
};
JavaScript

Note: Your site JavaScript functions file must be loaded after Ajax Load More to trigger callbacks.