Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#15148 closed feature (plugin)

findExclude - a descendant traversal feature similar to nextUntil / parentsUntil / prevUntil...

Reported by: stealthpaladin Owned by:
Priority: low Milestone:
Component: traversing Version:
Keywords: findExclude, find, parentsUntil, exclusion Cc:
Blocked by: Blocking:

Description

Currently there seems to be no dedicated method to traverse while filtering certain branches.

Usefulness is similar to the *Until methods; I have not named it findUntil as find should not stop descendant traversal except for matching branches.

An example is provided here, in the js section lines 0-22: http://jsfiddle.net/KX65p/1/

Notable use cases:

  • Especially good for situations where elements with a given selector exist nested inside elements matching the same selector.
  • Can provide new functionality consistent with current traversal methods for descendants where CSS selectors and .not are inadequate.

One example of the problem exists on StackOverflow.

The above problem would be solved with $('table').findExclude('.target','table') which will search within each table individually without crossing into sub-tables. Most helpful when inside $('table').each()

Inspired by my similar, but wordier, problem which is addressed in the JSFiddle.

This is my first go at contributing, so please feel free to direct my attention elsewhere!

Originally I thought to leave this as a plugin but it does seem to fit with the *Until family of logic very closely in traversal methods. There is no particular version in which I think this feature should be introduced.

Change History (4)

comment:1 Changed 7 years ago by stealthpaladin

Attempted a draft of including the function into: /src/traversing.js

From lines 125 - 134. Edit can be found here.

comment:2 Changed 7 years ago by stealthpaladin

Revised to move .not out of the function by checking !thisObject.is( Mask ) within $( selector ).children().each()

This should save performance by sorting child elements only once

http://jsfiddle.net/KX65p/3/

GitHub branch updated.

comment:3 Changed 7 years ago by dmethvin

Resolution: plugin
Status: newclosed

We're trying to keep the core API surface small and light, but this does seem like a good plugin.

comment:4 Changed 7 years ago by stealthpaladin

Hi, thanks for the feedback. Completely understandable.

Just wanted to mention, after getting some further code review on stackoverflow, it was found that the function could be reduced considerably.

So much so, while it may fill a small hole for edge cases, it may also not be needed. The same result is achieved by:

el=$(anything); el.find(Select).not(el.find(Mask).find(Select));

In case anyone happens to arrive here via search or have a similar problem.

Last edited 7 years ago by stealthpaladin (previous) (diff)
Note: See TracTickets for help on using tickets.