Google Groups Home Help | Sign in
New event: elementReady
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
  15 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
Bennett McElwee  
View profile
 More options Jul 30 2007, 8:52 pm
From: Bennett McElwee <bennettmcel...@gmail.com>
Date: Tue, 31 Jul 2007 00:52:30 -0000
Local: Mon, Jul 30 2007 8:52 pm
Subject: New event: elementReady
jQuery currently does not give the ability to run a function when a
specific element is loaded into the DOM. Other libraries have this
ability and it would be a useful addition. It's not in the 1.2 roadmap
or in any plugin that I have found, so I was wondering if it has been
considered.

This feature would be similar to jQuery.ready() except that it would
apply to a specific element instead of the whole document. I imagine
the declaration would be something like
    jQuery.elementReady(id, fn)
which would call the given function as soon as an element with the
given ID is available in the DOM.

The Yahoo UI library has two variants of this (onAvailable and
onContentReady), which work by polling. (See
http://developer.yahoo.com/yui/docs/YAHOO.util.Event.html) I think
other libraries also include this function. I'm sure it could be added
to jQuery, though code size is always the concern.

Has anyone thought about this, or even worked on it?

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.
Steve Clay  
View profile
 More options Jul 30 2007, 9:29 pm
From: Steve Clay <st...@mrclay.org>
Date: Mon, 30 Jul 2007 21:29:14 -0400
Local: Mon, Jul 30 2007 9:29 pm
Subject: Re: [jquery-dev] New event: elementReady

Bennett McElwee wrote:
> jQuery currently does not give the ability to run a function when a
> specific element is loaded into the DOM. Other libraries have this

http://brandonaaron.net/jquery/plugins/behavior/
Looks very flexible (you assign behaviors based on selectors). I've
never used it, but the author implies quality.

--
Steve Clay
http://mrclay.org/


    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.
Yehuda Katz  
View profile
 More options Jul 31 2007, 1:47 am
From: "Yehuda Katz" <wyc...@gmail.com>
Date: Mon, 30 Jul 2007 22:47:57 -0700
Local: Tues, Jul 31 2007 1:47 am
Subject: Re: [jquery-dev] Re: New event: elementReady

In fact, this was originally considered for inclusion into 1.2, but will
probably not quite make it just yet. However, we're definitely encouraging
people to use it and let Brandon (and the jQuery team) know about any weird
issues that arise.

-- Yehuda

On 7/30/07, Steve Clay <st...@mrclay.org> wrote:

--
Yehuda Katz
Web Developer | Procore Technologies
(ph)  718.877.1325

    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.
Sam Collett  
View profile
 More options Jul 31 2007, 6:56 am
From: "Sam Collett" <sam.coll...@gmail.com>
Date: Tue, 31 Jul 2007 11:56:00 +0100
Subject: Re: [jquery-dev] Re: New event: elementReady
Doesn't it require periodically running a script (via setInterval I
presume?) to check if the element is ready? If applied to many
elements, could it be detrimental to performance?

I can see the benefit of attaching a function automatically to any new
elements added via add, pre/append etc (for example, when you are
cloning form fields with validation applied to them).

On 31/07/07, Yehuda Katz <wyc...@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.
Brandon Aaron  
View profile
 More options Jul 31 2007, 8:22 am
From: "Brandon Aaron" <brandon.aa...@gmail.com>
Date: Tue, 31 Jul 2007 07:22:24 -0500
Local: Tues, Jul 31 2007 8:22 am
Subject: Re: [jquery-dev] Re: New event: elementReady

I believe there are two different trains of thought in this thread. The
original thread starter is not talking about a behavior type plugin where
when the DOM is updated events and or functions are applied to matching
elements. Instead he is actually talking about an event to fire before
document ready. An event that will fire once a single element and/or its
contents are available. I thought about writing this a while back but
document ready has suited my needs and I just haven't found the time. I
think to do it right someone has to create an "available" method and rework
the existing "ready" method to work for both document and elements.

At least I think that is the case. :)

