]> source.dussan.org Git - jquery.git/commitdiff
Selector state wasn't being passed along on a cloned jQuery object.
authorJohn Resig <jeresig@gmail.com>
Thu, 8 Jan 2009 21:41:58 +0000 (21:41 +0000)
committerJohn Resig <jeresig@gmail.com>
Thu, 8 Jan 2009 21:41:58 +0000 (21:41 +0000)
src/core.js
test/unit/core.js

index 61a9bd9f6a406f352ba5310162ea82b121d9d8cf..fe5dbc6bf053b91764b2c5fbcf8a042a590dfb9d 100644 (file)
@@ -73,6 +73,12 @@ jQuery.fn = jQuery.prototype = {
                } else if ( jQuery.isFunction( selector ) )
                        return jQuery( document ).ready( selector );
 
+               // Make sure that old selector state is passed along
+               if ( selector.selector && selector.context ) {
+                       this.selector = selector.selector;
+                       this.context = selector.context;
+               }
+
                return this.setArray(jQuery.makeArray(selector));
        },
 
index ee5f805ec5fc10d1e0431ea00ad982bb5b2ede0f..98a161fa8ef8bf947c824b9bca97b8fe75a9b90d 100644 (file)
@@ -53,7 +53,7 @@ test("jQuery()", function() {
 });
 
 test("selector state", function() {
-       expect(26);
+       expect(28);
 
        var test;
        
@@ -80,6 +80,11 @@ test("selector state", function() {
        test = jQuery("#main", document.body);
        equals( test.selector, "#main", "#main Selector" );
        equals( test.context, document.body, "#main Context" );
+
+       // Test cloning
+       test = jQuery(test);
+       equals( test.selector, "#main", "#main Selector" );
+       equals( test.context, document.body, "#main Context" );
        
        test = jQuery(document.body).find("#main");
        equals( test.selector, "#main", "#main find Selector" );