aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-03-16 01:16:32 -0400
committertimmywil <tim.willison@thisismedium.com>2011-03-16 01:16:32 -0400
commit7a69e34a5cd4df37762cbee9c9468c96c0ac3017 (patch)
tree01d7a27135d76fb61a590d36b66a87b2a92ac2f0 /src
parent8246347b7191e79ed09bf1fc4c4a0a58211cf345 (diff)
downloadjquery-7a69e34a5cd4df37762cbee9c9468c96c0ac3017.tar.gz
jquery-7a69e34a5cd4df37762cbee9c9468c96c0ac3017.zip
2773: first pass adding node/jQuery object support to jQuery.fn.find; unit tests added
Diffstat (limited to 'src')
-rw-r--r--src/core.js2
-rw-r--r--src/traversing.js23
2 files changed, 19 insertions, 6 deletions
diff --git a/src/core.js b/src/core.js
index 9312ee288..812ecde55 100644
--- a/src/core.js
+++ b/src/core.js
@@ -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;
}
diff --git a/src/traversing.js b/src/traversing.js
index fe2e33d88..fa6aae2fe 100644
--- a/src/traversing.js
+++ b/src/traversing.js
@@ -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;
+
+ 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;
+ }
+ }
+ });
+ }
- for ( var i = 0, l = this.length; i < l; i++ ) {
+ 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;