Skip to content
Permalink
Browse files
No ticket: Reduce .find
(cherry picked from commit 85b3c82)
  • Loading branch information
gibson042 committed Apr 20, 2013
1 parent ebecdac commit d754b50
Showing 1 changed file with 10 additions and 10 deletions.
@@ -10,29 +10,29 @@ var isSimple = /^.[^:#\[\.,]*$/,

jQuery.fn.extend({
find: function( selector ) {
var self, matched, i,
l = this.length;
var i,
ret = [],
self = this,
len = self.length;

if ( typeof selector !== "string" ) {
self = this;
return this.pushStack( jQuery( selector ).filter(function() {
for ( i = 0; i < l; i++ ) {
for ( i = 0; i < len; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
}
}) );
}

matched = [];
for ( i = 0; i < l; i++ ) {
jQuery.find( selector, this[ i ], matched );
for ( i = 0; i < len; i++ ) {
jQuery.find( selector, self[ i ], ret );
}

// Needed because $( selector, context ) becomes $( context ).find( selector )
matched = this.pushStack( l > 1 ? jQuery.unique( matched ) : matched );
matched.selector = ( this.selector ? this.selector + " " : "" ) + selector;
return matched;
ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
ret.selector = this.selector ? this.selector + " " + selector : selector;
return ret;
},

has: function( target ) {

0 comments on commit d754b50

Please sign in to comment.