constructor: jQuery,
+ // Start with an empty selector
+ selector: "",
+
// The default length of a jQuery object is 0
length: 0,
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
+ ret.context = this.context;
// Return the newly-formed element set
return ret;
if ( elem ) {
// Inject the element directly into the jQuery object
- this[ 0 ] = elem;
this.length = 1;
+ this[0] = elem;
}
+
+ this.context = document;
+ this.selector = selector;
return this;
}
// HANDLE: $(DOMElement)
} else if ( selector.nodeType ) {
- this[ 0 ] = selector;
+ this.context = this[0] = selector;
this.length = 1;
return this;
selector( jQuery );
}
+ if ( selector.selector !== undefined ) {
+ this.selector = selector.selector;
+ this.context = selector.context;
+ }
+
return jQuery.makeArray( selector, this );
};
jQuery.find( selector, self[ i ], ret );
}
- return this.pushStack( len > 1 ? jQuery.uniqueSort( ret ) : ret );
+ // Needed because $( selector, context ) becomes $( context ).find( selector )
+ ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
+ ret.selector = this.selector ? this.selector + " " + selector : selector;
+ return ret;
},
filter: function( selector ) {
return this.pushStack( winnow( this, selector || [], false ) );
// Basic constructor's behavior
assert.equal( jQuery().length, 0, "jQuery() === jQuery([])" );
- assert.equal( jQuery( undefined ).length, 0, "jQuery(undefined) === jQuery([])" );
- assert.equal( jQuery( null ).length, 0, "jQuery(null) === jQuery([])" );
- assert.equal( jQuery( "" ).length, 0, "jQuery('') === jQuery([])" );
- assert.deepEqual( jQuery( obj ).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" );
+ assert.equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" );
+ assert.equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" );
+ assert.equal( jQuery("").length, 0, "jQuery('') === jQuery([])" );
+ assert.equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" );
// Invalid #id goes to Sizzle which will throw an error (gh-1682)
try {
assert.equal( window.globalEvalTest, 3, "Test context (this) is the window object" );
} );
+
QUnit.test( "globalEval with 'use strict'", function( assert ) {
assert.expect( 1 );
Globals.register( "strictEvalTest" );
QUnit.test( "chaining", function( assert ) {
assert.expect( 3 );
var coords = { "top": 1, "left": 1 };
- assert.equal( jQuery( "#absolute-1" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" );
- assert.equal( jQuery( "#non-existent" ).offset( coords ).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" );
- assert.equal( jQuery( "#absolute-1" ).offset( undefined ).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" );
-} );
+ assert.equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
+ assert.equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
+ assert.equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" );
+});
QUnit.test( "offsetParent", function( assert ) {
assert.expect( 13 );