aboutsummaryrefslogtreecommitdiffstats
path: root/src/traversing.js
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/traversing.js
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/traversing.js')
-rw-r--r--src/traversing.js23
1 files changed, 18 insertions, 5 deletions
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;