Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Will the live() method be improved in 1.4?
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
  Messages 1 - 25 of 32 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
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
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
xwisdom  
View profile  
 More options Nov 4, 8:44 pm
From: xwisdom <xwis...@gmail.com>
Date: Wed, 4 Nov 2009 17:44:13 -0800 (PST)
Local: Wed, Nov 4 2009 8:44 pm
Subject: Will the live() method be improved in 1.4?
Hello,

Just wondering if version 1.4 will include improvements to live()
events.

See example here:
http://www.zachleat.com/web/2009/05/08/performance-caveat-with-jquery...


    Reply    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 Nov 4, 8:57 pm
From: John Resig <jere...@gmail.com>
Date: Thu, 5 Nov 2009 02:57:21 +0100
Local: Wed, Nov 4 2009 8:57 pm
Subject: Re: [jquery-dev] Will the live() method be improved in 1.4?
Yes, 1.4 will include improvements to the live event.

Specifically though this blog post is discussing the ability to not
run the initial selector if all you're doing is binding a live event
(they proposed a $.live). It's not clear if we'll be landing this
specific functionality in jQuery 1.4.

--John


    Reply    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.
xwisdom  
View profile  
 More options Nov 4, 11:13 pm
From: xwisdom <xwis...@gmail.com>
Date: Wed, 4 Nov 2009 20:13:34 -0800 (PST)
Local: Wed, Nov 4 2009 11:13 pm
Subject: Re: Will the live() method be improved in 1.4?
Hi John,

Thanks for the quick feedback

IMO, I think it would be handy to have something like $.live as I can
see where it would be of great benefit when working with a lot of
elements.


    Reply    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.
furf  
View profile  
 More options Nov 5, 2:08 pm
From: furf <furftas...@gmail.com>
Date: Thu, 5 Nov 2009 11:08:05 -0800 (PST)
Local: Thurs, Nov 5 2009 2:08 pm
Subject: Re: Will the live() method be improved in 1.4?
I've also been among those clamoring for an optimized $.live method
and have a offered similar hack around in the past <http://
blurf.furf.com/2009/09/jquery-live-from-new-york/> (via Paul Irish's
Anti-Patterns). Last night on the flight to jsconf, I hacked up a more
formal patch which puts optimized live and die methods into the jQuery
root and aliases them back to the jQuery instances.

http://github.com/furf/jquery-live/blob/master/jquery.live.js

Unless I'm missing something, I really haven't modified much and these
changes could be integrated into jQuery with two copies and two
pastes.

Hope that helps.


    Reply    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.
Robert Katić  
View profile  
 More options Nov 5, 7:31 pm
From: Robert Katić <robert.ka...@gmail.com>
Date: Thu, 5 Nov 2009 16:31:13 -0800 (PST)
Local: Thurs, Nov 5 2009 7:31 pm
Subject: Re: Will the live() method be improved in 1.4?
I wonder why there would be an $.live with document as the only
interesting context.

Something like

  $(document).zombi(selector, type, ...)

would be more flexible (I know, "zombi" is not nice, but I have no
inspirations about a more suitable name).

To avoid to repeat selector on multiple bindings, I suggest something
like:

  $(document).make(selector)
    .zombi(type, ...)
    .zombi(type, ...)

An possible implementation of that: http://gist.github.com/227508

Maybe this is only a silly idea for majority of users (now), but I am
really of idea that this have even more sense then the current
$.fn.live.

On Nov 5, 2:44 am, xwisdom <xwis...@gmail.com> wrote:


    Reply    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.
Justin Meyer  
View profile  
 More options Nov 5, 8:42 pm
From: Justin Meyer <justinbme...@gmail.com>
Date: Thu, 5 Nov 2009 17:42:01 -0800 (PST)
Local: Thurs, Nov 5 2009 8:42 pm
Subject: Re: Will the live() method be improved in 1.4?
How about $("#something").delegate(".thing","click", func).

It almost makes too much sense :).

On Nov 5, 6:31 pm, Robert Katić <robert.ka...@gmail.com> wrote:


    Reply    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.
Robert Katić  
View profile  
 More options Nov 5, 9:05 pm
From: Robert Katić <robert.ka...@gmail.com>
Date: Fri, 6 Nov 2009 03:05:15 +0100
Local: Thurs, Nov 5 2009 9:05 pm
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
Meyer, "delegate" was my first candidate too but I was worry that it  
was overused :). Seams that I was wrong. Will update it with  
"delegate" ASAP.

--Robert

On 6. stu. 2009., at 02:42, Justin Meyer <justinbme...@gmail.com> wrote:


    Reply    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.
furf  
View profile  
 More options Nov 5, 9:57 pm
