2773: first pass adding node/jQuery object support to jQuery.fn.find; unit tests added

This commit is contained in:
timmywil 2011-03-16 01:16:32 -04:00
parent 8246347b71
commit 7a69e34a5c
3 changed files with 39 additions and 11 deletions

View file

@ -88,7 +88,7 @@ jQuery.fn = jQuery.prototype = {
if ( selector === "body" && !context && document.body ) {
this.context = document;
this[0] = document.body;
this.selector = "body";
this.selector = selector;
this.length = 1;
return this;
}

View file

@ -17,17 +17,30 @@ var runtil = /Until$/,
jQuery.fn.extend({
find: function( selector ) {
var ret = this.pushStack( "", "find", selector ),
length = 0;
var self = this,
ret, i, l;
for ( var i = 0, l = this.length; i < l; i++ ) {
if ( typeof selector !== "string" ) {
return jQuery( selector ).filter(function() {
for ( i = 0, l = self.length; i < l; i++ ) {
if ( jQuery.contains( self[ i ], this ) ) {
return true;
}
}
});
}
ret = this.pushStack( "", "find", selector );
var length, n, r;
for ( i = 0, l = this.length; i < l; i++ ) {
length = ret.length;
jQuery.find( selector, this[i], ret );
if ( i > 0 ) {
// Make sure that the results are unique
for ( var n = length; n < ret.length; n++ ) {
for ( var r = 0; r < length; r++ ) {
for ( n = length; n < ret.length; n++ ) {
for ( r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) {
ret.splice(n--, 1);
break;