Skip to content
Permalink
Browse files

Simplify jQuery( html, props ), closes gh-765.

  • Loading branch information...
scottgonzalez authored and dmethvin committed May 4, 2012
1 parent a743be1 commit 95a4a776cffe6dd56f5796e93c0cba0225ee49e4
Showing with 3 additions and 6 deletions.
  1. +3 −6 src/core.js
@@ -116,19 +116,16 @@ jQuery.fn = jQuery.prototype = {
// HANDLE: $(html) -> $(array)
if ( match[1] ) {
context = context instanceof jQuery ? context[0] : context;
doc = ( context ? context.ownerDocument || context : document );
doc = ( context && context.nodeType ? context.ownerDocument || context : document );

This comment has been minimized.

@Krinkle

Krinkle May 7, 2012

Member

Did you mean to commit this? Doesn't appear to be related to the PR-summary/commit-msg.

I'd ask to add a unit test to verify that passing { ownerDocument: 1 } as context doesn't fail, but that looks a little silly. But if it is worth fixing, maybe a unit test is justified?

This comment has been minimized.

@rwaldron

This comment has been minimized.

@scottgonzalez

scottgonzalez May 7, 2012

Author Member

Yes, this was intentional. It's a required change in order to support squashing the conditional. jQuery( "<div>", { id: "foo" } ) will have a context, but that context is not a real context. This was handled before because the conditional used document in one case and doc in the other. In order to squash the conditional, they both need to use the same, which much be doc.

As for unit tests, if you remove context.nodeType, you will get failing tests, for the reason I just stated. I don't think it makes sense to add a unit test for passing a context of a plain object with an ownerDocument property as that seems invalid.

This comment has been minimized.

@Krinkle

Krinkle May 7, 2012

Member

Ah, makes perfect sense now :)


// If a single string is passed in and it's a single tag
// just do a createElement and skip the rest
ret = rsingleTag.exec( selector );

if ( ret ) {
selector = [ doc.createElement( ret[1] ) ];
if ( jQuery.isPlainObject( context ) ) {
selector = [ document.createElement( ret[1] ) ];
jQuery.fn.attr.call( selector, context, true );

} else {
selector = [ doc.createElement( ret[1] ) ];
this.attr.call( selector, context, true );
}

} else {

0 comments on commit 95a4a77

Please sign in to comment.
You can’t perform that action at this time.