aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
diff options
context:
space:
mode:
authorDave Methvin <dave.methvin@gmail.com>2012-10-31 22:43:04 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-10-31 22:43:04 -0400
commit5ed0450dc471f61e4c5d5df30df3f3294a3e6bd6 (patch)
tree50ffd4beb836eaa7fe3c311c3a7903e861fde75a /src/traversing.js
parente8cf41a051a62bf1f19beab1a5c1d643f121e28e (diff)
downloadjquery-5ed0450dc471f61e4c5d5df30df3f3294a3e6bd6.tar.gz
jquery-5ed0450dc471f61e4c5d5df30df3f3294a3e6bd6.zip
Fix #12816. Ensure .find() result are DOM ordered.
Diffstat (limited to 'src/traversing.js')
-rw-r--r--src/traversing.js40
1 files changed, 10 insertions, 30 deletions
diff --git a/src/traversing.js b/src/traversing.js
index 0d76038ca..b50f230ce 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -12,46 +12,26 @@ var runtil = /Until$/,
jQuery.fn.extend({
find: function( selector ) {
- var prevLength, n, r, ret,
- i = 0,
- self = this,
- selfLength = this.length;
+ var i, ret, self;
if ( typeof selector !== "string" ) {
-
- ret = jQuery( selector ).filter(function() {
- for ( ; i < selfLength; i++ ) {
+ self = this;
+ return this.pushStack( jQuery( selector ).filter(function() {
+ for ( i = 0; i < self.length; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
}
- });
-
- } else {
+ }) );
+ }
- ret = [];
- for ( ; i < selfLength; i++ ) {
- prevLength = ret.length;
- jQuery.find( selector, this[ i ], ret );
-
- if ( i > 0 ) {
- // Make sure that the results are unique
- // by comparing the newly added elements on the ith
- // iteration to the elements added by the previous iterations
- for ( n = prevLength; n < ret.length; n++ ) {
- for ( r = 0; r < prevLength; r++ ) {
- if ( ret[ r ] === ret[ n ] ) {
- ret.splice( n--, 1 );
- break;
- }
- }
- }
- }
- }
+ ret = [];
+ for ( i = 0; i < this.length; i++ ) {
+ jQuery.find( selector, this[ i ], ret );
}
// Needed because $( selector, context ) becomes $( context ).find( selector )
- ret = this.pushStack( ret );
+ ret = this.pushStack( jQuery.unique( ret ) );
ret.selector = ( this.selector ? this.selector + " " : "" ) + selector;
return ret;
},