aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2013-03-26 21:20:27 -0400
committerRichard Gibson <richard.gibson@gmail.com>2013-04-05 00:37:36 -0400
commit5d1dfe747403c093cc0e837651dcf80027387fc6 (patch)
tree44cc433e2d2a3e496443128025983b39205c5822 /src/traversing.js
parent6358da8aa32e7ed52da3af1a912bdd1a05863faf (diff)
downloadjquery-5d1dfe747403c093cc0e837651dcf80027387fc6.tar.gz
jquery-5d1dfe747403c093cc0e837651dcf80027387fc6.zip
Fix #13539: Utilize Sizzle hooks. Close gh-1215.
(cherry picked from commit 4ef516903e6e48bce388ca47c1ed88a447199fa1)
Diffstat (limited to 'src/traversing.js')
-rw-r--r--src/traversing.js57
1 files changed, 26 insertions, 31 deletions
diff --git a/src/traversing.js b/src/traversing.js
index 81c1e5b57..a063a4612 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -1,6 +1,4 @@
-var runtil = /Until$/,
- rparentsprev = /^(?:parents|prev(?:Until|All))/,
- isSimple = /^.[^:#\[\.,]*$/,
+var isSimple = /^.[^:#\[\.,]*$/,
rneedsContext = jQuery.expr.match.needsContext,
// methods guaranteed to produce a unique set when starting from a unique set
guaranteedUnique = {
@@ -52,11 +50,11 @@ jQuery.fn.extend({
},
not: function( selector ) {
- return this.pushStack( winnow(this, selector, false) );
+ return this.pushStack( winnow(this, selector || [], true) );
},
filter: function( selector ) {
- return this.pushStack( winnow(this, selector, true) );
+ return this.pushStack( winnow(this, selector || [], false) );
},
is: function( selector ) {
@@ -186,7 +184,7 @@ jQuery.each({
jQuery.fn[ name ] = function( until, selector ) {
var matched = jQuery.map( this, fn, until );
- if ( !runtil.test( name ) ) {
+ if ( name.slice( -5 ) !== "Until" ) {
selector = until;
}
@@ -195,11 +193,13 @@ jQuery.each({
}
if ( this.length > 1 ) {
+ // Remove duplicates
if ( !guaranteedUnique[ name ] ) {
jQuery.unique( matched );
}
- if ( rparentsprev.test( name ) ) {
+ // Reverse order for parents* and prev*
+ if ( name[ 0 ] === "p" ) {
matched.reverse();
}
}
@@ -210,13 +210,17 @@ jQuery.each({
jQuery.extend({
filter: function( expr, elems, not ) {
+ var elem = elems[ 0 ];
+
if ( not ) {
expr = ":not(" + expr + ")";
}
- return elems.length === 1 ?
- jQuery.find.matchesSelector( elems[ 0 ], expr ) ? [ elems[ 0 ] ] : [] :
- jQuery.find.matches( expr, elems );
+ return elems.length === 1 && elem.nodeType === 1 ?
+ jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
+ jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
+ return elem.nodeType === 1;
+ }));
},
dir: function( elem, dir, until ) {
@@ -248,40 +252,31 @@ jQuery.extend({
});
// Implement the identical functionality for filter and not
-function winnow( elements, qualifier, keep ) {
-
- // Can't pass null or undefined to indexOf
- // Set to 0 to skip string check
- qualifier = qualifier || 0;
-
- var filtered;
-
+function winnow( elements, qualifier, not ) {
if ( jQuery.isFunction( qualifier ) ) {
- return jQuery.grep(elements, function( elem, i ) {
- var retVal = !!qualifier.call( elem, i, elem );
- return retVal === keep;
+ return jQuery.grep( elements, function( elem, i ) {
+ /* jshint -W018 */
+ return !!qualifier.call( elem, i, elem ) !== not;
});
+
}
if ( qualifier.nodeType ) {
- return jQuery.grep(elements, function( elem ) {
- return ( elem === qualifier ) === keep;
+ return jQuery.grep( elements, function( elem ) {
+ return ( elem === qualifier ) !== not;
});
+
}
if ( typeof qualifier === "string" ) {
- filtered = jQuery.grep(elements, function( elem ) {
- return elem.nodeType === 1;
- });
-
if ( isSimple.test( qualifier ) ) {
- return jQuery.filter( qualifier, filtered, !keep );
+ return jQuery.filter( qualifier, elements, not );
}
- qualifier = jQuery.filter( qualifier, filtered );
+ qualifier = jQuery.filter( qualifier, elements );
}
- return jQuery.grep(elements, function( elem ) {
- return ( core_indexOf.call( qualifier, elem ) >= 0 ) === keep;
+ return jQuery.grep( elements, function( elem ) {
+ return ( core_indexOf.call( qualifier, elem ) >= 0 ) !== not;
});
}