When using the Prototype framework, I decided to register each Ajax call with Ajax.Responders.register. The main goal was to display an Ajax Spinner only when a request is in progress. However, if a request is completed quickly, there is no need to show the spinner. In order to achieve this, I have to access the parameters of the request to check for specific flags or conditions.
The code snippet below showcases the current implementation:
var Ajax;
if (Ajax && (Ajax != null)) {
Ajax.Responders.register( {
onCreate : function(transport) {
console.log("Test");
console.log("Parameters: " + transport);
if (Ajax.activeRequestCount > 0) {
Effect.Appear('loading', {
duration : 0.5,
queue : 'end'
});
//new Effect.toggle('loading', 'appear');
new Effect.Opacity('page', { from: 1.0, to: 0.3, duration: 0.7 });
Mask.centerSpinner('loading');
}
},
onComplete : function() {
if (Ajax.activeRequestCount == 0) {
Effect.Fade('loading', {
duration : 0.5,
queue : 'end'
});
//new Effect.toggle('loading', 'appear');
new Effect.Opacity('page', { from: 0.3, to: 1, duration: 0.7 });
}
}
});
}