Forums › Forums › Search & Filter Pro › How does making a simple loader work in SFP
- This topic has 8 replies, 2 voices, and was last updated 8 years, 10 months ago by Ross.
-
Anonymous(Private) January 13, 2016 at 10:47 am #34098
Hi,
I was wondering, is there anymore documentation on how to make a simple loading message appear when you do a request? I have read this article (http://www.designsandcode.com/wordpress-plugins/search-filter-pro/faqs/) but I don’t know what to do and where to place this code:
//detects the start of an ajax request being made
$(document).on(“sf:ajaxstart”, “.searchandfilter”, function(){
console.log(“ajax start”);
});//detects when the ajax request has finished and the content has been updated
// – add scripts that apply to your results here
$(document).on(“sf:ajaxfinish”, “.searchandfilter”, function(){
console.log(“ajax complete”);
//so load your lightbox or JS scripts here again
});//an event fired when S&F is initialised and S&F scripts have been loaded
$(document).on(“sf:init”, “.searchandfilter”, function(){
console.log(“S&F JS initialised”);
});Can anyone help me?
Ross Moderator(Private) January 13, 2016 at 5:03 pm #34160Hey Edward
Ok, this is more a developer feature for now until I add something via the UI to make this easier.
Essentially, what you want to do is the following:
1) Create your loader and add it to your page / site.
So as a really basic example (by no means comprehensive or complete) – edit your themes “footer.php”.
Before the closing
</body>
tag add the following html code:<div class="sf-loader" style="display:none"> Loading... </div>
This will add an element to your page to use as a loader. This will need to be customised via CSS, such as centering it on the page etc but for now thats not important.
2) Add the loader code.
In your themes main JavaScript file, scroll the to very end, and after everything else add:
jQuery(document).ready(function($) { $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ $('.sf-loader').hide(); }); $(document).on("sf:ajaxstart", ".searchandfilter", function(){ $('.sf-loader').show(); }); });
now you will see an element on your site being shown/hidden when being loaded. As mentioned you will need to style it up.
Hope that helps!
Thanks
Ross Moderator(Private) January 14, 2016 at 4:09 pm #34256This code should go inside a script file (JS file).
Normally you would add this code into an already existing script file in your theme (it differs from theme to theme, so can’t advise) – but creating a whole new file and loading it in is also fine.
Just make sure when loading the script you have jquery as a dependency.
Thanks
-
AuthorPosts