Google Groups Home
Help | Sign in
Message from discussion New event: elementReady
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
Bennett McElwee  
View profile
 More options Aug 5 2007, 6:15 pm
From: Bennett McElwee <bennettmcel...@gmail.com>
Date: Sun, 05 Aug 2007 22:15:39 -0000
Local: Sun, Aug 5 2007 6:15 pm
Subject: Re: New event: elementReady
On Aug 1, 12:22 am, "Brandon Aaron" <brandon.aa...@gmail.com> wrote:

> I believe there are two different trains of thought in this thread.

Yes. The behaviour plugin is an excellent piece of software, but it
does not address the problem I posted about.

> The
> original thread starter is [...] talking about an event to fire before
> document ready. An event that will fire once a single element and/or its
> contents are available.

Exactly. Here's the documentation for the Yahoo UI version of this,
which does just what I want:

static void onAvailable  ( p_id , p_fn , p_obj , p_override )
Executes the supplied callback when the item with the supplied id is
found. This is meant to be used to execute behavior as soon as
possible as the page loads. If you use this after the initial page
load it will poll for a fixed time for the element. The number of
times it will poll and the frequency are configurable. By default it
will poll for 10 seconds.

The callback is executed with a single parameter: the custom object
parameter, if provided.

Parameters:
    p_id <string> the id of the element to look for.
    p_fn <function> what to execute when the element is found.
    p_obj <object> an optional object to be passed back as a parameter
to p_fn.
    p_override <boolean|object> If set to true, p_fn will execute in
the scope of p_obj, if set to an object it will execute in the scope
of that object

Returns: void

> I thought about writing this a while back but
> document ready has suited my needs and I just haven't found the time.

Here's a simple example of where jQuery.ready is insufficient. A large-
ish page (50kb) uses jQuery.ready to add rounded corners to the header
at the top of the page. The title displays straight away with square
corners; then the rest of the page loads (a delay of a second); then
jQuery.ready fires and the corners abruptly become rounded. If we
rounded the corners as soon as the header was available then the user
experience would be smoother.

Another poster was worried about poor performance if the technique is
applied to many elements. The obvious remedy is: don't apply it to
many elements. :) Actually, the Yahoo UI code simply adds each
monitored element to a list, and runs through the list every 10ms
doing getElementByID for each item to see if it's available yet. It
would be easy to construct a situation where this killed performance,
but used judiciously it has not caused any problems for me at least.

Cheerio,
Bennett.


    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.

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