Callback Functions
A JavaScript callback is a function which 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 allow you to trigger custom functions based on the events.
To utilize the following callback functions, copy and paste a code example below into your sites JavaScript file.
- almFiltersActive
- almFiltersChange
- almFiltersComplete
- almFiltersURLUpdate
- almFiltersFormatRangeValues
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.
1 2 3 4 5 6 |
// custom.js // {obj} is the object containing filter key/value pairs // e.g. {postType:post,category:design} window.almFiltersActive = function(obj){ console.log(obj); } |
almFiltersChange()
The almFiltersChange() callback function is dispatched when a filter change event is triggered.
1 2 3 4 |
// custom.js window.almFiltersChange = function(){ console.log('Filtering has started...'); } |
almFiltersComplete()
The almFiltersComplete() callback function is dispatched after the filter process has completed.
1 2 3 4 |
// custom.js window.almFiltersComplete = function(){ console.log('Ajax filtering has completed!'); } |
almFiltersURLUpdate()
The almFiltersURLUpdate() callback function is dispatched after the browser URL has been updated.
1 2 3 4 |
// custom.js window.almFiltersURLUpdate = function(url){ console.log('Browser URL has been updated to ' + url); } |
almFiltersFormatRangeValues()
The almFiltersFormatRangeValues() callback function provides a method to format the display labels for the start and end value of the Range Slider field type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
/** * Format the Range Slider display label. * ./custom.js * * @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; } |