Oh and please use the behavior plugin! Test it and let us know if it works
or not. There have been some interesting use-cases develop around it and I
want to know how you might use it. :)

--
Brandon Aaron

On 7/31/07, Sam Collett <sam.coll...@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.
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.
John Resig  
View profile
 More options Aug 5 2007, 6:25 pm
From: "John Resig" <jere...@gmail.com>
Date: Sun, 5 Aug 2007 18:25:10 -0400
Local: Sun, Aug 5 2007 6:25 pm
Subject: Re: [jquery-dev] Re: New event: elementReady
Sounds like a great opportunity to build a plugin! :-) The best way to
get functionality into jQuery core is to prove its usefulness through
a plugin. If people start using a plugin all the time, then it becomes
obvious that it should be in core (which is what's happening with the
Dimensions plugin and part of the forms plugin).

--John

On 8/5/07, Bennett McElwee <bennettmcel...@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.
Bennett McElwee  
View profile
 More options Aug 5 2007, 7:17 pm
From: Bennett McElwee <bennettmcel...@gmail.com>
Date: Sun, 05 Aug 2007 23:17:01 -0000
Local: Sun, Aug 5 2007 7:17 pm
Subject: Re: New event: elementReady
On Aug 6, 10:25 am, "John Resig" <jere...@gmail.com> wrote:

> Sounds like a great opportunity to build a plugin! :-) The best way to
> get functionality into jQuery core is to prove its usefulness through
> a plugin.

Thanks for that. I was planning to put something together myself, but
I didn't want to duplicate effort in case somebody else had already
done it. I will add this plugin task to my to-do list. But if anyone
else out there feels like having a go as well, don't let me stop you!

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.
Erik Beeson  
View profile
 More options Aug 6 2007, 5:35 am
From: "Erik Beeson" <erik.bee...@gmail.com>
Date: Mon, 6 Aug 2007 02:35:47 -0700
Local: Mon, Aug 6 2007 5:35 am
Subject: Re: [jquery-dev] Re: New event: elementReady
hmm, this is easy enough if you just do it the old school way:

<body>
[headers to round]
<script ...> /* do corner rounding on header stuff */ </script>
[the rest of the page that takes a while to load]
</body>

Is there a reason that won't work or isn't ideal? Since you know
exactly when you want the corner rounding to start, seems like you
shouldn't need to mess around with callback voodoo...

--Erik

On 8/5/07, Bennett McElwee <bennettmcel...@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.
Klaus Hartl  
View profile
 More options Aug 6 2007, 5:37 am
From: Klaus Hartl <klaus.ha...@stilbuero.de>
Date: Mon, 06 Aug 2007 11:37:44 +0200
Local: Mon, Aug 6 2007 5:37 am
Subject: Re: [jquery-dev] Re: New event: elementReady

Erik Beeson wrote:
> hmm, this is easy enough if you just do it the old school way:

> <body>
> [headers to round]
> <script ...> /* do corner rounding on header stuff */ </script>
> [the rest of the page that takes a while to load]
> </body>

> Is there a reason that won't work or isn't ideal? Since you know
> exactly when you want the corner rounding to start, seems like you
> shouldn't need to mess around with callback voodoo...

> --Erik

Even more old school, you could even do it with pure CSS ;-)

--Klaus


    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.
Erik Beeson  
View profile
 More options Aug 6 2007, 5:50 am
From: "Erik Beeson" <erik.bee...@gmail.com>
Date: Mon, 6 Aug 2007 02:50:43 -0700
Local: Mon, Aug 6 2007 5:50 am
Subject: Re: [jquery-dev] Re: New event: elementReady

> Even more old school, you could even do it with pure CSS ;-)

True. But then you end up with either fixed sized boxes, or fairly hairy,
un-semantic markup, or both. It's all about markup that starts out clean and
is completely abused by JavaScript to be made roundy. ShadedBorder creates
1153 divs to make rounded corners. Imagine doing that by hand ;) Ouch.

I'm still waiting for browsers to support border-radius properly... and
waiting, and waiting, and waiting...

--Erik


    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.
Bennett McElwee  
View profile