Made sure that .remove now uses multiFilter. Fixes bug #4205.
[jquery.git] / src / core.js
index b3142d0..65960e2 100644 (file)
@@ -75,7 +75,9 @@ jQuery.fn = jQuery.prototype = {
                        this.context = selector.context;
                }
 
-               return this.setArray(jQuery.makeArray(selector));
+               return this.setArray(jQuery.isArray( selector ) ?
+                       selector :
+                       jQuery.makeArray(selector));
        },
 
        // Start with an empty selector
@@ -95,7 +97,7 @@ jQuery.fn = jQuery.prototype = {
                return num === undefined ?
 
                        // Return a 'clean' array
-                       jQuery.makeArray( this ) :
+                       Array.prototype.slice.call( this ) :
 
                        // Return just the object
                        this[ num ];
@@ -265,8 +267,10 @@ jQuery.fn = jQuery.prototype = {
        },
 
        // For internal use only.
-       // Behaves like an Array's .push method, not like a jQuery method.
+       // Behaves like an Array's method, not like a jQuery method.
        push: [].push,
+       sort: [].sort,
+       splice: [].splice,
 
        find: function( selector ) {
                if ( this.length === 1 ) {
@@ -498,13 +502,13 @@ jQuery.fn = jQuery.prototype = {
                if ( this[0] ) {
                        var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
                                scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
-                               first = fragment.firstChild,
-                               extra = this.length > 1 ? fragment.cloneNode(true) : fragment;
+                               first = fragment.firstChild;
 
                        if ( first )
                                for ( var i = 0, l = this.length; i < l; i++ )
-                                       callback.call( root(this[i], first), i > 0 ? extra.cloneNode(true) : fragment );
-                       
+                                       callback.call( root(this[i], first), this.length > 1 || i > 0 ?
+                                                       fragment.cloneNode(true) : fragment );
+               
                        if ( scripts )
                                jQuery.each( scripts, evalScript );
                }
@@ -1185,13 +1189,16 @@ jQuery.each({
        insertAfter: "after",
        replaceAll: "replaceWith"
 }, function(name, original){
-       jQuery.fn[ name ] = function() {
-               var args = arguments;
+       jQuery.fn[ name ] = function( selector ) {
+               var ret = [], insert = jQuery( selector );
 
-               return this.each(function(){
-                       for ( var i = 0, length = args.length; i < length; i++ )
-                               jQuery( args[ i ] )[ original ]( this );
-               });
+               for ( var i = 0, l = insert.length; i < l; i++ ) {
+                       var elems = (i > 0 ? this.clone(true) : this).get();
+                       jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
+                       ret = ret.concat( elems );
+               }
+
+               return this.pushStack( ret, name, selector );
        };
 });
 
@@ -1217,7 +1224,7 @@ jQuery.each({
        },
 
        remove: function( selector ) {
-               if ( !selector || jQuery.filter( selector, [ this ] ).length ) {
+               if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
                        // Prevent memory leaks
                        jQuery( "*", this ).add([this]).each(function(){
                                jQuery.event.remove(this);
@@ -1230,7 +1237,7 @@ jQuery.each({
 
        empty: function() {
                // Remove element nodes and prevent memory leaks
-               jQuery( ">*", this ).remove();
+               jQuery(this).children().remove();
 
                // Remove any remaining nodes
                while ( this.firstChild )