From: furf <furftas...@gmail.com>
Date: Thu, 5 Nov 2009 18:57:02 -0800 (PST)
Local: Thurs, Nov 5 2009 9:57 pm
Subject: Re: Will the live() method be improved in 1.4?
I don't think that the method name is at question here, but rather the
unnecessary performance cost of querying a selector before DOMReady
(or even after), ie. $('#anything'), when it is not needed for the
event delegation pattern. The .live method uses only the .selector
property of the jQuery instance and not the actual collection of DOM
elements, so there is no reason to query the DOM, especially before it
is even available.

Also, @robert, my solution supports the following notation, similar to
yours but using the familiar jQuery syntax (before/after DOMReady):
$.live("#mySelector", "click", fn1)
  .live("#mySelector", "mouseover", fn2)
  ...;

as well as (after DOMReady):
$("#mySelector").css("color", "#ff0000")
  .live("click", fn1)
  .live("mouseover", fn2);


    Reply    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 Nov 5, 10:56 pm
From: John Resig <jere...@gmail.com>
Date: Fri, 6 Nov 2009 04:56:47 +0100
Local: Thurs, Nov 5 2009 10:56 pm
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?

> Also, @robert, my solution supports the following notation, similar to
> yours but using the familiar jQuery syntax (before/after DOMReady):
> $.live("#mySelector", "click", fn1)
>  .live("#mySelector", "mouseover", fn2)
>  ...;

I understand the logic behind you wanting a $.live method (for the
edge cases where, presumably, you have hundreds or thousands of
elements that you're trying to match - and you don't want to run the
initial selector). Although there's a lot that I don't like about it:
 - You are now passing in a selector to a non $(...) or .foo() method.
This goes against all the conventions that the library has - when you
interact with DOM elements, stay within the jQuery set.
 - The only case where this matters is in a fringe case (namely, only
when you use both a complicated selector AND run it in IE < 8, since
all other browsers are using querySelectorAll) - but the existence of
the method in jQuery would remove the need to ever use the one method
that everyone should use.
 - Presumably since you're in a situation where you're really caring
about performance - then why are you using .live to begin with?
Shouldn't you be binding lower in the document? This is why the
closest method was added, to make tasks like this even easier.

I would simply recommend: If you're in a situation where you're
starting with a critical number of elements on your page, enough to
ruin your pages' overall performance, then you should use a basic form
of event delegation, like so:

$("#someRootTable").click(function(e){
  $(e.target).closest("td.foo").each(function(){
    // Your code goes here.
  });

});

Which is really what you should be doing anyway (live method or not).

--John


    Reply    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.
Nik Pasaran  
View profile  
 More options Nov 5, 8:18 am
From: Nik Pasaran <nik.pasa...@gmail.com>
Date: Thu, 5 Nov 2009 16:18:34 +0300
Local: Thurs, Nov 5 2009 8:18 am
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
What about something like this:

    $.live = function(selector, type, callback) {
        $.fn.live.call({ selector: selector }, type, callback);
    }


    Reply    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.
Robert Katić  
View profile  
 More options Nov 5, 11:22 pm
From: Robert Katić <robert.ka...@gmail.com>
Date: Fri, 6 Nov 2009 05:22:50 +0100
Local: Thurs, Nov 5 2009 11:22 pm
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?

$("#someRootTable").delegate("td.foo", "click", function(e){
    // Your code goes here.

});

Would be easer and safer because the event will be handlet only by  
"td.foo" elements inside "#someRootTable".

--Robert

On 6. stu. 2009., at 04:56, John Resig <jere...@gmail.com> wrote:


    Reply    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 Nov 5, 11:29 pm
From: John Resig <jere...@gmail.com>
Date: Fri, 6 Nov 2009 05:29:49 +0100
Local: Thurs, Nov 5 2009 11:29 pm
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
If you want to limit, just do this (using the nightlies):

$("#someRootTable").click(function(e){
  $(e.target).closest("td.foo", this).each(function(){
     // Your code goes here.
  });

});

Still pretty simple and requires no additional functionality. I may
just write this up as an example and add it to the live and closest
docs.

--John


    Reply    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.
Robert Katić  
View profile  
 More options Nov 6, 12:12 am
From: Robert Katić <robert.ka...@gmail.com>
Date: Fri, 6 Nov 2009 06:12:06 +0100
Local: Fri, Nov 6 2009 12:12 am
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
I suppose you will need an "return false;" too at the end of the  
handler...

--Robert

On 6. stu. 2009., at 05:29, John Resig <jere...@gmail.com> wrote:


    Reply    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.
Robert Katić  
View profile  
 More options Nov 6, 12:20 am
From: Robert Katić <robert.ka...@gmail.com>
Date: Fri, 6 Nov 2009 06:20:42 +0100
Local: Fri, Nov 6 2009 12:20 am
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
No you will not. My Mistake

