Google Groups Home
Help | Sign in
ajaxStart / ajaxStop and Global Triggers..
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
oderwat@googlemail.com  
View profile
 More options Feb 6, 4:16 pm
From: "oder...@googlemail.com" <oder...@googlemail.com>
Date: Wed, 6 Feb 2008 13:16:07 -0800 (PST)
Local: Wed, Feb 6 2008 4:16 pm
Subject: ajaxStart / ajaxStop and Global Triggers..
If you use ajaxStart or any other global trigger. The event.trigger()
code calls itself on all elements in the page by calling $('*') and
adding document and window to this collection.

This leads to some problems for me. A recent project has about 3300
elements if you do a $('*').size().

I have the obvious:

$('#loader').ajaxStart(function() { $(this).show() } ...

code going.

At first I was not even thinking about this to be the problem for the
gui delays. After some testing it was clear the delay is only
happening when I have the ajaxStart/ajaxStop callbacks.

To solve this problem I tried 2 things:

1. Limit the elements collected for the call of event.trigger without
an element by adding a new nodes selector. I named it :event and it
test against jQuery.data(a,"handle") to select only nodes which have a
jQuery event handler. This selector may be of interest for other
purposes too..

At least this is what I understand (I just jumped into the code for 30
minutes) what I did.

In 1.2.2 this would change the following code

                        // :animated
                        animated: "jQuery.grep(jQuery.timers,function(fn){return
a==fn.elem;}).length",

                        // :event
                        event: 'jQuery.data(a, "handle")'

and

                // Handle a global trigger
                if ( !elem ) {
                        // Only trigger if we've ever bound an event for it
                        if ( this.global[type] )
                                jQuery("*:event").add([window, document]).trigger(type, data);

But it still does a lot of "work" for a simple ajax activity
indicator... so I added another possibility.. less "cool" but way
better for the cpu-cycles:

2. I simply extendet axajSetup with 2 (yes only the 2 i need)
callbacks. Code changes are:

        ajaxSettings: {
                global: true,
                type: "GET",
                timeout: 0,
                ajaxStart: null,
                ajaxStop: null,
                contentType: "application/x-www-form-urlencoded",

and...

                // Watch for a new set of requests
                if ( s.global && ! jQuery.active++ ) {
                                if (jQuery.isFunction(s.ajaxStart)) {
                                        s.ajaxStart()
                                }
                                jQuery.event.trigger( "ajaxStart" );

and...

                        // Handle the global AJAX counter
                        if ( s.global && ! --jQuery.active )
                                if (jQuery.isFunction(s.ajaxStop)) {
                                        s.ajaxStop()
                                }
                                jQuery.event.trigger( "ajaxStop" );

usage is clear:

$.ajaxSetup({ 'ajaxStart': function(){
  $("#loading").show();

}, 'ajaxStop': function(){

  $("#loading").hide();

}});

...

I did NOT do a nice DIFF.. no Line-Numbers.. and I am not going to
contribute into SVN... because I have no time.. do what you want with
my changes.. if at all.

Sinverely,
 Hans Raaf


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Serduke  
View profile
 More options Feb 7, 12:00 pm
From: David Serduke <davidserd...@gmail.com>
Date: Thu, 7 Feb 2008 09:00:57 -0800 (PST)
Local: Thurs, Feb 7 2008 12:00 pm
Subject: Re: ajaxStart / ajaxStop and Global Triggers..
I can imagine this could cause problems so I went ahead and opened a
ticket and proposed my own idea too.

http://dev.jquery.com/ticket/2298

David


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hans Raaf  
View profile
 More options Feb 7, 3:12 pm
From: Hans Raaf <oder...@googlemail.com>
Date: Thu, 7 Feb 2008 12:12:29 -0800 (PST)
Local: Thurs, Feb 7 2008 3:12 pm
Subject: Re: ajaxStart / ajaxStop and Global Triggers..
I was thinking about the same solution as you propose... before I was
implementing the simple and cpu friendly call back function listed in
2.

I am not clear about what impacts the changes in 1. have... I guess
"native" triggers like "onclick" would not trigger anymore.. I did not
test it..

On 7 Feb., 18:00, David Serduke <davidserd...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google