Bug Tracker

Modify

Ticket #8075 (closed feature: fixed)

Opened 2 years ago

Last modified 14 months ago

nextUntil, prevUntil and parentsUntil should accept more then just selectors

Reported by: anonymous Owned by:
Priority: high Milestone: 1.6
Component: traversing Version: 1.5
Keywords: neededdocs Cc:
Blocking: Blocked by:

Description

Just as the title says. One way to make sure the "Until" methods accept more then just selectors is to use the filter method instead of jQuery().is from line 4556 from:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) {

To:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !jQuery( cur ).filter(until)[0] )) {

Now, correct me if I'm wrong here. But assuming you are comparing two DOM nodes to each other. Wouldn't it be a lot faster to compare those right away, so a new jQuery instance won't be created on each iteration? This way you would get something like:

while ( cur && cur.nodeType !== 9 && ( until === undefined || cur.nodeType !== 1 || !( cur === until || jQuery( cur ).filter( until )[0])) ) {

Heck, we could even use matchesSelector between them with something like this:

!( cur === until || ( typeof until === "string" && jQuery.find.matchesSelector( cur, until ) ) || jQuery( cur ).filter( until )[0])

Any thoughts?

Change History

comment:1 Changed 2 years ago by jitter

  • Priority changed from undecided to high
  • Component changed from unfiled to traversing

comment:2 Changed 2 years ago by jitter

  • Priority changed from high to low

comment:3 Changed 2 years ago by jitter

  • Owner set to anonymous
  • Status changed from new to pending

To increase the chances for this to make into the core you should make a pull request with the needed changes


 http://docs.jquery.com/Tips_for_jQuery_Bug_Patching
 http://docs.jquery.com/Getting_Involved

comment:4 Changed 2 years ago by anonymous

  • Status changed from pending to new

 http://jsperf.com/nextuntil-tests

Created a small perf on this ticket. I think it could be optimized and enhanced.

comment:5 Changed 2 years ago by jitter

  • Version changed from 1.4.4 to 1.5

comment:7 Changed 2 years ago by snover

  • Priority changed from low to high
  • Status changed from new to open
  • Milestone changed from 1.next to 1.6

Increasing priority & retargeting due to potential performance benefits.

comment:8 Changed 2 years ago by john

  • Owner anonymous deleted
  • Status changed from open to assigned
  • Milestone changed from 1.6 to 1.next

Let's look at this for 1.7.

comment:9 Changed 2 years ago by JRSchild

As of jQuery 1.6 and the updated is() and find() methods this already works:

nextUntil:  http://jsfiddle.net/asz7m/
prevUntil:  http://jsfiddle.net/mXmSS/
parentsUntil:  http://jsfiddle.net/n77ua/

Should the documentation and test-cases be updated?

comment:10 Changed 2 years ago by timmywil

  • Keywords needsdocs added
  • Status changed from assigned to closed
  • Type changed from enhancement to feature
  • Resolution set to fixed
  • Milestone changed from 1.next to 1.6

Good point! Thanks JRSchild

comment:11 Changed 2 years ago by addyosmani

Working on this at the moment. We'll make sure to post updated examples, signatures and wordage, JRSchild. Thanks!

comment:12 Changed 2 years ago by addyosmani

  • Keywords neededdocs added; needsdocs removed

I've updated the docs on .nextUntil(), .prevUntil() and .parentsUntil() to reflect the changes in behaviour.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.