--Robert

On 6. stu. 2009., at 05:29, John Resig <jere...@gmail.com> wrote:


    Reply    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.
Robert Katić  
View profile  
 More options Nov 6, 2:29 am
From: Robert Katić <robert.ka...@gmail.com>
Date: Thu, 5 Nov 2009 23:29:50 -0800 (PST)
Local: Fri, Nov 6 2009 2:29 am
Subject: Re: Will the live() method be improved in 1.4?
Regarding improving live(), I would note two things about liveHandler:

1. Calling closest, context argument still is not used.
I was unable to find the proper ticket. Would I open one?

2. Storing "how much a parent is close to an element" with data API is
an big overhead. An jQuery.lastCloser or something similar would be
enough. Also it would speed up sorting inside liveHandler with
somethin like this:

...
       elems.push({ elem: elem, fn: fn, closer: jQuery.lastCloser });
....
  elems.sort(function( a, b ) {
    return a.closer - b.closer;
  });


    Reply    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.
furf  
View profile  
 More options Nov 6, 6:59 am
From: furf <furftas...@gmail.com>
Date: Fri, 6 Nov 2009 03:59:50 -0800 (PST)
Local: Fri, Nov 6 2009 6:59 am
Subject: Re: Will the live() method be improved in 1.4?
Fair enough, @john. I was unaware of the convention regarding
selectors. But isn't "write less, do more" also a convention? ;-)

$("#someRootTable").click(function(e){
  $(e.target).closest("td.foo", this).each(function(){
     // Your code goes here.
  });

});

vs.

$.live("#someRootTable td.foo", "click", function(){
  // Your code goes here.

});

Joking aside, your solution would probably solve our key cases at MLB,
although we would still need to use the live method for rendering and
editing dynamic data. But at least, the (unnecessary) selector is much
faster.

$("#someRootTable").live("click", function(e){
  $(e.target).closest("td.foo", this).each(function(){
     // Your code goes here.
  });

});

On the front end, we are rendering large tables of stats data
regularly and, on the back end, we have several interfaces for
manipulating large data, including an XML editor. In the case of the
XML editor, during common usage, $.live increased rendering
performance over $(...).live from 2s to 9ms by eliminating the need to
collect thousands of nodes and attributes.

We haven't noticed any significant performance issues using document
as the root context at event time. When we're acting on large
collections, the collections are usually the most important data on
the page and therefore not too far down in the DOM.

Thanks for the insights. I look forward to a few more at jsconf.


    Reply    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 Nov 6, 9:01 am
From: John Resig <jere...@gmail.com>
Date: Fri, 6 Nov 2009 15:01:35 +0100
Local: Fri, Nov 6 2009 9:01 am
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?

> 1. Calling closest, context argument still is not used.
> I was unable to find the proper ticket. Would I open one?

> 2. Storing "how much a parent is close to an element" with data API is
> an big overhead. An jQuery.lastCloser or something similar would be
> enough. Also it would speed up sorting inside liveHandler with
> somethin like this:

> ...
>       elems.push({ elem: elem, fn: fn, closer: jQuery.lastCloser });
> ....
>  elems.sort(function( a, b ) {
>    return a.closer - b.closer;
>  });

I'd appreciate tickets/patches for both of these - they both sound
like great additions.

--John


    Reply    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.
lrbabe  
View profile  
 More options Nov 6, 10:40 am
From: lrbabe <lrb...@gmail.com>
Date: Fri, 6 Nov 2009 07:40:15 -0800 (PST)
Local: Fri, Nov 6 2009 10:40 am
Subject: Re: Will the live() method be improved in 1.4?
Adding the context to closest in liveHandler is really an easy thing
to fix...
What we need is a working implementation of the context.
Last time I talked to Brandon Aaron about that (back at the jQuery
conf) he told me that context was broken in his opinion and needed
some additional work before being useful...
Has anything changed?

On Nov 6, 3:01 pm, John Resig <jere...@gmail.com> wrote:


    Reply    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.
Robert Katić  
View profile  
 More options Nov 6, 11:29 am
From: Robert Katić <robert.ka...@gmail.com>
Date: Fri, 6 Nov 2009 08:29:37 -0800 (PST)
Local: Fri, Nov 6 2009 11:29 am
Subject: Re: Will the live() method be improved in 1.4?
event.currentTarget as context is not enough?

On Nov 6, 4:40 pm, lrbabe <lrb...@gmail.com> wrote:


    Reply    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.
lrbabe  
View profile  
 More options Nov 6, 2:48 pm
