From: John Resig Date: Thu, 8 Jan 2009 21:41:58 +0000 (+0000) Subject: Selector state wasn't being passed along on a cloned jQuery object. X-Git-Tag: 1.3rc1~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c6f189ac73939c813bf3a2b848c492c8ba259807;p=jquery.git Selector state wasn't being passed along on a cloned jQuery object. --- diff --git a/src/core.js b/src/core.js index 61a9bd9f6..fe5dbc6bf 100644 --- a/src/core.js +++ b/src/core.js @@ -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)); }, diff --git a/test/unit/core.js b/test/unit/core.js index ee5f805ec..98a161fa8 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -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" );