Implemented XF.ajax needs an option to hide the XF.ActivityIndicator

Jawsh

Active member
I am developing something that has AJAX stuff running a lot. The activity indicator is extremely irritating and distracting. This has been a consistent issue with XF's JS library even in XF1, and I've dealt with it by just force-hiding the indicator. I'd really like to show indicators for other concurrent AJAX activity, though. Please add something for this.
 
Upvote 0
This suggestion has been implemented. Votes are no longer accepted.
It's already possible. Pretty sure, in fact, it was similarly possible in XF1.

Either way, for XF2, you pass an option to XF.ajax and the AJAX indicator won't load:

JavaScript:
XF.ajax('post', href, { global: false }, XF.proxy(this, 'handleAjax'));

The global option here is what triggers the underlying jQuery AJAX library to trigger global jQuery events ajaxStart and ajaxStop to fire or not. These are the events we listen to and we start/stop the action indicator accordingly. Setting it to false means they don't fire, which means we don't start/stop the indicator.

As I say, pretty sure it was possible in a similar way in XF1.
 
@Chris D I don't think so. I'm using a global:false flag and it's not affecting anything. There are some core.js global references but they're in jQuery.ajax references. I don't know if that affects the calls on these events?

Code:
            $(document).on({
                ajaxStart: show,
                'xf:action-start': show,
                ajaxStop: hide,
                'xf:action-stop': hide
            });

Like, does global:false make it so that the event doesn't cascade to the document object? It doesn't seem to do that.

Edit: Your second paragraph addresses this, but perhaps the global flag doesn't affect the xf:action-start events. I'll poke around.

Edit 2: with jQuery.ajax it does work but it robs me of the built in xf data plugins I would prefer to keep.
 
Last edited:
Yeah, not sure if you actually read my post in full, there. To reiterate, passing global: false will tell $.ajax not to fire the ajaxStart and ajaxStop events. You can see that documented here:

http://api.jquery.com/jquery.ajax/

xf:action-start and xf:action-stop are custom events that allow us to show the action indicator on demand, even if it's not an AJAX request. IIRC we only use this in precisely one location, and otherwise these events wouldn't be fired.

I did, however, make a mistake in my code example, I think.

In my example the parameter is being passed into the URL data. It should look more like this:
JavaScript:
XF.ajax('post', href, {}, XF.proxy(this, 'handleAjax'), { global: false });
 
Top Bottom