From: lrbabe <lrb...@gmail.com>
Date: Fri, 6 Nov 2009 11:48:39 -0800 (PST)
Local: Fri, Nov 6 2009 2:48 pm
Subject: Re: Will the live() method be improved in 1.4?
Exactly, it's as simple as that.
I actually thought that live wasn't taking advantage of the context
when using the syntax
$(selector, context).live(type, handler);
But I just tested it and it does work.
You can file the ticket.

On Nov 6, 5:29 pm, Robert Katić <robert.ka...@gmail.com> wrote:


    Reply    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.
stephband@googlemail.com  
View profile  
 More options Nov 7, 6:38 am
From: "stephb...@googlemail.com" <stephb...@googlemail.com>
Date: Sat, 7 Nov 2009 03:38:06 -0800 (PST)
Local: Sat, Nov 7 2009 6:38 am
Subject: Re: Will the live() method be improved in 1.4?
To handle click delegation I took the approach of enhancing the click
event using the special events framework.  This might be a slight
tangent to this thread, but it does address many of the problems
discussed here.  Here's the code:

http://webdev.stephband.info/events/click/js/jquery.event.click.js

It allows you to bind a click as normal, but if you pass in an options
object with the properties 'selector' or 'href' the bound function
fires only when the conditions are met:

jQuery('context')
.bind('click', {
    selector: 'h3'

}, handlerFunction);

will fire handlerFunction whenever an h3 (or anything inside an h3) in
'context' is clicked. Since I find 90% of my click bindings are on
links, and I'm often interested in sorting links by type, I also
provide a way to bind to links by type of href:

jQuery('context')
.bind('click', {
    href: 'hash'

}, handlerFunction);

will fire handlerFunction when an anchor with href = "#xxx" is
clicked.  Similarily, it will take the values 'slash' ( /xxx ),
'url' ( xxx://xxx ), 'empty' ( # ), or an exact match for your href.
One more example:

jQuery('context')
.bind('click', {
    selector: 'a[target=overlay]'
    href: 'url'

}, handlerFunction);

will fire handlerFunction on links with target="overlay" and an href
that is a full url.

It caches the results of .closest() so when the same element is
clicked twice .closest() is only run the first time.  Inside
handlerFunction, e.target is set to the selected element (even if it
was an element inside that element that was originally clicked) for
easy manipulation.

As a solution, I like it because it allows me to continue write
bindings the same way as I always have, but just enhance them with an
options object when I want delegation.  I never published it on
jQuery.com, for some reason... perhaps I never considered it entirely
finished. But I have had it working in a couple of website projects.

Cheers,
Stephen.


    Reply    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.
Robert Katić  
View profile  
 More options Nov 7, 11:47 am
From: Robert Katić <robert.ka...@gmail.com>
Date: Sat, 7 Nov 2009 08:47:32 -0800 (PST)
Local: Sat, Nov 7 2009 11:47 am
Subject: Re: Will the live() method be improved in 1.4?
I opened a ticket: http://dev.jquery.com/ticket/5470
with link on commit.

Commit also includes context inside liveHandler (it is a too small
change to make a separate commit).

Component is "unfiled". Please tell me if I made mistakes opening this
ticket.

On Nov 6, 3:01 pm, John Resig <jere...@gmail.com> wrote:


    Reply    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 Nov 7, 11:58 am
From: John Resig <jere...@gmail.com>
Date: Sat, 7 Nov 2009 17:58:48 +0100
Local: Sat, Nov 7 2009 11:58 am
Subject: Re: [jquery-dev] Re: Will the live() method be improved in 1.4?
I've already landed the commits - looks great - thanks! (I'll close
the ticket once my network stops flaking out.)

--John


    Reply    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.
Robert Katić  
View profile  
 More options Nov 7, 6:48 pm
From: Robert Katić <robert.ka...@gmail.com>
Date: Sat, 7 Nov 2009 15:48:18 -0800 (PST)
Local: Sat, Nov 7 2009 6:48 pm
Subject: Re: Will the live() method be improved in 1.4?
I detect only now that in closest method the selector is evaluated
without selector.
I am not sure which context is more correct: (context || this.context)
or it have to be a document?

PS: It is not completely clear to me why selectors with positions can
not be handled by multiFilter in this situation.

On Nov 7, 5:58 pm, John Resig <jere...@gmail.com> wrote:


    Reply    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.
Robert Katić  
View profile  
 More options Nov 7, 6:50 pm
From: Robert Katić <robert.ka...@gmail.com>
Date: Sat, 7 Nov 2009 15:50:52 -0800 (PST)
Local: Sat, Nov 7 2009 6:50 pm
Subject: Re: Will the live() method be improved in 1.4?
oops: "evaluated without context"

On Nov 8, 12:48 am, Robert Katić <robert.ka...@gmail.com> wrote:


    Reply    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.
Messages 1 - 25 of 32   Newer >
« Back to Discussions « Newer topic     Older topic »

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