Callback Functions
A JavaScript callback is a function that is executed after another function has finished execution. The Ajax Load More Filters add-on dispatches callbacks at various stages of the filtering process that allows you to trigger custom functions based on the events.
To utilize the following callback functions, copy and paste a code example below into your site’s JavaScript file.
almFiltersActive()
The almFiltersActive() callback function is dispatched after a filter submit action and returns an object containing the key/value pair combinations of active filters.
// {obj} is the object containing filter key/value pairs
// e.g. {postType:post,category:design}
window.almFiltersActive = function(obj){
console.log(obj);
}
JavaScriptalmFiltersChange()
The almFiltersChange() callback function is dispatched when a filter change event is triggered.
window.almFiltersChange = function(){
console.log('Filtering has started...');
}
JavaScriptalmFiltersComplete()
The almFiltersComplete() callback function is dispatched after the filter process has completed.
window.almFiltersComplete = function(){
console.log('Ajax filtering has completed!');
}
JavaScriptalmFiltersURLUpdate()
The almFiltersURLUpdate() callback function is dispatched after the browser URL has been updated.
window.almFiltersURLUpdate = function(url){
console.log('Browser URL has been updated to ' + url);
}
JavaScriptalmFiltersFormatRangeValues()
The almFiltersFormatRangeValues() callback function provides a method to format the display labels for the start and end values of the Range Slider field type.
/**
* Format the Range Slider display label.
*
* @param {string} id The current ID of the filter.
* @param {object} values An object of start and end values.
* @return {object}
*/
window.almFiltersFormatRangeValues = function (id, values) {
console.log(values); // { start: a, end: b}
// Add a comma to value if needed to start and end values.
values.start = values.start.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
values.end = values.end.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return values;
}
JavaScript