Make sure that the correct args are passed in to the filter callback (and by extensio...
[jquery.git] / src / traversing.js
index 4efe282..942138c 100644 (file)
@@ -2,14 +2,13 @@ var runtil = /Until$/,
        rparentsprev = /^(?:parents|prevUntil|prevAll)/,
        // Note: This RegExp should be improved, or likely pulled from Sizzle
        rmultiselector = /,/,
-       slice = Array.prototype.slice,
-       join = Array.prototype.join;
+       slice = Array.prototype.slice;
 
 // Implement the identical functionality for filter and not
 var winnow = function( elements, qualifier, keep ) {
        if ( jQuery.isFunction( qualifier ) ) {
                return jQuery.grep(elements, function(elem, i) {
-                       return !!qualifier.call( elem, i ) === keep;
+                       return !!qualifier.call( elem, i, elem ) === keep;
                });
 
        } else if ( qualifier.nodeType ) {
@@ -58,6 +57,21 @@ jQuery.fn.extend({
                return ret;
        },
 
+       has: function( target ) {
+               var targets = jQuery( target );
+               return this.filter(function() {
+                       for ( var i = 0, l = targets.length; i < l; i++ ) {
+                               if ( jQuery.contains( this, targets[i] ) ) {
+                                       return true;
+                               }
+                       }
+               });
+       },
+
+       contains: function( target ) {
+               return this.has( target ).length > 0;
+       },
+
        not: function( selector ) {
                return this.pushStack( winnow(this, selector, false), "not", selector);
        },
@@ -138,7 +152,7 @@ jQuery.fn.extend({
 
        slice: function() {
                return this.pushStack( slice.apply( this, arguments ),
-                       "slice", join.call(arguments, ",") );
+                       "slice", slice.call(arguments).join(",") );
        },
 
        map: function( callback ) {
@@ -187,7 +201,7 @@ jQuery.each({
                        ret = ret.reverse();
                }
 
-               return this.pushStack( ret, name, join.call(arguments, ",") );
+               return this.pushStack( ret, name, slice.call(arguments).join(",") );
        };
 });