Removed the need for the results set to have array methods. Resolves jQuery bug ...
[jquery.git] / src / core.js
index d99f401..56fd098 100644 (file)
@@ -279,22 +279,28 @@ jQuery.fn = jQuery.prototype = {
                return this.prevObject || jQuery(null);
        },
 
-       // For internal use only.
-       // Behaves like an Array's method, not like a jQuery method.
-       push: [].push,
-       sort: [].sort,
-       splice: [].splice,
-
        find: function( selector ) {
-               if ( this.length === 1 ) {
-                       var ret = this.pushStack( "", "find", selector );
-                       jQuery.find( selector, this[0], ret );
-                       return ret;
-               } else {
-                       return this.pushStack( jQuery.unique(jQuery.map(this, function(elem){
-                               return jQuery.find( selector, elem );
-                       })), "find", selector );
+               var ret = this.pushStack( "", "find", selector ), length = 0,
+                       splice = Array.prototype.splice;
+
+               for ( var 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++ ) {
+                                               if ( ret[r] === ret[n] ) {
+                                                       splice.call(ret, n--, 1);
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
                }
+
+               return ret;
        },
 
        clone: function( events ) {