No ticket: Reduce .find

This commit is contained in:
Richard Gibson 2013-04-20 10:02:07 -04:00
parent 157aeb7c37
commit 85b3c82445

View File

@ -10,11 +10,12 @@ var isSimple = /^.[^:#\[\.,]*$/,
jQuery.fn.extend({ jQuery.fn.extend({
find: function( selector ) { find: function( selector ) {
var i, ret, self, var i,
len = this.length; ret = [],
self = this,
len = self.length;
if ( typeof selector !== "string" ) { if ( typeof selector !== "string" ) {
self = this;
return this.pushStack( jQuery( selector ).filter(function() { return this.pushStack( jQuery( selector ).filter(function() {
for ( i = 0; i < len; i++ ) { for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) { if ( jQuery.contains( self[ i ], this ) ) {
@ -24,14 +25,13 @@ jQuery.fn.extend({
}) ); }) );
} }
ret = [];
for ( i = 0; i < len; i++ ) { for ( i = 0; i < len; i++ ) {
jQuery.find( selector, this[ i ], ret ); jQuery.find( selector, self[ i ], ret );
} }
// Needed because $( selector, context ) becomes $( context ).find( selector ) // Needed because $( selector, context ) becomes $( context ).find( selector )
ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
ret.selector = ( this.selector ? this.selector + " " : "" ) + selector; ret.selector = this.selector ? this.selector + " " + selector : selector;
return ret; return ret;
}, },