Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Waiter with Request.HTML #66

Open
appaulo14 opened this issue Jun 19, 2010 · 1 comment
Open

Using Waiter with Request.HTML #66

appaulo14 opened this issue Jun 19, 2010 · 1 comment

Comments

@appaulo14
Copy link

Although it works fine in the Clientcide demo (http://www.clientcide.com/wiki/cnet-libraries/07-ui/11-waiter#ajax-integration), using a waiter with the useWaiter option of Request.HTML does not work for me. The waiter does not appear over the target.\n\n To examine the problem, I created two mooshells. The first at http://mootools.net/shell/fkuhA/4/ uses a direct copy of the clientcide demo. After running it and examining the result with firebug, I realized that instead of an image being inserted over the target element, only an empty div with a class of "spinner-img" was inserted. I tried setting the 'img' options inside the waiterOptions section, but all those options were apply to the "spinner-img" div. Since Waiter inherits from Spinner, I looked up the Spinner class documentation and found that applying options to the 'img' section alters the "spinner-img" div rather than the image, which is different than how the non-Request.HTML Waiter does it. \n\n A workaround that I created for now was to put the full html for an image into the 'html' option of the 'img' option of 'waiterOptions' in the Request.HTML options, as demonstrated in my second MooShell : http://mootools.net/shell/fGS4w/3/ .

@appaulo14
Copy link
Author

Here's a little more elegant and customizable solution using Class.refactor. This should allow for all of the waiter options that are normally available.

//Fix for the useWaiter Request Bug

Request = Class.refactor(Request,{
initialize: function (options){
//If we are using a waiter
if (options.useWaiter && (options.waiterTarget || options.update)){
//Call the previous without using its Waiter method
options.useWaiter = false;
this.previous(options);
this.options.useWaiter = true;

        //Create a waiter
        var waiterTarget = options.waiterTarget || options.update;
        this.waiter = new Waiter(waiterTarget, options.waiterOptions);

        //Add event triggers to start and stop the waiter
        this.addEvent('request', function(){
            this.waiter.start();
        }.bind(this));
        ['onComplete', 'onException', 'onCancel'].each(function(event){
            this.addEvent(event, function(){
                //Stop the waiter
                this.waiter.stop();
                //Destroy the waiter residue from the page
                this.waiter.destroy();
            });
        }, this);
    }
    //If not using a waiter, just run the previous stuff
    else{
        this.previous(options);
    }
}

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant