You can register a so-called Ajax.Responder globally for the onLoading event of Prototype Ajax requests. This would fire for every remoteFunction/Ajax call in your page. To do that you should put something like this somewhere into your gsp page or the layout:
<script type="text/javascript">
function showSpinner() {
// TODO show spinner
}
function hideSpinner() {
// TODO hide spinner
}
Ajax.Responders.register({
onLoading: function() {
showSpinner();
},
onComplete: function() {
if(!Ajax.activeRequestCount) hideSpinner();
}
});
</script>
You'd need to implement the showSpinner and hideSpinner function of course. As a complete example, you could use something like:
<script type="text/javascript">
function showSpinner() {
$('spinner').show();
}
function hideSpinner() {
$('spinner').hide();
}
Ajax.Responders.register({
onLoading: function() {
showSpinner();
},
onComplete: function() {
if(!Ajax.activeRequestCount) hideSpinner();
}
});
</script>
<div id="spinner" style="display: none;">
<img src="${createLinkTo(dir:'images',file:'spinner.gif')}" alt="Loading..." width="16" height="16" />
</div>