views:

25

answers:

1

Hi at all,

I am registering each Ajax call with Ajax.Responders.register of the Prototype framework. The idea was to render an Ajax Spinner if a request is open. But when a request only needs some millis, then I wouldn't show the ajax spinner. But therefore I need the parameters of the request to check for example a flag in the parameters.

The code snippet of the actual implementation is pasted below.

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 });
            }
        }
    });
}
A: 

I found the solution:

var Ajax;
if (Ajax && (Ajax != null)) {
    Ajax.Responders.register( {
        onCreate : function(transport) {
            if (Ajax.activeRequestCount > 0 && transport.options.parameters.disabledAjaxSpinner==undefined) {
                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(transport) {
            if (Ajax.activeRequestCount == 0 && transport.options.parameters.disabledAjaxSpinner==undefined) {
                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 });
            }
        }
    });
}
Fabian